completed all the commands and functions
This commit is contained in:
@@ -1,25 +1,270 @@
|
|||||||
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');
|
||||||
|
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) => {
|
let checkValue = checkFunction();
|
||||||
|
//if check value is false
|
||||||
//get the user
|
if(checkValue == '')
|
||||||
let user = data.getUser(id);
|
|
||||||
if(user == undefined)
|
|
||||||
{
|
{
|
||||||
data.addUser(id);
|
return callback();
|
||||||
user = data.getUser(id);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//add the website with the company name
|
return checkValue;
|
||||||
user.addWebsite(new Website(companyName));
|
}
|
||||||
|
|
||||||
|
const checkSelectedWebsiteExist= () => {
|
||||||
|
|
||||||
|
if(user.getSelectedWebsite() == null)
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
`A website should be selected or created
|
||||||
|
To create website, please use the following command : `,
|
||||||
|
`*wg create <company-name>*`,
|
||||||
|
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
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 <product-name>
|
||||||
|
3. wg product cost <product-cost>
|
||||||
|
4. wg product desc <product-desc>
|
||||||
|
5. wg product image <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 <product-name>
|
||||||
|
3. wg product cost <product-cost>
|
||||||
|
4. wg product desc <product-desc>
|
||||||
|
5. wg product image <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
|
* A help function
|
||||||
@@ -56,9 +301,11 @@ module.exports.help = () =>
|
|||||||
* @param {string} input of the company name
|
* @param {string} input of the company name
|
||||||
* @return {void} gives information on how to add details to website
|
* @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!`,
|
`welcome to building your own website!`,
|
||||||
`We would like you add the following details:`,
|
`We would like you add the following details:`,
|
||||||
`wg website firstname *<First_Name>*`,
|
`wg website firstname *<First_Name>*`,
|
||||||
@@ -71,13 +318,30 @@ module.exports.comp = (input) =>
|
|||||||
`For adding information use *wg website <firstname>*`,
|
`For adding information use *wg website <firstname>*`,
|
||||||
|
|
||||||
];
|
];
|
||||||
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
|
* @param {string} input of the firstname for website
|
||||||
* @return {void} informs you that first name has been added
|
* @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
|
* @param {string} input of the last name for website
|
||||||
* @return {void} informs you that last name has been added
|
* @return {void} informs you that last name has been added
|
||||||
*/
|
*/
|
||||||
module.exports.lastName = (ldata) =>
|
module.exports.onSetLastName = () =>
|
||||||
{
|
{
|
||||||
|
|
||||||
|
return check({
|
||||||
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
|
callback : () => {
|
||||||
|
|
||||||
let info =
|
user.getSelectedWebsite().lastName = input['lastName'];
|
||||||
[`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) =>
|
|
||||||
{
|
|
||||||
|
|
||||||
|
return [`Last name has been set to ${user.getSelectedWebsite().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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -175,28 +390,17 @@ module.exports.CompanyName_website = (cdata) =>
|
|||||||
* @return {void} informs you that logo URL has been added
|
* @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
|
* @param {string} input of the banner URL for website
|
||||||
* @return {void} informs you that banner URL has been added
|
* @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
|
user.getSelectedWebsite().bannerUrl = input['bannerURL'];
|
||||||
];
|
return [`Banner has been set to ${user.getSelectedWebsite().bannerUrl}`];
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -239,42 +427,18 @@ module.exports.bannerurl = (bannerdata) =>
|
|||||||
* @param {string} input of the company description for website
|
* @param {string} input of the company description for website
|
||||||
* @return {void} informs you that description has been added
|
* @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
|
user.getSelectedWebsite().desc = input['desc'];
|
||||||
];
|
return [`Banner has been set to ${user.getSelectedWebsite().desc}`];
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wg website email
|
* wg website email
|
||||||
* @param {string} input of the email for website
|
* @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 = () =>
|
||||||
{
|
{
|
||||||
|
return check({
|
||||||
let info = [`your email is: `+ email_data
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
];
|
callback : () => {
|
||||||
if(Website.companyName == null)
|
|
||||||
{
|
user.getSelectedWebsite().email = input['email'];
|
||||||
info = [`you have not input your company name. Please try again.`]
|
return [`Email has been set to ${user.getSelectedWebsite().email}`];
|
||||||
}
|
}
|
||||||
else if(Website.firstname == null)
|
});
|
||||||
{
|
}
|
||||||
info = [`you have not insert first name.`];
|
|
||||||
}
|
module.exports.onWebsiteFinished = () => {
|
||||||
else if(Website.lastname == null)
|
return check({
|
||||||
{
|
checkFunction : checkSelectedWebsiteExist,
|
||||||
info = [`you have not insert last name.`];
|
callback : async () => {
|
||||||
}
|
//get json from the website
|
||||||
else if(Website.logoUrl == null)
|
let json = user.getSelectedWebsite().toJson();
|
||||||
{
|
//creates a promise
|
||||||
info = [`you have not insert logo url`];
|
//resolve and reject value is going to be returned
|
||||||
}
|
//resolve value = message to be sent
|
||||||
else if(Website.bannerUrl == null)
|
let res = new Promise( (resolve, reject) => {
|
||||||
{
|
request({
|
||||||
info = [`you have not insert banner url`];
|
url: process.argv[2]+"/generate",
|
||||||
}
|
method: "POST",
|
||||||
else if(Website.desc == null)
|
headers: {
|
||||||
{
|
"content-type": "application/json", // <--Very important!!!
|
||||||
info = [`you have not insert the description`];
|
},
|
||||||
}
|
body: json
|
||||||
else
|
}, (error, response, body) => {
|
||||||
{
|
//send reject value in promise if error exist
|
||||||
Website.email = email_data
|
if(error)
|
||||||
}
|
{
|
||||||
return info;
|
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;
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|||||||
@@ -4,12 +4,14 @@ class Entity {
|
|||||||
|
|
||||||
constructor(){
|
constructor(){
|
||||||
this.data = new Map();
|
this.data = new Map();
|
||||||
|
this.selectedData = null;
|
||||||
this.count = 0;
|
this.count = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
addData(key ,value){
|
addData(key ,value){
|
||||||
if(!this.isData(key)){
|
if(!this.isData(key)){
|
||||||
this.data[key] = value;
|
this.data.set(key, value);
|
||||||
|
this.selectedData = key;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
@@ -20,28 +22,56 @@ class Entity {
|
|||||||
* @param {string} key
|
* @param {string} key
|
||||||
*/
|
*/
|
||||||
isData(key){
|
isData(key){
|
||||||
return this.data[key] != undefined ? true : false;
|
return this.data.has(key) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteData(key){
|
deleteData(key){
|
||||||
if(this.isData(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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
clearData(){
|
clearData(){
|
||||||
|
this.selectedData = null;
|
||||||
this.data = new Map();
|
this.data = new Map();
|
||||||
this.count = 0;
|
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){
|
getData(key){
|
||||||
if(this.isData(key)){
|
if(this.isData(key)){
|
||||||
return this.data[key];
|
return this.data.get(key);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns a map of all data
|
||||||
|
*/
|
||||||
getAllData(){
|
getAllData(){
|
||||||
return this.data;
|
return this.data;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,50 @@
|
|||||||
|
|
||||||
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;
|
||||||
this.cost = cost;
|
this.cost = cost;
|
||||||
this.image = image;
|
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;
|
module.exports.Product = Product;
|
||||||
|
|||||||
@@ -29,6 +29,18 @@ class User{
|
|||||||
return this.websites.getData(companyName);
|
return this.websites.getData(companyName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectWebsite(companyName)
|
||||||
|
{
|
||||||
|
return this.websites.selectData(companyName);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Website}
|
||||||
|
*/
|
||||||
|
getSelectedWebsite(){
|
||||||
|
return this.websites.selectedData;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.User = User;
|
module.exports.User = User;
|
||||||
@@ -37,6 +37,14 @@ class Website {
|
|||||||
return this.products.getData(productId);
|
return this.products.getData(productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* returns all the products in the website
|
||||||
|
*/
|
||||||
|
getAllProduct(){
|
||||||
|
return this.products.getAllData().values();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {string} productId
|
* @param {string} productId
|
||||||
@@ -46,6 +54,18 @@ class Website {
|
|||||||
return this.products.deleteData(productId);
|
return this.products.deleteData(productId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
selectProduct(productId){
|
||||||
|
return this.products.selectData(productId);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {Product}
|
||||||
|
*/
|
||||||
|
getSelectedProduct()
|
||||||
|
{
|
||||||
|
return this.products.selectedData;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
|
|
||||||
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');
|
||||||
//add the commands here
|
|
||||||
///////////
|
|
||||||
|
|
||||||
|
|
||||||
|
//commands and the corresponding function to be executed
|
||||||
|
//are input in the array
|
||||||
const commands = [
|
const commands = [
|
||||||
new Command({
|
new Command({
|
||||||
//User command
|
//User command
|
||||||
@@ -25,46 +25,43 @@ const commands = [
|
|||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product new <id>`,
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onCreateProduct
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product delete <id>`,
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onDeleteProduct
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product select <id>`,
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSelectProduct
|
||||||
|
}),
|
||||||
|
|
||||||
|
|
||||||
//gives user information on how to create website
|
//gives user information on how to create website
|
||||||
new Command({
|
new Command({
|
||||||
//User command
|
//User command
|
||||||
|
|
||||||
command: 'wg help',
|
command: 'wg help',
|
||||||
|
|
||||||
//function to be executed
|
//function to be executed
|
||||||
callback : (input) => {
|
callback : logic.help
|
||||||
|
|
||||||
logic.onWG();
|
|
||||||
//mesage to be sent to the user
|
|
||||||
get_help = logic.help();
|
|
||||||
|
|
||||||
|
|
||||||
return get_help;
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
//helps user to create a website. The first step.
|
//helps user to create a website. The first step.
|
||||||
new Command({
|
new Command({
|
||||||
//User command
|
//User command
|
||||||
|
|
||||||
|
|
||||||
command: 'wg create <company_name>',
|
command: 'wg create <company_name>',
|
||||||
|
|
||||||
//function to be executed
|
//function to be executed
|
||||||
callback : (input) =>
|
callback : logic.onCreateWebsite
|
||||||
{
|
|
||||||
|
|
||||||
logic.onWG();
|
|
||||||
|
|
||||||
data = input['company_name'];
|
|
||||||
cn = logic.comp(data);
|
|
||||||
return cn;
|
|
||||||
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
//Inputs user's first name for website
|
//Inputs user's first name for website
|
||||||
new Command({
|
new Command({
|
||||||
//User command
|
//User command
|
||||||
@@ -72,19 +69,7 @@ const commands = [
|
|||||||
command: 'wg website firstname <firstName>',
|
command: 'wg website firstname <firstName>',
|
||||||
|
|
||||||
//function to be executed
|
//function to be executed
|
||||||
callback : (input) =>
|
callback : logic.onSetFirstName
|
||||||
{
|
|
||||||
|
|
||||||
logic.onWG();
|
|
||||||
|
|
||||||
//cdata = input['company'];
|
|
||||||
fdata = input['firstName'];
|
|
||||||
|
|
||||||
|
|
||||||
info = logic.firstName(fdata);
|
|
||||||
return info;
|
|
||||||
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
@@ -92,45 +77,10 @@ const commands = [
|
|||||||
new Command({
|
new Command({
|
||||||
//User command
|
//User command
|
||||||
|
|
||||||
command: 'wg website lastname <lastname>',
|
command: 'wg website lastname <lastName>',
|
||||||
|
|
||||||
//function to be executed
|
//function to be executed
|
||||||
callback : (input) =>
|
callback : logic.onSetLastName
|
||||||
{
|
|
||||||
|
|
||||||
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 <cname>',
|
|
||||||
|
|
||||||
//function to be executed
|
|
||||||
callback : (input) =>
|
|
||||||
{
|
|
||||||
|
|
||||||
logic.onWG();
|
|
||||||
|
|
||||||
//cdata = input['company'];
|
|
||||||
cdata = input['cname'];
|
|
||||||
|
|
||||||
|
|
||||||
info = logic.CompanyName_website(cdata);
|
|
||||||
return info;
|
|
||||||
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
//inputs the logo of the company to website using url of logo
|
//inputs the logo of the company to website using url of logo
|
||||||
@@ -140,19 +90,7 @@ const commands = [
|
|||||||
command: 'wg website logo <url>',
|
command: 'wg website logo <url>',
|
||||||
|
|
||||||
//function to be executed
|
//function to be executed
|
||||||
callback : (input) =>
|
callback : logic.onSetLogo
|
||||||
{
|
|
||||||
|
|
||||||
logic.onWG();
|
|
||||||
|
|
||||||
//cdata = input['company'];
|
|
||||||
logoU = input['url'];
|
|
||||||
|
|
||||||
|
|
||||||
info = logic.logourl(logoU);
|
|
||||||
return info;
|
|
||||||
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|
||||||
@@ -163,89 +101,131 @@ const commands = [
|
|||||||
command: 'wg website banner <bannerURL>',
|
command: 'wg website banner <bannerURL>',
|
||||||
|
|
||||||
//function to be executed
|
//function to be executed
|
||||||
callback : (input) =>
|
callback : logic.onSetBanner
|
||||||
{
|
|
||||||
|
|
||||||
logic.onWG();
|
|
||||||
|
|
||||||
bannerU = input['bannerURL'];
|
|
||||||
|
|
||||||
|
|
||||||
info = logic.bannerurl(bannerU);
|
|
||||||
return info;
|
|
||||||
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
//inputs the description of the company to be seen in the website
|
//inputs the description of the company to be seen in the website
|
||||||
new Command({
|
new Command({
|
||||||
//User command
|
//User command
|
||||||
|
|
||||||
command: 'wg website description <descript>',
|
command: 'wg website desc <desc>',
|
||||||
|
|
||||||
//function to be executed
|
//function to be executed
|
||||||
callback : (input) =>
|
callback : logic.onSetDesc
|
||||||
{
|
|
||||||
|
|
||||||
logic.onWG();
|
|
||||||
|
|
||||||
websiteDescription = input['descript'];
|
|
||||||
|
|
||||||
|
|
||||||
info = logic.company_description(websiteDescription);
|
|
||||||
return info;
|
|
||||||
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
//inputs the email of the company for contacting.
|
//inputs the email of the company for contacting.
|
||||||
new Command({
|
new Command({
|
||||||
//User command
|
//User command
|
||||||
|
|
||||||
command: 'wg website email <Email>',
|
command: 'wg website email <email>',
|
||||||
|
|
||||||
//function to be executed
|
//function to be executed
|
||||||
callback : (input) =>
|
callback : logic.onSetEmail
|
||||||
{
|
|
||||||
|
|
||||||
logic.onWG();
|
|
||||||
|
|
||||||
mail = input['Email'];
|
|
||||||
|
|
||||||
|
|
||||||
info = logic.email(mail);
|
|
||||||
return info;
|
|
||||||
|
|
||||||
}
|
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
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 <product-name>`,
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetProductName
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: `wg product cost <product-cost>`,
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetProductCost
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: 'wg product desc <product-desc>',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetProductDesc
|
||||||
|
}),
|
||||||
|
new Command({
|
||||||
|
//User command
|
||||||
|
command: 'wg product image <product-image>',
|
||||||
|
|
||||||
|
//function to be executed
|
||||||
|
callback : logic.onSetProductImage
|
||||||
|
}),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
module.exports= onMessage = (message, client) => {
|
module.exports= onMessage = async (message, client) => {
|
||||||
|
|
||||||
let command = null;
|
let command = null;
|
||||||
|
|
||||||
//if the message start with wg then proceed
|
//if the message start with wg then proceed
|
||||||
if(message.body.startsWith("wg"))
|
if(message.body.startsWith("wg"))
|
||||||
{
|
{
|
||||||
|
//loop through all the commands
|
||||||
for (let c of 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))
|
if(c.equals(message.body))
|
||||||
{
|
{
|
||||||
command = c;
|
command = c;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//if the command is not null, implies, the message sent is a valid command
|
||||||
if(command != null){
|
if(command != null){
|
||||||
let input = {};
|
let input = {};
|
||||||
if(command.requireInput)
|
//check if the command requires input
|
||||||
{
|
if(command.requireInput){
|
||||||
input = command.getInput(message.body);
|
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)
|
for (let msg of messageToBeSent)
|
||||||
{
|
{
|
||||||
client.sendMessage(message.from, msg, new Object());
|
client.sendMessage(message.from, msg, new Object());
|
||||||
@@ -253,7 +233,7 @@ module.exports= onMessage = (message, client) => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -91,6 +91,21 @@ describe('Command', () => {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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', () => {
|
it('Test : equals() with spelling error', () => {
|
||||||
|
|
||||||
let message = 'wg websit';
|
let message = 'wg websit';
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ describe('Entity', () => {
|
|||||||
expect(a.isData('pagol')).to.false;
|
expect(a.isData('pagol')).to.false;
|
||||||
expect(a.isData('hello world')).to.false;
|
expect(a.isData('hello world')).to.false;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Test: getData', () => {
|
it('Test: getData', () => {
|
||||||
let a = new Entity();
|
let a = new Entity();
|
||||||
a.addData('hello world', new Website('hello world'));
|
a.addData('hello world', new Website('hello world'));
|
||||||
a.addData('gada', new Website('gada'));
|
a.addData('gada', new Website('gada'));
|
||||||
a.addData('pagol', new Website('pagol'));
|
a.addData('pagol', new Website('pagol'));
|
||||||
|
|
||||||
expect(a.getData('hello world').companyName).to.equal('hello world');
|
expect(a.getData('hello world').companyName).to.equal('hello world');
|
||||||
expect(a.getData('gada').companyName).to.equal('gada');
|
expect(a.getData('gada').companyName).to.equal('gada');
|
||||||
expect(a.getData('chu chu')).to.null;
|
expect(a.getData('chu chu')).to.null;
|
||||||
@@ -51,5 +51,67 @@ describe('Entity', () => {
|
|||||||
a.deleteData('gada');
|
a.deleteData('gada');
|
||||||
expect(a.getData('gada')).to.null;
|
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;
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
})
|
})
|
||||||
Reference in New Issue
Block a user