29 Commits

Author SHA1 Message Date
Mohammed Ashab Uddin
2aae4fe6e9 small fixes 2020-07-28 10:46:02 +04:00
Mohammed Ashab Uddin
e71e9f372b fixed entity map problems 2020-07-28 10:44:40 +04:00
Mohammed Ashab Uddin
595941341d staged 2020-07-27 10:15:48 +04:00
Baber-Jan
ff7eb53eef Single change 2020-07-26 20:10:58 +04:00
Baber-Jan
eeb04e1615 Did the required changes 2020-07-26 19:12:51 +04:00
Baber-Jan
d53380616e Did the required change 2020-07-25 22:13:01 +04:00
Mohammed Ashab Uddin
416deb477c fixed bug in command.js 2020-07-25 21:19:59 +04:00
Mohammed Ashab Uddin
d4be542a91 fixed bug in command.js 2020-07-25 21:17:11 +04:00
Mohammed Ashab Uddin
90a14a9e1b added default value to the object parameter 2020-07-25 10:46:30 +04:00
Mohammed Ashab Uddin
0b0569b783 deleted all the logic.onWg() 2020-07-25 10:15:33 +04:00
Baber-Jan
c58bc1ce91 I Think the product functions are done. 2020-07-24 19:11:38 +04:00
Mohammed Ashab Uddin
6288eefa99 Merge remote-tracking branch 'origin' 2020-07-24 16:00:34 +04:00
Mohammed Ashab Uddin
11063d120d fixed gettng input from the message 2020-07-24 15:59:23 +04:00
Mohammed Ashab Uddin
507e62e049 added input functionalities on command 2020-07-24 14:58:32 +04:00
Akilan Selvacoumar
2a1ade4f25 Merge pull request #5 from HWTechClub/dependabot/npm_and_yarn/website-generator/lodash-4.17.19
Bump lodash from 4.17.15 to 4.17.19 in /website-generator
2020-07-24 11:45:37 +04:00
Baber-Jan
4ca9d1418c moved some code to logic.j 2020-07-23 20:23:15 +04:00
Baber-Jan
2f653468e6 Added all the product methods, now have to figure out how to use id in call back function 2020-07-23 20:02:16 +04:00
dependabot[bot]
60367476d8 Bump lodash from 4.17.15 to 4.17.19 in /website-generator
Bumps [lodash](https://github.com/lodash/lodash) from 4.17.15 to 4.17.19.
- [Release notes](https://github.com/lodash/lodash/releases)
- [Commits](https://github.com/lodash/lodash/compare/4.17.15...4.17.19)

Signed-off-by: dependabot[bot] <support@github.com>
2020-07-22 10:10:57 +00:00
Mohammed Ashab Uddin
ca46a66283 getAllData() is added 2020-07-22 11:01:47 +04:00
Mohammed Ashab Uddin
7b0779d552 added and used entity methods 2020-07-22 10:51:29 +04:00
Mohammed Ashab Uddin
596f56b708 StructuredData uses entity to store data 2020-07-22 10:43:52 +04:00
Mohammed Ashab Uddin
1535d4cec0 added entity 2020-07-22 10:43:05 +04:00
Mohammed Ashab Uddin
29db39c642 Added mocha and chai for testing 2020-07-22 10:42:51 +04:00
Mohammed Ashab Uddin
9c7f90a102 fixed bugs 2020-07-22 08:30:01 +04:00
ashab272000
401aa1a17d Update commands.md 2020-07-22 08:25:18 +04:00
ashab272000
07f3c114e0 Update README.md 2020-07-22 08:20:03 +04:00
ashab272000
4924eaef2c Update commands.md 2020-07-22 07:58:48 +04:00
ashab272000
1513186a45 Merge pull request #7 from HWTechClub/npmBot
Npm bot
2020-07-21 14:56:58 +04:00
ashab272000
23ceb9fe14 Merge pull request #4 from HWTechClub/npmBot
Integrated the whatsapp bot from npm.
2020-07-20 15:18:19 +04:00
15 changed files with 1766 additions and 132 deletions

View File

@@ -9,21 +9,45 @@ In this project we will illustrate how to build a static web page using commands
## Installation ## Installation
Requirements : Node js and Npm Requirements : Node js and Npm
### To start web generator ### Install web generator
First, go to the folder named **website-generator**.
Then install all the node modules.
``` ```
cd website-generation cd website-generation
npm install
``` ```
Installation : https://github.com/Tech-club/Challenge-1/tree/master/website-generator#installation
### Install whatsapp bot
### To start whatsapp bot First, go to the folder named **whatsapp-web.js**.
Then install all the node modules.
``` ```
cd whatsapp-web.js cd whatsapp-web.js
npm install npm install
```
### Start the website generator
Make sure you are in **website-generator** directory. Then type the following command :
```
npm start npm start
``` ```
For more information on deploying the server in IPFS, please click the following link:
https://github.com/Tech-club/Challenge-1/tree/master/website-generator#installation
### Start whatsapp bot
Make sure you are in **whatsapp-web.js** directory. Then type the following command :
```
npm start
```
### Start generating websites with whatsapp
You need to start both website-generator and whatsapp-bot.
### Contributors ### Contributors
1. Akilan Selvacoumar : as251@hw.ac.uk 1. Akilan Selvacoumar : as251@hw.ac.uk

View File

@@ -1132,9 +1132,9 @@
"integrity": "sha1-ZMTwJfF/1Tv7RXY/rrFvAVp0dVA=" "integrity": "sha1-ZMTwJfF/1Tv7RXY/rrFvAVp0dVA="
}, },
"lodash": { "lodash": {
"version": "4.17.15", "version": "4.17.19",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.15.tgz", "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.19.tgz",
"integrity": "sha512-8xOcRHvCjnocdS5cpwXQXVzmmh5e5+saE2QGoeQmbKmRS6J3VQppPOIt0MnmE+4xlZoumy0GPG0D0MVIQbNA1A==" "integrity": "sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ=="
}, },
"lodash.debounce": { "lodash.debounce": {
"version": "4.0.8", "version": "4.0.8",

File diff suppressed because it is too large Load Diff

View File

@@ -4,7 +4,8 @@
"description": "", "description": "",
"main": "test.js", "main": "test.js",
"scripts": { "scripts": {
"test": "node website_test.js http://localhost:8004", "test-web": "node website_test.js http://localhost:8004",
"test" : "mocha",
"start": "node index.js" "start": "node index.js"
}, },
"author": "", "author": "",
@@ -12,5 +13,9 @@
"dependencies": { "dependencies": {
"request": "^2.88.2", "request": "^2.88.2",
"whatsapp-web.js": "^1.7.0" "whatsapp-web.js": "^1.7.0"
},
"devDependencies": {
"chai": "^4.2.0",
"mocha": "^8.0.1"
} }
} }

View File

@@ -1,5 +1,6 @@
const { Website } = require("../models/website"); const { Website } = require("../models/website");
const { data } = require("../models/data"); const { data } = require("../models/data");
const { Product } = require('../models/product');
module.exports.onWG = () => { module.exports.onWG = () => {
console.log('hello world'); console.log('hello world');
@@ -18,3 +19,26 @@ module.exports.onCreate = (id, companyName) => {
//add the website with the company name //add the website with the company name
user.addWebsite(new Website(companyName)); user.addWebsite(new Website(companyName));
} }
module.exports.addProduct = (id,website) => {
if(id==null)
{
// Setting up the product id if not given
id = Math.floor((Math.random() * 100000) + 1);
while(website.products.isData(id))// This is will check if the generated id is already used
{
id = Math.floor((Math.random() * 100000) + 1);
}
}
// Create a product and select it. At this point all the product properties will be default including the id will be empty
var product = new Product();
product.setId(id);
// Add a product to the selected website. We will add the id based on the count of the products on the website
website.addProduct(product);
return product;
}
module.exports.deleteProduct = (id,website) => {
return website.deleteProduct(id);
}

View File

@@ -1,47 +1,41 @@
# Commands available for user interaction # Commands available for user interaction
*wg* -> Command wg help to get the avaialabe instructions `wg` -> Command wg help to get the avaialabe instructions.
*wg help* -> The following are the available commands: `wg help` -> All the commands will be made be displayed to the user.
*wg create <company name> -> creates a website without details `wg website <company name>` -> if a website exists with the same **company name**, then that website is selected, else it creates a new website.
# Note: ### Note:
After the user uses *wg create <company name>*. The bot should instruct the user to enter the rest of the details. After the user uses `wg create <company name>`. The bot should instruct the user to enter the rest of the details.
To see the details to be entered, please check *website.js* under models folder. To see the details to be entered, please check [website.js](https://github.com/HWTechClub/Custom-Static-Website-Generator/blob/master/whatsapp-web.js/src/models/website.js) under models folder.
The commands should follow the rules below : The commands should follow the rules below :
*wg website firstName* `wg website firstName`, `wg website lastName`, etc..
*wg website lastName*
...etc
### Following commands only works when a website is created
`wg product all` -> shows all the products that are created.
`wg product new` -> creates a new product with generated Id.
`wg product <id>` -> if the id exists, the product with *id* is selected, else, create a new product with the id given.
### NOTE :
# Following commands only works when a website is created
*wg product all* -> shows all the products that are created
*wg product new* -> creates a new product with generated Id
*wg product <id>* -> if the id exists, the product with “id“ is selected, else, create a new product with the id given
# NOTE :
User should be given feedback on their commands. For example: User should be given feedback on their commands. For example:
If a user created a product, the bot should reply, "a product has been created with the id : <id>" If a user created a product, the bot should reply, *a product has been created with the id : <id>*.
If a user created a product without a website, the bot should handle the error and reply, "A website should be selected or created before creating a product" If a user created a product without a website, the bot should handle the error and reply, *A website should be selected or created before creating a product*.
# Following command only works if a product is selected ### Following command only works if a product is selected
*wg product info* -> shows the information about the product. Ie name, cost, description, image `wg product info` -> shows the information about the product. Ie name, cost, description, image.
*wg product name* <product-name> -> set the name of the product `wg product name <product-name>` -> set the name of the product.
*wg product cost* <product-cost> -> set the cost of the product `wg product cost <product-cost>` -> set the cost of the product.
*wg product desc* <product-desc> -> set the description of the product `wg product desc <product-desc>` -> set the description of the product.
*wg product image* <product-image> -> sets the image of the product. The caption of the image should be the command. `wg product image <product-image>` -> sets the image of the product. The caption of the image should be the command.
*wg finished* -> creates the website and gives a link to the website maker
# delete
Users should be able to delete products and website
*wg delete product <id>*
*wg delete website <company name>*
### Create the website
`wg website finished` -> creates the website and gives a link to the website maker.
# Delete
Users should be able to delete products and website.
`wg delete product <id>`, `wg delete website <company name>`
# Note: # Note:
If you think these commands are not enough, please add them in a seperate section with a clear defination. If you think these commands are not enough, please add them in a seperate section with a clear defination.

View File

@@ -1,10 +1,100 @@
class Command{ class Command{
/**
*
* @param {{string, function()}} param0
*/
constructor({command,callback}){ constructor({command,callback}){
this.command = command; this.command = command;
this.callback = callback; this.callback = callback;
this.requireInput = false;
this.inputPos = [];
this._requireInput();
}
/**
*
* @param {string} message
*/
equals(message){
let msg = message.trim();
//check if the command is exactly equals to the msg
//if mathces then return true
//else if we check if the command requires an input
//if not, then we return false
if(this.command == msg){
return true
}else if(this.requireInput){
//the command requires input
let splitCommand = this.command.split(' ');
let splitMsg = msg.split(' ');
//check the number of words both has
//if not same then return false
//else iterate through all the words
if(splitCommand.length == splitMsg.length)
{
for(let i = 0; i < splitMsg.length; i++)
{
//if words matches then continue
//if the word is a input then continue
//else return false
if(splitMsg[i] == splitCommand[i]){
continue;
}else if(splitCommand[i].match(/[<>]/g) != null){
continue;
}else{
return false;
}
}
// all the words are matched to each other or to an input field
return true;
}
//the message is not the same as the command
return false;
}
return false;
}
/**
* Only used in class
*
* This determines if the command requires input
* if the command has <inputName> in the string
* then the command requires input
*/
_requireInput(){
let msg = this.command;
let matched = msg.match(/[<>]/g);
this.requireInput = matched != null && matched.length > 1;
}
/**
* returns an array of string representing the inputs of the command
* @param {string} message
*/
getInput(message){
let splitMsg = message.split(' ');
let splitCommand = this.command.split(' ');
let input = {};
for(let i = 0; i < splitMsg.length; i++){
if(splitCommand[i].startsWith('<')){
let key = splitCommand[i].slice(1, splitCommand[i].length-1);
input[key] = splitMsg[i];
} }
} }
return input;
}
}
module.exports.Command = Command; module.exports.Command = Command;

View File

@@ -1,22 +1,18 @@
const { Entity } = require("./entity");
const { User } = require("./user"); const { User } = require("./user");
const { Website } = require("./website");
module.exports.data = new StructuredData();
class StructuredData { class StructuredData {
constructor() { constructor() {
this.data={}; this.entity = new Entity();
} }
/**
addUser(id){ * Adds a user
if(this.data[id] != undefined) * @param {User} user
{ */
this.data[id] = new User(id); addUser(user){
return true return this.entity.addData(user.id, user);
}
return false;
} }
/** /**
@@ -25,22 +21,37 @@ class StructuredData {
* @returns {User} * @returns {User}
*/ */
getUser(id){ getUser(id){
return this.data[id]; return this.entity.getData(id);
} }
/**
* Delete the user with a specific id
* @param {string} id
*/
deleteUser(id){ deleteUser(id){
if(this.data[id] != undefined) return this.entity.deleteData(id)
{
return delete this.data[id];
} }
return false; /**
* Check if a user with the given id exists
* @param {string} id
*/
isUser(id){
return this.entity.isData(id);
}
/**
* Clears all the data stored
*/
clearData(){
this.entity.clearData();
} }
} }
module.exports.data = new StructuredData();
/* /*
data structured: data structured:
data = { data = {

View File

@@ -0,0 +1,51 @@
class Entity {
constructor(){
this.data = new Map();
this.count = 0;
}
addData(key ,value){
if(!this.isData(key)){
this.data.set(key, value);
return true;
}
return false;
}
/**
* check if key exists
* @param {string} key
*/
isData(key){
return this.data.has(key) ? true : false;
}
deleteData(key){
if(this.isData(key)){
this.data.delete(key);
return true;
}
return false;
}
clearData(){
this.data = new Map();
this.count = 0;
}
getData(key){
if(this.isData(key)){
return this.data.get(key);
}
return null;
}
getAllData(){
return this.data;
}
}
module.exports.Entity = Entity;

View File

@@ -1,7 +1,7 @@
class Product { class Product {
constructor({ id = '', name = '', desc = '', cost = 0, image = null }) { constructor({ id = '', name = '', desc = '', cost = 0, image = null } = {}) {
this.id = id; this.id = id;
this.name = name; this.name = name;
this.desc = desc; this.desc = desc;
@@ -9,40 +9,40 @@ class Product {
this.image = image; this.image = image;
} }
getId(){ /**
return this.id; *
* @param {Number} id
*/
setId(id){
return this.id = id;
} }
/**
*
* @param {String} name
*/
setName(name){ setName(name){
this.name = name; return this.name = name;
} }
/**
getName(){ *
return this.name; * @param {String} description
*/
setDesc(description){
return this.desc = description;
} }
/**
setDesc(desc){ *
this.desc = desc; * @param {Number} cost
} */
getDesc(){
return this.desc;
}
setCost(cost){ setCost(cost){
this.cost = cost; return this.cost = cost;
} }
/**
getCost(){ *
return this.cost; * @param {String} image
} */
setImage(image){ setImage(image){
this.imageUrl = image; return this.image = image;
}
getImage(){
return this.imageUrl;
} }
} }

View File

@@ -1,14 +1,16 @@
const { Entity } = require('./entity');
const {Website} = require('./website'); const {Website} = require('./website');
class User{ class User{
/**
*
* @param {string} id
*/
constructor(id){ constructor(id){
this.id = id; this.id = id;
//uses key value pair to store website this.websites = new Entity();
//key is the companyName of the website
//value is the website itself
this.websites = {};
} }
/** /**
@@ -16,26 +18,15 @@ class User{
* @param {Website} website * @param {Website} website
*/ */
addWebsite(website){ addWebsite(website){
if(this.websites[website.companyName] != undefined) return this.websites.addData(website.companyName, website);
{
return false;
}else{
this.websites[website.companyName] = website;
return true;
}
} }
deleteWebsite(companyName){ deleteWebsite(companyName){
if(this.websites[companyName] != undefined) return this.websites.deleteData(companyName);
{
return delete this.websites[companyName];
}else{
return false
}
} }
getWebsite(companyName){ getWebsite(companyName){
return this.websites[companyName]; return this.websites.getData(companyName);
} }
} }

View File

@@ -1,3 +1,4 @@
const { Entity } = require('./entity');
const {Product} = require('./product'); const {Product} = require('./product');
class Website { class Website {
@@ -16,7 +17,7 @@ class Website {
//uses key value pair to store product //uses key value pair to store product
//key is the productId of the product //key is the productId of the product
//value is the product itself //value is the product itself
this.products = {}; this.products = new Entity();
} }
/** /**
@@ -24,13 +25,7 @@ class Website {
* @param {Product} product * @param {Product} product
*/ */
addProduct(product){ addProduct(product){
if(this.products[product.id] == undefined) return this.products.addData(product.id, product);
{
this.products[product.id] = product;
return true
}
return false;
} }
/** /**
@@ -39,7 +34,15 @@ class Website {
* @returns {Product} * @returns {Product}
*/ */
getProduct(productId){ getProduct(productId){
return this.products[productId]; return this.products.getData(productId);
}
/**
*
* @returns {[]}
*/
getAllProduct(){
return this.products.getAllData().values();
} }
/** /**
@@ -47,12 +50,8 @@ class Website {
* @param {string} productId * @param {string} productId
*/ */
deleteProduct(productId){ deleteProduct(productId){
if(this.products[productId] != undefined)
{
return delete this.products[productId];
}
return false; return this.products.deleteData(productId);
} }

View File

@@ -1,6 +1,11 @@
const { Command } = require("../models/commands"); const { Command } = require("../models/commands");
const logic = require("../businessLogic/logic"); const logic = require("../businessLogic/logic");
const { Website } = require("../models/website");
const { Product } = require('../models/product');
var selected_product = null;// Will keep track of the selected product
var selected_website = null; // Selected website.
/////////// ///////////
//add the commands here //add the commands here
@@ -11,7 +16,7 @@ const commands = [
command: 'wg', command: 'wg',
//function to be executed //function to be executed
callback : () => { callback : (input) => {
logic.onWG(); logic.onWG();
//mesage to be sent to the user //mesage to be sent to the user
@@ -23,12 +28,240 @@ const commands = [
return message; return message;
} }
}), }),
new Command({
//User command
command: `wg product new <id>`,
//function to be executed
callback : (input) => {
if(selected_website==null)
{
let message = [
`A website should be selected or created before creating a product `
];
return message;
}
selected_product= logic.addProduct(input['id'],selected_website);
//mesage to be sent to the user
let message = [
`The product has been created with the id : ` + selected_product.id ,
`This product has been selected . \nNow you can make change to the product with the following commands : \n1. wg product info \n2. wg product name <product-name> \n3. wg product cost <product-cost> \n4. wg product desc <product-desc> \n5. wg product image <product-image>`
];
return message;
}
}),
new Command({
//User command
command: `wg product delete <id>`,
//function to be executed
callback : (input) => {
if(selected_website==null)
{
let message = [
`A website should be selected or created before deleting a product `
];
return message;
}
if(logic.deleteProduct(input['id'],selected_website) == false)
{
let message = [
`No product with the given id`
];
return message;
}
let message = [
`The product has been deleted with the id : ` + id
];
return message;
}
}),
new Command({
//User command
command: `wg product select <id>`,
//function to be executed
callback : (input) => {
if(selected_website==null)
{
let message = [
`A website should be selected or created before selecting a product `
];
return message;
}
// Find the product with the given id
selected_product = selected_website.getProduct(input['id']);
if(selected_product == null)
{
logic.addProduct(input['id'],selected_website);
selected_product = selected_website.getProduct(input['id']);
let message = [
`There was no product with the give id. So a new product was created and selected with the id : ` + selected_product.id ,
`Now you can make change to the product with the following commands : \n1. wg product info \n2. wg product name <product-name> \n3. wg product cost <product-cost> \n4. wg product desc <product-desc> \n5. wg product image <product-image>`
];
return message;
}
let message = [
`The product has been selected with the id : ` + selected_product.id ,
'Now you can make change to the product with the following commands : \n1. wg product info \n2. wg product name <product-name> \n3. wg product cost <product-cost> \n4. wg product desc <product-desc> \n5. wg product image <product-image>'
];
return message;
}
}),
new Command({
//User command
command: `wg product all`,
//function to be executed
callback : () => {
if(selected_website==null)
{
let message = [
`A website should be selected or created `
];
return message;
}
let message = [
'Your website has following products: '
];
for(let p of selected_website.getAllProduct())
{
let m = 'Product id: ' + p.id + '\nProduct Name : ' + p.name + '\nProduct description : '+ p.desc + '\nProduct Cost: ' + p.cost + '\nProduct Image : '+ p.image;
message.push(m);
}
return message;
}
}),
new Command({
//User command
command: `wg product info`,
//function to be executed
callback : () => {
if(selected_product == null)
{
let message = [
`A product should be selected `
];
return message;
}
let message = [
'Product id: ' + selected_product.id,
'Product Name : ' + selected_product.name ,
'Product description : '+ selected_product.desc ,
'Product Cost: ' + selected_product.cost ,
'Product Image : '+ selected_product.image
];
return message;
}
}),
new Command({
//User command
command: `wg product name <product-name>`,
//function to be executed
callback : (input) => {
if(selected_product == null)
{
let message = [
`A product should be selected `
];
return message;
}
selected_product.setName(input['product-name']);
let message = [
'The product name has been set to '+ selected_product.name
];
return message;
}
}),
new Command({
//User command
command: `wg product cost <product-cost>`,
//function to be executed
callback : (input) => {
if(selected_product == null)
{
let message = [
`A product should be selected `
];
return message;
}
selected_product.setCost(input['product-cost']);
let message = [
'The product cost has been set to '+ selected_product.cost
];
return message;
}
}),
new Command({
//User command
command: 'wg product desc <product-desc>',
//function to be executed
callback : (input) => {
if(selected_product == null)
{
let message = [
`A product should be selected `
];
return message;
}
selected_product.setDesc(input['product-desc']);
let message = [
'The product description has been set to : '+ selected_product.desc
];
return message;
}
}),
new Command({
//User command
command: 'wg product image <product-image>',
//function to be executed
callback : (input) => {
if(selected_product == null)
{
let message = [
`A product should be selected `
];
return message;
}
selected_product.setImage(input['product-image']);
let message = [
'The product image has been set to : '+ selected_product.image
];
return message;
}
}),
]; ];
const onMessage = (message, client) => { module.exports= onMessage = (message, client) => {
let command = null; let command = null;
@@ -36,7 +269,7 @@ const onMessage = (message, client) => {
if(message.body.startsWith("wg")) if(message.body.startsWith("wg"))
{ {
for (let c of commands){ for (let c of commands){
if(c.command == message.body) if(c.equals(message.body))
{ {
command = c; command = c;
break; break;
@@ -44,7 +277,12 @@ const onMessage = (message, client) => {
} }
if(command != null){ if(command != null){
let messageToBeSent = command.callback(); let input = {};
if(command.requireInput){
input = command.getInput(message.body);
}
let messageToBeSent = command.callback(input);
for (let msg of messageToBeSent) for (let msg of messageToBeSent)
{ {
client.sendMessage(message.from, msg, new Object()); client.sendMessage(message.from, msg, new Object());
@@ -54,6 +292,6 @@ const onMessage = (message, client) => {
}; };
module.exports.onMessage = onMessage;
//export default onMessage; //export default onMessage;

View File

@@ -0,0 +1,169 @@
const { Command } = require('../src/models/commands');
const expect = require('chai').expect;
describe('Command', () => {
it('Test : requireInput() without input', () => {
let a = new Command({
command: "wg create",
callback: () => {
}
});
expect(a.requireInput).to.false;
});
it('Test : requireInput() with input', () => {
let a = new Command({
command: "wg create <id>",
callback: () => {
}
});
expect(a.requireInput).to.true;
});
it('Test : requireInput() with 2 inputs', () => {
let a = new Command({
command: "wg create <id> <name>",
callback: () => {
}
});
expect(a.requireInput).to.true;
});
it('Test : equals() without input', () => {
let message = 'wg website';
let a = new Command({
command: "wg create <id>",
callback: () => {
}
});
let b = new Command({
command: "wg website",
callback: () => {
}
});
let c = new Command({
command: "wg product p12",
callback: () => {
}
});
let d = new Command({
command: "wg",
callback: () => {
}
});
expect(a.equals(message)).to.false;
expect(b.equals(message)).to.true;
expect(c.equals(message)).to.false;
expect(d.equals(message)).to.false;
});
it('Test : equals() with input', () => {
let message = 'wg create p12';
let a = new Command({
command: "wg create <id>",
callback: () => {
}
});
expect(a.equals(message)).to.true;
});
it('Test : equals() with different message', () => {
let message = 'wg website web';
let a = new Command({
command: "wg create <id>",
callback: () => {
}
});
expect(a.equals(message)).to.false;
});
it('Test : equals() with spelling error', () => {
let message = 'wg websit';
let b = new Command({
command: "wg website",
callback: () => {
}
});
expect(b.equals(message)).to.false;
});
it('Test : equals() with extra inputs', () => {
let message = 'wg create p12 pr';
let a = new Command({
command: "wg create <id>",
callback: () => {
}
});
expect(a.equals(message)).to.false;
});
it('Test : getInput() with 1 input', () => {
let message = 'wg create p12'
let a = new Command({
command: "wg create <id>",
callback: () => {
}
});
expect(a.getInput(message)['id']).to.equal('p12');
});
it('Test : getInput() with 2 input', () => {
let message = 'wg create p12 pikachu'
let a = new Command({
command: "wg create <id> <name>",
callback: () => {
}
});
expect(a.getInput(message)['id']).to.equal('p12');
expect(a.getInput(message)['name']).to.equal('pikachu');
});
});

View File

@@ -0,0 +1,68 @@
const expect = require('chai').expect;
const {data} = require('../src/models/data')
const {Entity} = require('../src/models/entity');
const { Website } = require('../src/models/website');
describe('Entity', () => {
it('Test : addData', () => {
let a = new Entity();
a.addData('hello', new Website('hello'));
expect(a.isData('hello')).to.true;
expect(a.count).to.equal(0);
});
it('Test : clearData()', () => {
let a = new Entity();
a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol'));
a.clearData();
expect(a.count).to.equal(0);
expect(a.isData("kruta")).to.false;
expect(a.isData("hello")).to.false;
expect(a.isData('pagol')).to.false;
expect(a.isData('hello world')).to.false;
});
it('Test: getData', () => {
let a = new Entity();
a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol'));
expect(a.getData('hello world').companyName).to.equal('hello world');
expect(a.getData('gada').companyName).to.equal('gada');
expect(a.getData('chu chu')).to.null;
})
it('Test: deleteData', () => {
let a = new Entity();
a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol'));
a.deleteData('gada');
expect(a.getData('gada')).to.null;
})
it('Test: getAllData', () => {
let a = new Entity();
a.addData('hello world', new Website('hello world'));
a.addData('gada', new Website('gada'));
a.addData('pagol', new Website('pagol'));
let websitegen = a.getAllData().values();
for(let t of websitegen)
{
console.log(t.companyName);
}
})
})