Skip to content

Bootcamp boilerplate #3

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

Open
wants to merge 3 commits into
base: bootcamp-boilerplate
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
8 changes: 6 additions & 2 deletions lib/notes.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// Note class
/**
* Note class for creating authors' notes
*/

module.exports = function() {

module.exports = function(author, note_content) {
this.author = author;
this.note_content = note_content;
}
121 changes: 120 additions & 1 deletion lib/notesapplication.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,124 @@
// NotesApplication class

var Note = require("./notes.js")

/**
* NotesApplication class for managing authors' notes
*/

module.exports = function() {

}
this.notesList = [];


/**
* Adds a note to the NotesApplication instance
* @param {Note} note A note object
*/
this.create = function(note) {
if (note instanceof Note) {
this.notesList.push(note);
} else {
return "The Object supplied is not a note!"
}
}


/**
* Operates on an instance of NotesApplication
* Lists all the notes in the application
*/
this.listNotes = function() {
if (this.notesList.length < 1) {
return [];
} else {
for (var i = 0; i < this.notesList.length; i++) {
console.log("Note ID: " + i + "\n"
+ "CONTENT: " + this.notesList[i].note_content + "\n"
+ "By Author " + this.notesList[i].author + "\n")
}
return this.notesList;
}

}


/**
* Operates on an instance of NotesApplication
* Fetches the note at
* @param {Number} note_id The index of the note within the list of notes
*/
this.getNote = function(note_id) {
var note = this.notesList[note_id]
if (note)
return note
return "No note with ID " + "'" + note_id + "'"
}



/**
* Operates on an instance of NotesApplication
* Searches all notes that match a certain string
* @param {string} search_text The text to search for.
*/
this.searchNote = function(search_text) {
if (this.notesList.length < 1) {
return "O Results Found";
} else {
var notesFound = []

for (var i = 0; i < this.notesList.length; i++) {
if (this.notesList[i].note_content.indexOf(search_text) > -1)
notesFound.push(this.notesList[i])
}

if (notesFound.length < 1) {
return "0 Results Found";
} else {
for (var j = 0; j < notesFound.length; j++) {
console.log( "Showing results for search " + "'" + search_text + "'" + "\n"
+ "Note ID: " + j + "\n"
+ "CONTENT: " + this.notesList[j].note_content + "\n"
+ "By Author " + this.notesList[j].author + "\n" )
}
return notesFound.length + " Results Found"
}
}
}


/**
* Operates on an instance of NotesApplication
* Deletes the note at
* @param {Number} note_id The index of the note within the list of notes
*/
this.deleteNote =function(note_id) {
var note = this.notesList[note_id]
if (note) {
this.notesList.pop(note)
return "Note with ID of " + note_id + " succcessfully deleted!";
} else {
return "Note with ID of " + note_id + " is not in the Application!";
}
}


/**
* Operates on an instance of NotesApplication
* Edits the note at
* @param {Number} note_id The index of the note within the list of notes
* @param {string} new_content The new content to add
*/
this.editNote = function(note_id, new_content) {
var note = this.notesList[note_id]
if (note) {
note.note_content = new_content;
return "Note with ID of " + note_id + " succcessfully edited!"
} else {
return "Note with ID of " + note_id + " is not in the Application!"
}
}
}


128 changes: 116 additions & 12 deletions tests.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,128 @@
'use strict'
// 'use strict'

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("creates a note with parameters author and note_content", function() {
var note = new Note("This is my first note");
assert(note.hasOwnProperty("author"))
assert(note.hasOwnProperty("note_content"))

})

it("assigns author based on the parameter supplied in the constructor", function() {
note = new Note("Hello world", "Chidiebere")
assert(note.author == "Chidiebere")
var note = new Note("Chidiebere", "Hello world");
assert(note.author === "Chidiebere")
})

it("assigns note content based on the parameter supplied in the constructor", function() {
var note = new Note("Awa", "Welcom Awa");
assert(note.note_content === "Welcom Awa");
})
})

describe("Notes application increments number of notes as notes are added", function() {
it("increments the note list as notes are added", function() {
note = new Note("Hello world", "Chidiebere");
noteapp = new NotesApplication("Chidiebere");
assert(noteapp.notelist.length == 0)
noteapp.addNote(note)
assert(noteapp.notelist.length == 1)
describe("Notes application works properly", function() {

it("creates an empty list of notes when notes application is created", function() {
var noteapp = new NotesApplication();
assert(noteapp.notesList)
})

it("implements the create, getNote, searchNote, listNotes, editNote and deleteNote functions", function() {
var noteapp = new NotesApplication();
assert(noteapp.hasOwnProperty("create"))
assert(noteapp.hasOwnProperty("getNote"))
assert(noteapp.hasOwnProperty("searchNote"))
assert(noteapp.hasOwnProperty("listNotes"))
assert(noteapp.hasOwnProperty("editNote"))
assert(noteapp.hasOwnProperty("deleteNote"))
})

it("adds notes successfully", function() {
var note = new Note("Chidiebere", "Hello world");
var noteapp = new NotesApplication();
var len = noteapp.notesList.length

noteapp.create(note)
var new_len = noteapp.notesList.length
assert(new_len === (len + 1));
assert(note === noteapp.notesList[0]);
})

it("retrieves notes successfully", function() {
var note = new Note("Chidiebere", "Hello world");
var noteapp = new NotesApplication();
noteapp.create(note)
assert(noteapp.getNote(0) === note)
assert(noteapp.getNote(5) === "No note with ID " + "'" + 5 + "'")
})


it("searches for notes successfully", function() {
var note1 = new Note("Chidiebere", "Hello world");
var noteapp = new NotesApplication();

assert(noteapp.searchNote("world") == "O Results Found")

noteapp.create(note1);
assert(noteapp.searchNote("world") == "1 Results Found");

var note2 = new Note("Awa", "working with Functions");
noteapp.create(note2);

assert(noteapp.searchNote("wor") === "2 Results Found");
assert(noteapp.searchNote("Awa") === "0 Results Found")


})


it("returns a list of notes or an empty list if no list is present", function() {
var noteapp = new NotesApplication();
assert(noteapp.listNotes().length === 0)

var note1 = new Note("Awa", "Hello world");
var note2 = new Note("Awa", "Working with Functions");


noteapp.create(note1);
noteapp.create(note2);

assert(noteapp.listNotes() === noteapp.notesList)
assert(noteapp.notesList.length === 2)
})


it("deletes note correctly", function() {
var note = new Note("Chidiebere", "Hello world");
var noteapp = new NotesApplication();

assert(noteapp.notesList.length === 0)

noteapp.create(note);
assert(noteapp.notesList.length === 1)

noteapp.deleteNote(0)
assert(noteapp.notesList.length === 0)
})
})

it("edits notes correctly", function() {
var note = new Note("Awa", "Hello world");
var noteapp = new NotesApplication();
noteapp.create(note);

assert(noteapp.notesList[0] === note)

noteapp.editNote(0, "Going Deeper in Javascript")

assert(noteapp.notesList[0].note_content === "Going Deeper in Javascript")

})
})