Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avonyel's Solution' #16

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.DS_Store

node_modules
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# assignment_test_driven_diary
Build a command line diary interface, driven and protected by a suite of comprehensive tests.

Names: Ian Halverson and Stephanie Barker
19 changes: 19 additions & 0 deletions diaries/testDiary.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"entries": {
"1": "lolol Brad #heartemoji #brad",
"2": "8) #brad",
"3": "I'm at your windooooooooooow #juststalkerthings #brad"
},

"tags": {
"heartemoji": ["1"],
"brad": ["1", "2", "3"],
"juststalkerthings": ["3"]
},

"dates": {
"1501272599": ["1"],
"1501272665": ["2"],
"1501272682": ["3"]
}
}
39 changes: 39 additions & 0 deletions diary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
currentDiary: {
}
// {
// entry: "I luv uuuuuu #brad",
// tags: ["brad"],
// id: "4"
// };

let diary = {
load: path => {
return require(path);
},

entry: message => {
tags = [];

/#(\w+){#|\s}/;

return {};
},

insertEntry: () => {},

entriesWithTag: () => {},

entries: () => {},

tags: () => {},

today: () => {},

date: () => {},

search: () => {},

save: () => {}
};

module.exports = diary;
4 changes: 4 additions & 0 deletions lib/integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// save and load


module.exports =
4 changes: 4 additions & 0 deletions lib/parser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//everything else


module.exports =
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "assignment_test_driven_diary",
"version": "1.0.0",
"description": "Build a command line diary interface, driven and protected by a suite of comprehensive tests.",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Avonyel/assignment_test_driven_diary.git"
},
"author": "Ian and Stephanie",
"license": "ISC",
"bugs": {
"url": "https://github.com/Avonyel/assignment_test_driven_diary/issues"
},
"homepage": "https://github.com/Avonyel/assignment_test_driven_diary#readme",
"dependencies": {
"jasmine": "^2.7.0",
"jasmine-node": "^1.14.5"
}
}
275 changes: 275 additions & 0 deletions spec/diary.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,275 @@
const fs = require("fs");
const diary = require("../diary");

const currentDiary = {
entries: {
1: "lolol Brad #heartemoji #brad",
2: "8) #brad",
3: "I'm at your windooooooooooow #juststalkerthings #brad"
},

tags: {
heartemoji: ["1"],
brad: ["1", "2", "3"],
juststalkerthings: ["3"]
},

dates: {
1501272599: ["1"],
1501272665: ["2"],
1501272682: ["3"]
}
};

describe("Diary", () => {
describe("diary loading", () => {
it("should load the diary from a file", () => {
let loadedDiary = diary.load("./diaries/testDiary");

expect(loadedDiary).toEqual(currentDiary);
});
});

describe("diary entry creation", () => {
beforeEach(() => {
const currentDiary = {
entries: {
1: "lolol Brad #heartemoji #brad",
2: "8) #brad",
3: "I'm at your windooooooooooow #juststalkerthings #brad"
},

tags: {
heartemoji: ["1"],
brad: ["1", "2", "3"],
juststalkerthings: ["3"]
},

dates: {
1501272599: ["1"],
1501272665: ["2"],
1501272682: ["3"]
}
};

const newEntry = {
entry: "I luv uuuuuu #brad",
tags: ["brad"],
id: "4"
};

const updatedDummyDiary = {
entries: {
1: "lolol Brad #heartemoji #brad",
2: "8) #brad",
3: "I'm at your windooooooooooow #juststalkerthings #brad",
4: "I luv uuuuuu #brad"
},

tags: {
heartemoji: ["1"],
brad: ["1", "2", "3", "4"],
juststalkerthings: ["3"]
},

dates: {
1501272599: ["1"],
1501272665: ["2"],
1501272682: ["3"],
"/^d{10}/": ["4"]
}
};
let entry = diary.entry("I luv uuuuuu #brad");
let updatedDiary = diary.insertEntry(entry);
});

it("should parse message into the usable object correctly", () => {
expect(entry.entry).toEqual(newEntry.entry);
});

xit("should parse tags into the usable object correctly", () => {
expect(entry.tags).toEqual(newEntry.tags);
});

xit("should parse date into the usable object correctly", () => {
expect(entry.date).toMatch(/^\d{10}/);
});

xit("should parse ID into the usable object correctly", () => {
expect(entry.id).toEqual(newEntry.id);
});

xit("should insert message into the diary object correctly", () => {
expect(updatedDiary.entries).toEqual(updatedDummyDiary.entries);
});

xit("should insert tags into the diary object correctly", () => {
expect(updatedDiary.tags).toEqual(updatedDummyDiary.tags);
});

xit("should insert date into the diary object correctly", () => {
expect(updatedDiary.date).toEqual(updatedDummyDiary.date);
});

xit("should create each by unique ID", () => {
let entryCopy = diary.entry("I luv uuuuuu #brad");
var secondEntryUniqueId = "5";
expect(entryCopy.id).toEqual(secondEntryUniqueId);
});

xit("should create all entries as strings", () => {
expect(typeof entry.entry).toEqual("string");
});

xit("should create new tags if they don't already exist", () => {
let updatedTagDiary = diary.insertEntry(
diary.entry("ugh! school tomorrow #ihateschool")
);
expect(updatedTagDiary.tags.ihateschool).toBe(true);
});

xit("should create an entry by a user-specified date", () => {
let entry = diary.entry("omg im like so tired", "07/13/2017-20:30");
expect(entry.date).toEqual("1499977800");
});

xit("should accept date parameter in form of 'mm/dd/yyyy' ", () => {
let entry = diary.entry("omg im like so tired", "07/13/2017");
expect(entry.date).toEqual("1499904000");
});

xit("should throw error for any non-accepted date format", () => {
expect(diary.entry("omg im like so tired", "0712017")).toThrow(
"Invalid Date"
);
});

xit(
"should insert a new entry even if content and date are the same",
() => {
let currentDiary = diary.insertEntry(
diary.entry("omg im like so tired", "07/13/2017-20:30")
);
let updatedDiary = diary.insertEntry(
diary.entry("omg im like so tired", "07/13/2017-20:30")
);
expect(updatedDiary.dates["1499977800"]).toEqual(["5", "6"]);
}
);

xit("should not save a blank entry", () => {
expect(diary.entry("")).toThrow("Invalid entry.");
});

xit("should not save an entry with only white space", () => {
expect(diary.entry("\t\t\t\t \n")).toThrow("Invalid entry.");
});
});

describe("diary searching", () => {
beforeEach(() => {
const currentDiary = {
entries: {
1: "lolol Brad #heartemoji #brad",
2: "8) #brad",
3: "I'm at your windooooooooooow #juststalkerthings #brad"
},

tags: {
heartemoji: ["1"],
brad: ["1", "2", "3"],
juststalkerthings: ["3"]
},

dates: {
1501272599: ["1"],
1501272665: ["2"],
1501272682: ["3"]
}
};
});

xit("should return a list of all entries", () => {
let retrievedEntries = diary.entries();
const entries = [
"lolol Brad #heartemoji #brad",
"8) #brad",
"I'm at your windooooooooooow #juststalkerthings #brad"
];
expect(retrievedEntries).toEqual(entries);
});

xit("should notify user if no entries exist in diary", () => {
const emptyDiary = {};
expect(diary.entries(emptyDiary)).toThrow("There are no entries.");
});

xit("should return all entries with a certain tag", () => {
let retrievedEntries = diary.entriesWithTag("brad");
const entries = [
"lolol Brad #heartemoji #brad",
"8) #brad",
"I'm at your windooooooooooow #juststalkerthings #brad"
];
expect(retrievedEntries).toEqual(entries);
});

xit("should notify user if no entries exist by tag", () => {
expect(diary.entriesWithTag("yolo")).toThrow("There are no entries.");
});

xit("should return all existing tags", () => {
let entries = diary.tags();
let result = ["heartemoji", "brad", "juststalkerthings"];
expect(entries).toEqual(result);
});

xit("should notify user if no tags exist", () => {
expect(diary.tags()).toThrow("There are no tags.");
});

xit("should return all entries from the current day", () => {
let newEntry = diary.entry("i'm bored lol");
let entries = diary.today();
expect(entries).toEqual(["i'm bored lol"]);
});

xit("should notify user if no entries exist from current date", () => {
expect(diary.today()).toThrow("There are no entries.");
});

xit("should return all entries from a given date", () => {
let entries = diary.date("07/28/2017");
expect(entries).toEqual([
"lolol Brad #heartemoji #brad",
"8) #brad",
"I'm at your windooooooooooow #juststalkerthings #brad"
]);
});

xit("should notify user if no entries exist for given date", () => {
expect(diary.date("7/26/2017")).toThrow("There are no entries.");
});

xit(
"should return all entries containing a user-specified search string",
() => {
let entries = diary.search("Brad");
expect(entries).toEqual([
"lolol Brad #heartemoji #brad",
"8) #brad",
"I'm at your windooooooooooow #juststalkerthings #brad"
]);
}
);
});

describe("diary saving", () => {
xit("saves the diary object to a json file", () => {
diary.save("./diaries/testDiary.json").then(() => {
let result = fs.readFileSync("./diaries/testDiary.json");
expect(result).toEqual(currentDiary);
});
});
});
});
11 changes: 11 additions & 0 deletions spec/support/jasmine.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"spec_dir": "spec",
"spec_files": [
"**/*[sS]pec.js"
],
"helpers": [
"helpers/**/*.js"
],
"stopSpecOnExpectationFailure": false,
"random": false
}