Skip to content

Classes #2

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

Merged
merged 13 commits into from
Apr 4, 2020
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
6 changes: 6 additions & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
**/node_modules/*
**/docs/*
**/vendor/*
**/*.min.js
**/coverage/*
**/build/*
25 changes: 25 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"fail":true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2018
},
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"comma-dangle": ["error", "always-multiline"],
"semi": [ "error", "always" ],
"no-unused-vars": [1, {"vars": "local", "args": "none"}]
}
}
145 changes: 145 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# 401 JS
db
.env
temp
build

# Created by https://www.gitignore.io/api/vim,osx,node,linux,windows
### Linux ###
*~

# temporary files which can be created if a process still has a handle open of a deleted file
.fuse_hidden*

# KDE directory preferences
.directory

# Linux trash folder which might appear on any partition or disk
.Trash-*

# .nfs files are created when an open file is removed but is still being accessed
.nfs*

### Node ###
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env


### OSX ###
*.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk

### Vim ###
# swap
[._]*.s[a-v][a-z]
[._]*.sw[a-p]
[._]s[a-v][a-z]
[._]sw[a-p]
# session
Session.vim
# temporary
.netrwhist
# auto-generated tag files
tags

### Windows ###
# Windows thumbnail cache files
Thumbs.db
ehthumbs.db
ehthumbs_vista.db

# Folder config file
Desktop.ini

# Recycle Bin used on file shares
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msm
*.msp

# Windows shortcuts
*.lnk

# End of https://www.gitignore.io/api/vim,osx,node,linux,windows
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
# notes
# LAB - Class 01

## Notes

### Author: Joel Watson

### Links and Resources

- [submission PR (lab-01)](https://github.com/401-advanced-javascript-joel/notes/pull/1)
- [submission PR (lab-02)](https://github.com/401-advanced-javascript-joel/notes/pull/2)
- [ci/cd](https://github.com/401-advanced-javascript-joel/notes/runs/518200179) (GitHub Actions)
- [NPM](https://www.npmjs.com/package/@fellowjoel/notes)

### Setup

- `npm install`

#### How to run

Example of adding a note to the database (must use -a or --add)

- `node index.js notes --add "Hello, I am an example note"`

#### Tests

- `npm test`

#### UML

![UML01](https://raw.githubusercontent.com/JoelMWatson/data-structures-and-algorithms/master/assets/notes.jpg)
![UML02](https://raw.githubusercontent.com/JoelMWatson/data-structures-and-algorithms/master/assets/classes.jpg)
29 changes: 29 additions & 0 deletions __tests__/input.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

const Input = require('../lib/input');

describe('Testing input module rejects invalid input', () => {
test('handles empty input', () => {
let result = new Input([]);
expect(result.valid()).toBeFalsy();
});
test('handles wrong input format', () => {
let result = new Input(['WRONG']);
expect(result.valid()).toBeFalsy();
});
test('handles wrong flag input', () => {
let result = new Input(['-b', 'WRONG']);
expect(result.valid()).toBeFalsy();
});
test('handles wrong data type input', () => {
let result = new Input(['-a', 'false']);
expect(result.valid()).toBeFalsy();
});
});

describe('The instance methods returns the right thing given various valid inputs', () => {
test('handles valid input', () => {
let result = new Input(['-a', 'This is a correctly formatted note.']);
expect(result).toBeTruthy();
});
});
47 changes: 47 additions & 0 deletions __tests__/notes.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

const Notes = require('../lib/notes');

describe('Testing notes module handles add action when supplied valid parameters.', () => {
test('new note is logged to the console', () => {
// creating a spy on the console
const spy = jest.spyOn(console, 'log');
const notes = new Notes();

// run add
notes.execute({ action: 'add', payload: 'Hello, I am a test note' });

expect(spy).toHaveBeenCalled();
});

test('new note is added to the notes.db', () => {
const notes = new Notes();

// run add
notes.execute({ action: 'add', payload: 'Hello, I am a test note' });

expect(notes.db[0].note_text).toBe('Hello, I am a test note');
});
});

describe('Testing notes module handles add action when supplied invalid parameters.', () => {
test('new note isn\'t logged to the console', () => {
// creating a spy on the console
const spy = jest.spyOn(console, 'log');
const notes = new Notes();

// run add
notes.execute({ action: 'add', payload: '' });

expect(spy).toHaveBeenCalled();
});

test('new note isn\t added to the notes.db', () => {
const notes = new Notes();

// run add
notes.execute({ action: 'add', payload: '' });

expect(notes.db[0]).toBe(undefined);
});
});
61 changes: 61 additions & 0 deletions __tests__/validator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
'use strict';

const Validator = require('../lib/validator');

describe('Testing validator module handles validate when supplied valid parameters.', () => {
test('validate returns true with correct valid input', () => {
const validator = new Validator({
id: {type: 'string', required: true},
name: {type: 'string', required: true},
age: {type: 'number', required: true},
});

// run add
const result = validator.validate({
id:'123-45-6789',
name:'Susan McDeveloperson',
age: 37,
});
expect(result).toBeTruthy();
});

test('validate returns true with correct valid input', () => {
const validator = new Validator({
action: { type: 'string', required: true },
id: { type: 'number', required: true },
});

// run add
const result = validator.validate({ action: 'apple', id: 1 });
expect(result).toBeTruthy();
});
});

describe('Testing validator module handles validate when supplied invalid parameters.', () => {
test('validate returns false with correct invalid input', () => {
// creating a spy on the console
const validator = new Validator({
id: {type: 'string', required: true},
name: {type: 'string', required: true},
age: {type: 'number', required: true},
children: { type: 'array', valueType: 'string' },
});
// run add
const result = validator.validate({
id:38,
name:'Freddy McCoder',
children:[],
});
expect(result).toBeFalsy();
});

test('validate returns false with correct invalid input', () => {
const validator = new Validator({
action: { type: 'string', required: true },
id: { type: 'boolean', required: true },
});
// run add
const result = validator.validate({});
expect(result).toBeFalsy();
});
});
Loading