From bfc3cc720199c07645931b98ecca8fd404468dd0 Mon Sep 17 00:00:00 2001 From: robocopkaka Date: Thu, 18 Aug 2016 13:29:23 +0100 Subject: [PATCH 1/3] done ten tests --- lib/notes.js | 4 +- notes_application_tests.js | 101 +++++++++++++++++++++++++++++++++++++ tests.js | 2 +- 3 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 notes_application_tests.js diff --git a/lib/notes.js b/lib/notes.js index 9ccc1a2..347ee7b 100644 --- a/lib/notes.js +++ b/lib/notes.js @@ -1,5 +1,7 @@ // Note class -module.exports = function() { +module.exports = { + var Notes = function(an_object){ + }; } \ No newline at end of file diff --git a/notes_application_tests.js b/notes_application_tests.js new file mode 100644 index 0000000..bcdd9c8 --- /dev/null +++ b/notes_application_tests.js @@ -0,0 +1,101 @@ +'use strict' + +var chai = require('chai'); +var assert = chai.assert; + +var NotesApplication = require('./lib/notesapplication.js'); +var Notes = require('./lib/notes.js'); + +describe("Check that creating a note object properly", function(){ + it("should assign the note content based on the parameter supplied",function(){ + var an_object = { + author: "kachi", + }; + var note = new Notes({author: "kachi", note_content: "stuff"}); + assert(note.note_content == "stuff"); + }) + + it("should assign the author based on the parameter supplied",function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + assert(note.author == "kachi"); + }) +}) + +describe("Shoud check that you can create a new note", function(){ + it("it should check that a new entry was added", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var check = new NotesApplication(); + assert(check.notes.length === 0); + check.create_notes(note); + assert(check.notes.length === 1); + }) + + it("it should check if the parameter being supplied is an instance of the Notes class", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var check = new NotesApplication(); + check.create_notes(note); + assert.instanceOf(note, Notes); + }) +}) + +describe("it should check if you can get a note", function(){ + it("check if you can retrieve a note with an ID of 0", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var check = new NotesApplication(); + check.create_notes(note); + assert("stuff"); + }) + + it("check that you can't retrieve a note with an invalid ID", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var check = new NotesApplication(); + check.create_notes(note); + check.get(4.5); + assert("ID is invalid"); + }) + +}) + +describe("edit functionality works properly", function(){ + it("it should check that the content of a note at index 0 changes when edited", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var check = new NotesApplication(); + + check.create_notes(note); + check.edit(0, "new stuff") + assert(check.notes[0].note_content === "new stuff"); + }) + + it("check that you can't edit a note with an invalid ID", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var check = new NotesApplication(); + check.create_notes(note); + check.edit(0.1, "new stuff") + assert("ID is invalid") + }) +}) + +describe("that you can delete a note at index 1", function(){ + it("check that list notes returns notes ", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var note2 = new Notes({author: "kachi", note_content: "stuff2"}); + var check = new NotesApplication(); + check.create_notes(note); + check.create_notes(note2); + assert(check.notes.length === 2); + check.delete(1); + assert(check.notes.length == 1); + assert(check.notes[1] === null); + + }) + + it("checks that you can't delete a note at an invalid index", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var note2 = new Notes({author: "kachi", note_content: "stuff2"}); + var check = new NotesApplication(); + check.create_notes(note); + check.create_notes(note2); + check.delete(5.1); + assert("ID is invalid") + }) +}) \ No newline at end of file diff --git a/tests.js b/tests.js index 12661b7..abb8128 100644 --- a/tests.js +++ b/tests.js @@ -4,7 +4,7 @@ var chai = require('chai'); var assert = chai.assert; var NotesApplication = require('./lib/notesapplication.js'); -var Note = require('./lib/note.js'); +var Note = require('./lib/notes.js'); describe("Note creation works properly", function() { it("assigns author based on the parameter supplied in the constructor", function() { From 4f80ad925e28ad050f660602fbdcbe868232aafe Mon Sep 17 00:00:00 2001 From: robocopkaka Date: Thu, 18 Aug 2016 15:06:32 +0100 Subject: [PATCH 2/3] current tests passed, test for list_notes and search yet to be done --- lib/notes.js | 8 ++++---- lib/notesapplication.js | 27 ++++++++++++++++++++++++--- notes_application_tests.js | 17 +++++++++++------ 3 files changed, 39 insertions(+), 13 deletions(-) diff --git a/lib/notes.js b/lib/notes.js index 347ee7b..d1ac750 100644 --- a/lib/notes.js +++ b/lib/notes.js @@ -1,7 +1,7 @@ // Note class -module.exports = { - var Notes = function(an_object){ +module.exports = function Notes(an_object) { + this.author = an_object.author; + this.note_content = an_object.note_content; +} - }; -} \ No newline at end of file diff --git a/lib/notesapplication.js b/lib/notesapplication.js index 2b695f7..ee91d2a 100644 --- a/lib/notesapplication.js +++ b/lib/notesapplication.js @@ -1,5 +1,26 @@ -// NotesApplication class +var Notes = require('./notes.js'); +module.exports = function NotesApplication() { + this.notes = []; + this.create_notes = function(note){ + if(note instanceof Notes) this.notes.push(note); + } + + this.get = function(note_id){ + if(this.notes.hasOwnProperty(note_id)){ //checks to see if the notes id is an index of + return this.notes[note_id].note_content; + }// end if + else console.log("ID is invalid"); + } + + this.edit = function(note_id, new_content){ + if(this.notes.hasOwnProperty(note_id)) this.notes[note_id].note_content = new_content; + else console.log("ID is invalid"); + } + + this.delete = function(note_id){ + if(this.notes.hasOwnProperty(note_id)) this.notes.splice(note_id,1); + else console.log("ID is invalid"); + } +} -module.exports = function() { -} \ No newline at end of file diff --git a/notes_application_tests.js b/notes_application_tests.js index bcdd9c8..25133c3 100644 --- a/notes_application_tests.js +++ b/notes_application_tests.js @@ -10,13 +10,18 @@ describe("Check that creating a note object properly", function(){ it("should assign the note content based on the parameter supplied",function(){ var an_object = { author: "kachi", + note_content: "stuff" }; - var note = new Notes({author: "kachi", note_content: "stuff"}); + var note = new Notes(an_object); assert(note.note_content == "stuff"); }) it("should assign the author based on the parameter supplied",function(){ - var note = new Notes({author: "kachi", note_content: "stuff"}); + var an_object = { + author: "kachi", + note_content: "stuff" + }; + var note = new Notes(an_object); assert(note.author == "kachi"); }) }) @@ -43,7 +48,8 @@ describe("it should check if you can get a note", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); var check = new NotesApplication(); check.create_notes(note); - assert("stuff"); + check.get(0); + assert(check.notes[0].note_content === "stuff"); }) it("check that you can't retrieve a note with an invalid ID", function(){ @@ -75,8 +81,8 @@ describe("edit functionality works properly", function(){ }) }) -describe("that you can delete a note at index 1", function(){ - it("check that list notes returns notes ", function(){ +describe("that you can delete a note", function(){ + it("check that you can delete a note at index 1 ", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); var note2 = new Notes({author: "kachi", note_content: "stuff2"}); var check = new NotesApplication(); @@ -85,7 +91,6 @@ describe("that you can delete a note at index 1", function(){ assert(check.notes.length === 2); check.delete(1); assert(check.notes.length == 1); - assert(check.notes[1] === null); }) From 4f5e89076269c102db43601f69bf733c9bc23682 Mon Sep 17 00:00:00 2001 From: robocopkaka Date: Sun, 21 Aug 2016 23:13:44 +0100 Subject: [PATCH 3/3] Added tests for list_notes and search --- lib/notesapplication.js | 20 ++++++++ notes_application_tests.js | 102 +++++++++++++++++++++++-------------- 2 files changed, 83 insertions(+), 39 deletions(-) diff --git a/lib/notesapplication.js b/lib/notesapplication.js index ee91d2a..f6c518f 100644 --- a/lib/notesapplication.js +++ b/lib/notesapplication.js @@ -21,6 +21,26 @@ module.exports = function NotesApplication() { if(this.notes.hasOwnProperty(note_id)) this.notes.splice(note_id,1); else console.log("ID is invalid"); } + + this.list_notes = function(){ + var hold_notes = []; + for(var count = 0; count < this.notes.length; count++){ + hold_notes.push(this.notes[count]); + console.log("Note ID: " + count); + console.log("[" + this.notes[count].note_content + "]"); + console.log("By Author [" + this.notes[count].author + "]"); + }// nd for + return hold_notes; + } + + this.search = function(search_text){ + search_results = []; + for (var count = 0; count < this.notes.length; count++){ + if (this.notes[count].note_content.indexOf(search_text) !== -1) + search_results.push[this.notes.note_content] + } + return search_results; + } } diff --git a/notes_application_tests.js b/notes_application_tests.js index 25133c3..c21d5df 100644 --- a/notes_application_tests.js +++ b/notes_application_tests.js @@ -6,39 +6,39 @@ var assert = chai.assert; var NotesApplication = require('./lib/notesapplication.js'); var Notes = require('./lib/notes.js'); -describe("Check that creating a note object properly", function(){ +describe("Check that creating a note object works properly", function(){ it("should assign the note content based on the parameter supplied",function(){ - var an_object = { + var person = { author: "kachi", note_content: "stuff" }; - var note = new Notes(an_object); + var note = new Notes(person); assert(note.note_content == "stuff"); }) it("should assign the author based on the parameter supplied",function(){ - var an_object = { + var person = { author: "kachi", note_content: "stuff" }; - var note = new Notes(an_object); + var note = new Notes(person); assert(note.author == "kachi"); }) }) -describe("Shoud check that you can create a new note", function(){ +describe("should test that create note function works", function(){ it("it should check that a new entry was added", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); - var check = new NotesApplication(); - assert(check.notes.length === 0); - check.create_notes(note); - assert(check.notes.length === 1); + var noteapp_object = new NotesApplication(); + assert(noteapp_object.notes.length === 0); + noteapp_object.create_notes(note); + assert(noteapp_object.notes.length === 1); }) it("it should check if the parameter being supplied is an instance of the Notes class", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); - var check = new NotesApplication(); - check.create_notes(note); + var noteapp_object = new NotesApplication(); + noteapp_object.create_notes(note); assert.instanceOf(note, Notes); }) }) @@ -46,17 +46,17 @@ describe("Shoud check that you can create a new note", function(){ describe("it should check if you can get a note", function(){ it("check if you can retrieve a note with an ID of 0", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); - var check = new NotesApplication(); - check.create_notes(note); - check.get(0); - assert(check.notes[0].note_content === "stuff"); + var noteapp_object = new NotesApplication(); + noteapp_object.create_notes(note); + noteapp_object.get(0); + assert(noteapp_object.notes[0].note_content === "stuff"); }) - it("check that you can't retrieve a note with an invalid ID", function(){ + it("throws error when trying to get a note with an invalid id", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); - var check = new NotesApplication(); - check.create_notes(note); - check.get(4.5); + var noteapp_object = new NotesApplication(); + noteapp_object.create_notes(note); + noteapp_object.get(4.5); assert("ID is invalid"); }) @@ -65,18 +65,18 @@ describe("it should check if you can get a note", function(){ describe("edit functionality works properly", function(){ it("it should check that the content of a note at index 0 changes when edited", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); - var check = new NotesApplication(); + var noteapp_object = new NotesApplication(); - check.create_notes(note); - check.edit(0, "new stuff") - assert(check.notes[0].note_content === "new stuff"); + noteapp_object.create_notes(note); + noteapp_object.edit(0, "new stuff") + assert(noteapp_object.notes[0].note_content === "new stuff"); }) - it("check that you can't edit a note with an invalid ID", function(){ + it("throws an error when you try to edit a note with an invalid ID", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); - var check = new NotesApplication(); - check.create_notes(note); - check.edit(0.1, "new stuff") + var noteapp_object = new NotesApplication(); + noteapp_object.create_notes(note); + noteapp_object.edit(0.1, "new stuff") assert("ID is invalid") }) }) @@ -85,22 +85,46 @@ describe("that you can delete a note", function(){ it("check that you can delete a note at index 1 ", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); var note2 = new Notes({author: "kachi", note_content: "stuff2"}); - var check = new NotesApplication(); - check.create_notes(note); - check.create_notes(note2); - assert(check.notes.length === 2); - check.delete(1); - assert(check.notes.length == 1); + var noteapp_object = new NotesApplication(); + noteapp_object.create_notes(note); + noteapp_object.create_notes(note2); + assert(noteapp_object.notes.length === 2); + noteapp_object.delete(1); + assert(noteapp_object.notes.length == 1); }) - it("checks that you can't delete a note at an invalid index", function(){ + it("throws an error when you try to delete a note at an invalid index", function(){ var note = new Notes({author: "kachi", note_content: "stuff"}); var note2 = new Notes({author: "kachi", note_content: "stuff2"}); - var check = new NotesApplication(); - check.create_notes(note); - check.create_notes(note2); - check.delete(5.1); + var noteapp_object = new NotesApplication(); + noteapp_object.create_notes(note); + noteapp_object.create_notes(note2); + noteapp_object.delete(5.1); assert("ID is invalid") }) +}) + +describe("Check that the user can retrieve notes", function(){ + it("should check that the user can retrieve added notes", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var note1 = new Notes({author: "me", note_content: "more stuff"}); + var note2 = new Notes({author: "me", note_content: "more stuff"}); + var noteapp_object = new NotesApplication(); + noteapp_object.create_notes(note); + var hold_notes = noteapp_object.list_notes(); + assert.deepEqual([note], hold_notes); + }) +}) + +describe("Check that a user can search for text in notes", function(){ + it("should check that a user can search for specific text", function(){ + var note = new Notes({author: "kachi", note_content: "stuff"}); + var note1 = new Notes({author: "me", note_content: "more stuff"}); + var noteapp_object = new NotesApplication(); + noteapp_object.create_notes(note); + noteapp_object.create_notes(note1); + noteapp_object.search("s"); + assert(["stuff", "more stuff"]); + }) }) \ No newline at end of file