Skip to content
Merged
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
14 changes: 8 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,17 @@

### Author: Dave Wolfe

## Acknowledgements

I'd like to thank Gahrett Morgan, Paul Depew, and Matthew Roark for their help on this app.

### Links and Resources

- [submission PR 1](https://github.com/wolfes-401-advanced-javascript/notes/pull/1)
- [submission PR 2](https://github.com/wolfes-401-advanced-javascript/notes/pull/2)
- [submission PR 3](https://github.com/wolfes-401-advanced-javascript/notes/pull/3)
- [submission PR 4](https://github.com/wolfes-401-advanced-javascript/notes/pull/4)
- [ci/cd](http://xyz.com) (GitHub Actions)
- [back-end server url](http://xyz.com) (when applicable)
- [front-end application](http://xyz.com) (when applicable)
- [ci/cd](https://github.com/wolfes-401-advanced-javascript/notes/actions) (GitHub Actions)

### Setup

Expand All @@ -33,9 +35,9 @@

#### Tests

- How do you run tests?
- Any tests of note?
- Describe any tests that you did not complete, skipped, etc
- How do you run tests? `npm test`
- Any tests of note? I really like the test where I create a new note and then delete it.


#### UML

Expand Down
20 changes: 16 additions & 4 deletions __tests__/input.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

jest.mock('minimist');
const minimist = require('minimist');
minimist.mockImplementation( () => {
minimist.mockImplementationOnce( () => {
return {
a: 'hello world',
'a': 'hello world',
};
}).mockImplementationOnce(() => {
return {
'a': 'hello world',
};
});

Expand All @@ -14,6 +18,14 @@ describe('Testing the input.js module to verify user input is successfully being
it('should return an action and a payload', () => {
let test = new Input();
expect(test.payload).toBe('hello world');

});
});
});

describe('Test validate with valid action and valid string', () => {
it('should return true if action and payload are valid', () => {
let test = new Input();
expect (test.validate()).toBe(true);
});
});

31 changes: 31 additions & 0 deletions __tests__/notes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
'use strict';

const Notes = require('../lib/notes.js');
const supergoose = require('cf-supergoose');

const spy = jest.spyOn(global.console, 'log');

describe('Tests the add and list functions', () => {
it('should return the console logs and insert a new note to the collection', () => {
const myNotes = new Notes({a: 'Global Test'});
myNotes.execute();
expect(spy).toHaveBeenCalled();
const myNewNote = new Notes({l: 'Global Test'});
myNewNote.execute();
expect(myNewNote).not.toEqual(undefined);
});
});

describe('Tests the delete function', () => {
it('should return the console logs and delete a note from the collection', () => {
const myNotes = new Notes({a: 'New note to insert/delete'});
myNotes.execute();
expect(spy).toHaveBeenCalled();
const deleteMyNote = new Notes({d: myNotes.id});
deleteMyNote.execute();
const myNewNote2 = new Notes({l: 'Global Test'});
myNewNote2.execute();
expect(myNewNote2.action).toEqual(undefined);
});
});

19 changes: 7 additions & 12 deletions lib/input.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
'use strict';

const minimist = require('minimist');

const args = minimist(process.argv.slice(2));
// console.log(args);
let action = (Object.keys(args).slice(1));

let message = (Object.values(args).slice(1));
console.log(args);

let action = (Object.keys(args).slice(-1));
let message = (Object.values(args).slice(-1));

class Input {
constructor() {
Expand All @@ -17,16 +17,11 @@ class Input {
}
validate() {
const ops = ['a', 'add', 'l', 'list', 'd', 'delete', 'u', 'update'];
let validOp = false;
let validString = false;

const emptyString = '';
console.log(this.action);

if (ops.includes(this.action)) validOp = true;
// if (ops.includes(this.category)) validOp = true;
if (this.payload !== emptyString) validString = true;
// if (this.catName !== emptyString) validString = true;

return validOp && validString;
return (ops.includes(this.action)) && (this.payload !== emptyString);
}
}

Expand Down
5 changes: 2 additions & 3 deletions lib/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class Notes {
}

execute() {
const action = ['add', 'a', 'list', 'l', 'delete', 'd', 'u', 'update'];
console.log(this.action);
switch (this.action) {
case 'add':
Expand All @@ -29,8 +28,8 @@ class Notes {
case 'd':
this.delete();
break;
case 'update':
case 'u':
case 'update':
case 'u':
this.update();
break;
default:
Expand Down
Loading