diff --git a/whatsapp-web.js/src/businessLogic/logic.js b/whatsapp-web.js/src/businessLogic/logic.js index 4259ab9..e7015a0 100644 --- a/whatsapp-web.js/src/businessLogic/logic.js +++ b/whatsapp-web.js/src/businessLogic/logic.js @@ -1,25 +1,270 @@ const { Website } = require("../models/website"); const { data } = require("../models/data"); +const { Product } = require('../models/product'); +const { User } = require('../models/user'); +const request = require('request'); -module.exports.onWG = () => { - console.log('hello world'); +/** + * user to be sent the message to + * @type {User} + */ +let user = null; + +/** + * input to be used in the function if exists + * @type {string} + */ +let input = null; + +const addProduct = (id) => { + + // Create a product and select it. + //At this point all the product properties will be default + var product = new Product({id : id}); + // Add a product to the selected website. + user.getSelectedWebsite().addProduct(product); } +const check = ({checkFunction, callback}) => { -module.exports.onCreate = (id, companyName) => { - - //get the user - let user = data.getUser(id); - if(user == undefined) + let checkValue = checkFunction(); + //if check value is false + if(checkValue == '') { - data.addUser(id); - user = data.getUser(id); + return callback(); } - //add the website with the company name - user.addWebsite(new Website(companyName)); + return checkValue; +} + +const checkSelectedWebsiteExist= () => { + + if(user.getSelectedWebsite() == null) + { + return [ + `A website should be selected or created + To create website, please use the following command : `, + `*wg create *`, + + ]; + } + + return ''; +} + +const checkSelectedProductExist = () => { + + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { + if(user.getSelectedWebsite().getSelectedProduct() == null) + { + return [ + `A product should be created or selected` + ] + } + + return ''; + } + }); + +} + +module.exports.setUser = (id) =>{ + + if(!data.isUser(id)) + { + + data.addUser(new User(id)); + } + user = data.getUser(id) +}; + +module.exports.setInput= (value) => { + input = value; } +module.exports.onCreateProduct = () => { + + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { + //add the product + addProduct(input['id']); + + let selectedId = user.getSelectedWebsite().getSelectedProduct().id; + + //mesage to be sent to the user + let message = [ + `The product has been created with the id : ${selectedId}` , + ` + This product has been selected. + Now you can make change to the product with the following commands : + 1. wg product info + 2. wg product name + 3. wg product cost + 4. wg product desc + 5. wg product image + ` + ]; + + return message; + } + }); + +} + +module.exports.onDeleteProduct = () => { + + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { + + if(!user.getSelectedWebsite().deleteProduct(input['id'])) + { + return [ + `No product with the given id` + ]; + } + + return [ + `The product has been deleted with the id : ` + input['id'] + ]; + + } + }); +} + +module.exports.onSelectProduct = () => { + + + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { + + if(!user.getSelectedWebsite().selectProduct(input['id'])) + { + return [ + `There was no product with the given id. Use the following command to get the list of all id's`, + `wg product all` + ]; + } + + return [ + `The product has been selected with the id : ${user.getSelectedWebsite().getSelectedProduct().id}` , + ` + This product has been selected. + Now you can make change to the product with the following commands : + 1. wg product info + 2. wg product name + 3. wg product cost + 4. wg product desc + 5. wg product image + ` + ]; + + } + }); +} + +module.exports.onGetAllProducts = () => { + + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { + let message = [ + 'Your website has following products: ' + ]; + + for(let p of user.getSelectedWebsite().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; + } + }); + +} + +module.exports.onGetProductInfo = () => { + + return check({ + checkFunction : checkSelectedProductExist, + callback : () => { + let selected_product = user.getSelectedWebsite().getSelectedProduct(); + return [ + ` + 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} + ` + ]; + } + }); + +} + +module.exports.onSetProductName = () => { + + return check({ + checkFunction : checkSelectedProductExist, + callback : () => { + let selected_product = user.getSelectedWebsite().getSelectedProduct(); + selected_product.setName(input['product-name']); + return [ + 'The product name has been set to '+ selected_product.name + ]; + + } + }); +} + +module.exports.onSetProductCost = () => { + return check ({ + checkFunction : checkSelectedProductExist, + callback : () => { + let selected_product = user.getSelectedWebsite().getSelectedProduct(); + selected_product.setCost(input['product-cost']); + return[ + 'The product cost has been set to '+ selected_product.cost + ]; + + } + }); +} + +module.exports.onSetProductDesc = () => { + return check({ + checkFunction : checkSelectedProductExist, + callback : () => { + let selected_product = user.getSelectedWebsite().getSelectedProduct(); + selected_product.setDesc(input['product-desc']); + let message = [ + 'The product cost has been set to '+ selected_product.desc + ]; + return message; + } + }); +} + +module.exports.onSetProductImage = () => { + + return check({ + checkFunction : checkSelectedProductExist, + callback : () => { + let selected_product = user.getSelectedWebsite().getSelectedProduct(); + selected_product.setImage(input['product-image']); + let message = [ + 'The product cost has been set to '+ selected_product.image + ]; + return message; + } + }); +} /** * A help function @@ -56,9 +301,11 @@ module.exports.help = () => * @param {string} input of the company name * @return {void} gives information on how to add details to website */ -module.exports.comp = (input) => +module.exports.onCreateWebsite = () => { - let create_company = [ + user.addWebsite(new Website(input['company_name'])); + + return [ `welcome to building your own website!`, `We would like you add the following details:`, `wg website firstname **`, @@ -71,13 +318,30 @@ module.exports.comp = (input) => `For adding information use *wg website *`, ]; - Website.companyName = input; - if(Website.companyName == null) - { - create_company = [`you have not input your company name. Please try again.`]; - } - return create_company; +} + +module.exports.onGetInfo = () => { + + + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { + + let website = user.getSelectedWebsite(); + return [ + ` + First Name : ${website.firstName} + Last Name : ${website.lastName} + Company Name (id) : ${website.companyName } + Logo : ${website.logo} + Banner : ${website.bannerUrl} + Description : ${website.desc} + Email : ${website.email} + ` + ]; + } + }); } /** @@ -85,28 +349,20 @@ module.exports.comp = (input) => * @param {string} input of the firstname for website * @return {void} informs you that first name has been added */ -module.exports.firstName = (fdata) => +module.exports.onSetFirstName = () => { + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { + + user.getSelectedWebsite().firstName = input['firstName']; + + return [`First name has been set to ${user.getSelectedWebsite().firstName}`]; + } + }); - let info = [`your first name is:` + fdata - ]; - - - - if(Website.companyName == null) - { - info = [`you have not input your company name. Please try again.`] - } - else - { - Website.firstname = fdata; - console.log('this is data ' +Website.firstname); - - } - - return info; } /** @@ -114,59 +370,18 @@ module.exports.firstName = (fdata) => * @param {string} input of the last name for website * @return {void} informs you that last name has been added */ -module.exports.lastName = (ldata) => +module.exports.onSetLastName = () => { + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { - let info = - [`your last name is: ` + ldata - ]; - - if(Website.companyName == null) - { - info = [`company name has not been used`]; - } - else if(Website.firstname == null) - { - info = [`you have not insert first name.`]; - } - else - { - Website.lastname = ldata; - console.log('lname added'); - } - - return info; -} - -/** - * wg website companyname - * @param {string} input of the companyname for website. In case you want to change the company name, you can do so here. - * @return {void} informs you that company name has been updated - */ -module.exports.CompanyName_website = (cdata) => -{ + user.getSelectedWebsite().lastName = input['lastName']; - - let info = [`your company name is: ` + cdata - ]; - - if(Website.firstname == null) - { - info = [`you have not insert first name.`]; - } - else if(Website.lastname == null) - { - info = [`you have not insert last name.`]; - } - else(Website.companyName != cdata) - { - Website.companyName = cdata; - info = [`your company name has been changed to ` +cdata]; - console.log('this is data ' +Website.companyName); - } - - return info; + return [`Last name has been set to ${user.getSelectedWebsite().lastName}`]; + } + }); } /** @@ -175,28 +390,17 @@ module.exports.CompanyName_website = (cdata) => * @return {void} informs you that logo URL has been added */ -module.exports.logourl = (ldata) => +module.exports.onSetLogo = () => { + check({ + checkFunction : checkSelectedWebsiteExist, + callback: () => { + user.getSelectedWebsite().logoUrl = input['url']; + + return [`Logo has been set to ${user.getSelectedWebsite().logoUrl}`]; + } + }) - let info = [`your logo is: ` + ldata - ]; - if(Website.companyName == null) - { - info = [`you have not input your company name. Please try again.`] - } - else if(Website.firstname == null) - { - info = [`you have not insert first name.`]; - } - else if(Website.lastname == null) - { - info = [`you have not insert last name.`]; - } - else - { - Website.logoUrl = ldata - } - return info; } @@ -205,32 +409,16 @@ module.exports.logourl = (ldata) => * @param {string} input of the banner URL for website * @return {void} informs you that banner URL has been added */ -module.exports.bannerurl = (bannerdata) => +module.exports.onSetBanner = () => { + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { - let info = [`your banner is: ` + bannerdata - ]; - if(Website.companyName == null) - { - info = [`you have not input your company name. Please try again.`] - } - else if(Website.firstname == null) - { - info = [`you have not insert first name.`]; - } - else if(Website.lastname == null) - { - info = [`you have not insert last name.`]; - } - else if(Website.logoUrl == null) - { - info = [`you have not insert logo url`]; - } - else - { - Website.bannerUrl = bannerdata - } - return info; + user.getSelectedWebsite().bannerUrl = input['bannerURL']; + return [`Banner has been set to ${user.getSelectedWebsite().bannerUrl}`]; + } + }); } @@ -239,42 +427,18 @@ module.exports.bannerurl = (bannerdata) => * @param {string} input of the company description for website * @return {void} informs you that description has been added */ -module.exports.company_description = (descriptiondata) => +module.exports.onSetDesc = (descriptiondata) => { + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { - let info = [`your company description is: ` + descriptiondata - ]; - if(Website.companyName == null) - { - info = [`you have not input your company name. Please try again.`] - } - else if(Website.firstname == null) - { - info = [`you have not insert first name.`]; - } - else if(Website.lastname == null) - { - info = [`you have not insert last name.`]; - } - else if(Website.logoUrl == null) - { - info = [`you have not insert logo url`]; - } - else if(Website.bannerUrl == null) - { - info = [`you have not insert banner url`]; - } - else - { - Website.desc = descriptiondata - } - return info; + user.getSelectedWebsite().desc = input['desc']; + return [`Banner has been set to ${user.getSelectedWebsite().desc}`]; + } + }); } - - - - /** * wg website email * @param {string} input of the email for website @@ -283,38 +447,91 @@ module.exports.company_description = (descriptiondata) => */ -module.exports.email = (email_data) => +module.exports.onSetEmail = () => { - - let info = [`your email is: `+ email_data - ]; - if(Website.companyName == null) - { - info = [`you have not input your company name. Please try again.`] - } - else if(Website.firstname == null) - { - info = [`you have not insert first name.`]; - } - else if(Website.lastname == null) - { - info = [`you have not insert last name.`]; - } - else if(Website.logoUrl == null) - { - info = [`you have not insert logo url`]; - } - else if(Website.bannerUrl == null) - { - info = [`you have not insert banner url`]; - } - else if(Website.desc == null) - { - info = [`you have not insert the description`]; - } - else - { - Website.email = email_data - } - return info; -} \ No newline at end of file + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : () => { + + user.getSelectedWebsite().email = input['email']; + return [`Email has been set to ${user.getSelectedWebsite().email}`]; + } + }); +} + +module.exports.onWebsiteFinished = () => { + return check({ + checkFunction : checkSelectedWebsiteExist, + callback : async () => { + //get json from the website + let json = user.getSelectedWebsite().toJson(); + //creates a promise + //resolve and reject value is going to be returned + //resolve value = message to be sent + let res = new Promise( (resolve, reject) => { + request({ + url: process.argv[2]+"/generate", + method: "POST", + headers: { + "content-type": "application/json", // <--Very important!!! + }, + body: json + }, (error, response, body) => { + //send reject value in promise if error exist + if(error) + { + return reject(error); + } + // messsage to be sent + let returnStatement = [ + `${process.argv[2]}/pages/${JSON.parse(response.body).directory}`, + `*Website ID:* ${JSON.parse(response.body).directory}`, + `*Important to remember the ID*` + ]; + //send resolve value id + resolve(returnStatement); + }); + }); + + //waits for request to be completed + let msg = await res; + return msg; + } + }); +} + +module.exports.onDeployWebsite = () => { + return check({ + checkFunction: checkSelectedProductExist, + callback : async () => { + let res = new Promise( (resolve, reject) => { + request({ + url: process.argv[2]+"/ipfsdeploy?id="+user.getSelectedWebsite().companyName, + method: "GET", + headers: { + "content-type": "application/json", // <--Very important!!! + } + }, function (error, response, body){ + // reject error in promise + if(error) + { + return reject(error); + } + // messsage to be sent + let returnStatement = [ + `https://ipfs.io/ipfs/${JSON.parse(response.body).data}`, + `Takes around 10-30 minutues to deploy`, + `Read more about IPFS https://ipfs.io/` + ]; + //send resolve value id + resolve(returnStatement); + + }); + }); + + let msg = await res; + return msg; + + } + }); +} diff --git a/whatsapp-web.js/src/models/entity.js b/whatsapp-web.js/src/models/entity.js index 8297cb3..38abfcc 100644 --- a/whatsapp-web.js/src/models/entity.js +++ b/whatsapp-web.js/src/models/entity.js @@ -4,12 +4,14 @@ class Entity { constructor(){ this.data = new Map(); + this.selectedData = null; this.count = 0; } addData(key ,value){ if(!this.isData(key)){ - this.data[key] = value; + this.data.set(key, value); + this.selectedData = key; return true; } return false; @@ -20,28 +22,56 @@ class Entity { * @param {string} key */ isData(key){ - return this.data[key] != undefined ? true : false; + return this.data.has(key) ? true : false; } deleteData(key){ if(this.isData(key)){ - return delete this.data[key]; + this.data.delete(key); + if(this.selectedData == key){ + this.selectedData = null; + } + return true; } return false; } clearData(){ + this.selectedData = null; this.data = new Map(); this.count = 0; } + /** + * Select a specific data with its key + * @param {string} key + * @returns true if a data is selected + * @returns false if data is null + */ + selectData(key){ + if(this.isData(key)) + { + this.selectedData = key; + return true; + } + return false; + } + + /** + * + * @param {string} key + * @returns the value mapped to the key + */ getData(key){ if(this.isData(key)){ - return this.data[key]; + return this.data.get(key); } return null; } + /** + * @returns a map of all data + */ getAllData(){ return this.data; } diff --git a/whatsapp-web.js/src/models/product.js b/whatsapp-web.js/src/models/product.js index 0878b60..ebbefca 100644 --- a/whatsapp-web.js/src/models/product.js +++ b/whatsapp-web.js/src/models/product.js @@ -1,13 +1,50 @@ class Product { - constructor({ id = '', name = '', desc = '', cost = 0, image = null }) { + constructor({ id = '', name = '', desc = '', cost = 0, image = null } = {}) { this.id = id; this.name = name; this.desc = desc; this.cost = cost; this.image = image; } + + /** + * + * @param {Number} id + */ + setId(id){ + return this.id = id; + } + /** + * + * @param {String} name + */ + setName(name){ + return this.name = name; + } + /** + * + * @param {String} description + */ + setDesc(description){ + return this.desc = description; + } + /** + * + * @param {Number} cost + */ + setCost(cost){ + return this.cost = cost; + } + /** + * + * @param {String} image + */ + setImage(image){ + return this.image = image; + } + } module.exports.Product = Product; diff --git a/whatsapp-web.js/src/models/user.js b/whatsapp-web.js/src/models/user.js index 2c915c6..d001707 100644 --- a/whatsapp-web.js/src/models/user.js +++ b/whatsapp-web.js/src/models/user.js @@ -29,6 +29,18 @@ class User{ return this.websites.getData(companyName); } + selectWebsite(companyName) + { + return this.websites.selectData(companyName); + } + + /** + * @returns {Website} + */ + getSelectedWebsite(){ + return this.websites.selectedData; + } + } module.exports.User = User; \ No newline at end of file diff --git a/whatsapp-web.js/src/models/website.js b/whatsapp-web.js/src/models/website.js index 9584f76..5981556 100644 --- a/whatsapp-web.js/src/models/website.js +++ b/whatsapp-web.js/src/models/website.js @@ -37,6 +37,14 @@ class Website { return this.products.getData(productId); } + /** + * + * returns all the products in the website + */ + getAllProduct(){ + return this.products.getAllData().values(); + } + /** * * @param {string} productId @@ -46,6 +54,18 @@ class Website { return this.products.deleteData(productId); } + selectProduct(productId){ + return this.products.selectData(productId); + } + + /** + * @returns {Product} + */ + getSelectedProduct() + { + return this.products.selectedData; + } + } diff --git a/whatsapp-web.js/src/userInteraction/messages.js b/whatsapp-web.js/src/userInteraction/messages.js index a6cfb5b..56a995a 100644 --- a/whatsapp-web.js/src/userInteraction/messages.js +++ b/whatsapp-web.js/src/userInteraction/messages.js @@ -1,12 +1,12 @@ const { Command } = require("../models/commands"); const logic = require("../businessLogic/logic"); - -/////////// -//add the commands here -/////////// +const { Website } = require("../models/website"); +const { Product } = require('../models/product'); +//commands and the corresponding function to be executed +//are input in the array const commands = [ new Command({ //User command @@ -25,46 +25,43 @@ const commands = [ return message; } }), + new Command({ + //User command + command: `wg product new `, + //function to be executed + callback : logic.onCreateProduct + }), + new Command({ + //User command + command: `wg product delete `, - + //function to be executed + callback : logic.onDeleteProduct + }), + new Command({ + //User command + command: `wg product select `, + //function to be executed + callback : logic.onSelectProduct + }), + + //gives user information on how to create website new Command({ //User command - command: 'wg help', - //function to be executed - callback : (input) => { - - logic.onWG(); - //mesage to be sent to the user - get_help = logic.help(); - - - return get_help; - } + callback : logic.help }), //helps user to create a website. The first step. new Command({ //User command - - command: 'wg create ', //function to be executed - callback : (input) => - { - - logic.onWG(); - - data = input['company_name']; - cn = logic.comp(data); - return cn; - - } + callback : logic.onCreateWebsite }), - //Inputs user's first name for website new Command({ //User command @@ -72,19 +69,7 @@ const commands = [ command: 'wg website firstname ', //function to be executed - callback : (input) => - { - - logic.onWG(); - - //cdata = input['company']; - fdata = input['firstName']; - - - info = logic.firstName(fdata); - return info; - - } + callback : logic.onSetFirstName }), @@ -92,45 +77,10 @@ const commands = [ new Command({ //User command - command: 'wg website lastname ', + command: 'wg website lastname ', //function to be executed - callback : (input) => - { - - logic.onWG(); - - //cdata = input['company']; - ldata = input['lastname']; - - - info = logic.lastName(ldata); - return info; - - } - }), - - - //inputs user companyname;in case they want to update the name - new Command({ - //User command - - command: 'wg website companyname ', - - //function to be executed - callback : (input) => - { - - logic.onWG(); - - //cdata = input['company']; - cdata = input['cname']; - - - info = logic.CompanyName_website(cdata); - return info; - - } + callback : logic.onSetLastName }), //inputs the logo of the company to website using url of logo @@ -140,19 +90,7 @@ const commands = [ command: 'wg website logo ', //function to be executed - callback : (input) => - { - - logic.onWG(); - - //cdata = input['company']; - logoU = input['url']; - - - info = logic.logourl(logoU); - return info; - - } + callback : logic.onSetLogo }), @@ -163,89 +101,131 @@ const commands = [ command: 'wg website banner ', //function to be executed - callback : (input) => - { - - logic.onWG(); - - bannerU = input['bannerURL']; - - - info = logic.bannerurl(bannerU); - return info; - - } + callback : logic.onSetBanner }), //inputs the description of the company to be seen in the website new Command({ //User command - command: 'wg website description ', + command: 'wg website desc ', //function to be executed - callback : (input) => - { - - logic.onWG(); - - websiteDescription = input['descript']; - - - info = logic.company_description(websiteDescription); - return info; - - } + callback : logic.onSetDesc }), //inputs the email of the company for contacting. new Command({ //User command - command: 'wg website email ', + command: 'wg website email ', //function to be executed - callback : (input) => - { - - logic.onWG(); - - mail = input['Email']; - - - info = logic.email(mail); - return info; - - } + callback : logic.onSetEmail }), + new Command({ + //User command + + command: 'wg website info', + + //function to be executed + callback : logic.onGetInfo + }), + new Command({ + //User command + + command: 'wg website finished', + + //function to be executed + callback : logic.onWebsiteFinished + }), + //gives user information on how to create website + + new Command({ + //User command + command: `wg product all`, + + //function to be executed + callback : logic.onGetAllProducts + }), + new Command({ + //User command + command: `wg product info`, + + //function to be executed + callback : logic.onGetProductInfo + }), + new Command({ + //User command + command: `wg product name `, + + //function to be executed + callback : logic.onSetProductName + }), + new Command({ + //User command + command: `wg product cost `, + + //function to be executed + callback : logic.onSetProductCost + }), + new Command({ + //User command + command: 'wg product desc ', + + //function to be executed + callback : logic.onSetProductDesc + }), + new Command({ + //User command + command: 'wg product image ', + + //function to be executed + callback : logic.onSetProductImage + }), ]; -module.exports= onMessage = (message, client) => { +module.exports= onMessage = async (message, client) => { let command = null; //if the message start with wg then proceed if(message.body.startsWith("wg")) { + //loop through all the commands for (let c of commands){ + //check if the message sent is equal to the commands + //if the message matches a command, + //then save the command in the command variable if(c.equals(message.body)) { command = c; break; } } - + + //if the command is not null, implies, the message sent is a valid command if(command != null){ let input = {}; - if(command.requireInput) - { + //check if the command requires input + if(command.requireInput){ input = command.getInput(message.body); } + //determine the user + logic.setUser(message.id.remote); + //determine the input + logic.setInput(input); - let messageToBeSent = command.callback(input); + //call callback function in the command + //await is used, so that if a command is an async function + //the program will wait until it is finished + //the callback returns a message to be sent to the user + let messageToBeSent = await command.callback(); + + // send the message to the user for (let msg of messageToBeSent) { client.sendMessage(message.from, msg, new Object()); @@ -253,7 +233,7 @@ module.exports= onMessage = (message, client) => { } } -}; +}; diff --git a/whatsapp-web.js/test/test_command.js b/whatsapp-web.js/test/test_command.js index 1fca64a..fff3df5 100644 --- a/whatsapp-web.js/test/test_command.js +++ b/whatsapp-web.js/test/test_command.js @@ -91,6 +91,21 @@ describe('Command', () => { }); + it('Test : equals() with different message', () => { + + let message = 'wg website web'; + + let a = new Command({ + command: "wg create ", + callback: () => { + + } + }); + + expect(a.equals(message)).to.false; + + }); + it('Test : equals() with spelling error', () => { let message = 'wg websit'; diff --git a/whatsapp-web.js/test/test_entity.js b/whatsapp-web.js/test/test_entity.js index f42eb2e..46ea027 100644 --- a/whatsapp-web.js/test/test_entity.js +++ b/whatsapp-web.js/test/test_entity.js @@ -29,13 +29,13 @@ describe('Entity', () => { 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; @@ -51,5 +51,67 @@ describe('Entity', () => { 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); + } + }) + + it('Test: selectData()', () => { + 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.selectData('gada'); + + expect(a.selectedData).to.equals('gada'); + }); + + it.only('Test: selectedData() = false', () => { + 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.selectData('tara'); + expect(a.selectedData).to.equals('pagol'); + }); + + it('Test: selectedData when addData() is used', () => { + 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.selectedData).to.equals('pagol'); + }); + + it('Test : selectedData when 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; + expect(a.selectedData).to.null; + }); + + + + }) \ No newline at end of file