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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/**
26 changes: 26 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"env": {
"browser": true,
"node": true,
"commonjs": true,
"jest": true,
"es6": true
},
"globals": {
"err": true,
"req": true,
"res": true,
"next": true
},
"extends": "eslint:recommended",
"parserOptions": {
"sourceType": "module"
},
"rules": {
"no-console": "off",
"indent": [ "error", 2 ],
"quotes": ["error", "single", { "allowTemplateLiterals": true }],
"comma-dangle": ["error", "always-multiline"],
"semi": [ "error", "always" ]
}
}
3 changes: 1 addition & 2 deletions starter-code/.gitignore → .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Created by https://www.gitignore.io/api/vim,osx,linux,node
db
temp
Expand Down Expand Up @@ -97,4 +96,4 @@ jspm_packages
.npm

# Optional REPL history
.node_repl_history
.node_repl_history
Binary file added 20200125_020406.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
# class-01-Node-Ecosystem
# LAB - Class 01

### Author: Ghourob Ahmad Alswalqah
### Links and Resources
- [submission PR](https://github.com/Goorob-401-advanced-javascript/class-01-Node-Ecosystem/pull/1)
- [ci/cd](http://xyz.com) (GitHub Actions)


#### How to initialize/run your application (where applicable)
- `npm run test`
#### Tests
- How do you run tests? `npm run test`
- Any tests of note? none
- Describe any tests that you did not complete, skipped, etc
#### UML
[UML](https://github.com/Goorob-401-advanced-javascript/class-01-Node-Ecosystem/blob/lab1/20200125_020406.jpg)
116 changes: 116 additions & 0 deletions __tests__/validator.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
'use strict';

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

describe('validator module performs basic validation of', () => {

// TODO: Make this series of tests less repetitive ... DRY it out

it('strings', () => {
let str = 'yes';
let num = 1;
let arr = ['a'];
let obj = {x:'y'};
let func = () => {};
let bool = false;
expect(validator.isString(str)).toBeTruthy();
// expect(validator.isNum(num)).toBeTruthy();
// expect(validator.isString(arr)).toBeFalsy();
// expect(validator.isString(obj)).toBeFalsy();
// expect(validator.isString(func)).toBeFalsy();
// expect(validator.isString(bool)).toBeFalsy();
});

it('numbers', () => {
let num = 6 ;
expect(validator.isNum(num)).toBeTruthy();
});

it('arrays', () => {
let arr =[];
expect(validator.isObjest(arr)).toBeTruthy();
});

it('objects', () => {
let obj = {};
expect(validator.isObjest(obj)).toBeTruthy();
});

it('booleans', () => {
let bool = false ;
expect(validator.isBooleen(bool)).toBeTruthy();
});

it('functions', () => {
let func = {};
expect(validator.isObjest(func)).toBeTruthy();
});

});

describe('validator module performs complex validations', () => {

it('validates if the input is function ', () => {
const fred = {
id:38,
name:'Freddy McCoder',
age: 20 ,
children:[],
};
expect(validator.isObjest(fred)).toBeTruthy();
});
it('validates if theres a key ', () => {
const fred = {
id:38,
name:'Freddy McCoder',
age: 20 ,
children:[],
};
expect(validator.isThereKeys(fred)).toBeTruthy();
});
it('validates the proper types of object properties', () => {

const fred = {
id:38,
name:'Freddy McCoder',
age: 20 ,

};

expect(validator.validateObjValueType(fred)).toBeTruthy();
});

it('validates the proper types of object properties', () => {

const fred = {
id:38,
name:'Freddy McCoder',
age: 20 ,
children:[],
};
expect(validator.isThereValues(fred)).toBeTruthy();
});

it('validates the types of values contained in an array', () => {
const fred = {
id:38,
name:'Freddy McCoder',
age: 20 ,
children:[],
};
expect(validator.validateObjValueIfArr(fred.children)).toBeTruthy();
});

it('validates a value array against an approved list', () => {
const fred = {
id:38,
name:'Freddy McCoder',
age: 20 ,
children:[],
};
expect(validator.arrHasAnValues(fred)).toBeFalsy();
});

// TODO: Cover so, so many more cases

});
2 changes: 1 addition & 1 deletion starter-code/index.js → index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

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

validator.isValid();
validator.isValid();
103 changes: 103 additions & 0 deletions lib/validator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
'use strict';

let validator = module.exports = {};

/**
* Based on a set of rules, is the input valid?
* Is this object ?
* @param input
* @param rules
* @returns {boolean}
*/
validator.isObjest = (input) => {
return typeof (input) === 'object';
};
/**
* Based on a set of rules, is the input valid?
* Is the object have keys ?
* @param input
* @param rules
* @returns {boolean}
*/
validator.isThereKeys = (input) => {
if (Object.keys(input)) { return true };
};
/**
* Based on a set of rules, is the input valid?
* Is the object have values ?
* @param input
* @param rules
* @returns {boolean}
*/
validator.isThereValues = (input) => {
if (Object.values(input)) { return true };
};
/**
/**
* Based on a set of rules, is the input valid?
* What is the type of values ?
* @param input
* @param rules
* @returns {boolean}
*/
validator.validateObjValueType = (input) => {
return Object.values(input).every(val=> typeof val === 'string' || typeof val === 'number' || typeof val === 'object')
}
/**
* Based on a set of rules, is the input valid?
* Is the object have array ?
* @param input
* @param rules
* @returns {boolean}
*/
validator.validateObjValueIfArr = (input) => {
return Object.values(input).every(val => typeof val === 'object')
};
/**
* Is this a string?
* @param input
* @returns {boolean}
*/
validator.arrHasAnValues = (input) => {
Object.values(input).every(ele => {
if (typeof ele === 'object') {
if (ele.length > 0 ) {
return true
} else {
return false
} }
})
}
/**
* Is this a string?
* @param input
* @returns {boolean}
*/
validator.isString = (input) => {
return typeof (input) === 'string';
};
/**
* Is this a num?
* @param input
* @returns {boolean}
*/
validator.isNum = (input) => {
return typeof (input) === 'number';
};

/**
* Is this a bool?
* @param input
* @returns {boolean}
*/
validator.isBooleen = (input) => {
return typeof (input) === 'boolean';
};
/**
* Is this a num?
* @param input
* @returns {boolean}
*/
validator.isArray = (input) => {
return typeof (input) === 'object';
};
Loading