Did the required change
This commit is contained in:
@@ -45,7 +45,7 @@ class Command{
|
||||
//else return false
|
||||
if(splitMsg[i] == splitCommand[i]){
|
||||
continue;
|
||||
}else if(splitCommand[i].match(/[<>]/g).length > 1){
|
||||
}else if(splitCommand[i].match(/[<>]/g) != null){
|
||||
continue;
|
||||
}else{
|
||||
return false;
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
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;
|
||||
|
||||
@@ -5,7 +5,7 @@ const { Website } = require("../models/website");
|
||||
const { Product } = require('../models/product');
|
||||
|
||||
var selected_product = null;// Will keep track of the selected product
|
||||
var selected_website = new Website; // Selected website.
|
||||
var selected_website = null; // Selected website.
|
||||
|
||||
///////////
|
||||
//add the commands here
|
||||
@@ -43,7 +43,7 @@ const commands = [
|
||||
];
|
||||
return message;
|
||||
}
|
||||
selected_product= logic.addProduct(input,selected_website);
|
||||
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 ,
|
||||
@@ -55,7 +55,7 @@ const commands = [
|
||||
}),
|
||||
new Command({
|
||||
//User command
|
||||
command: `wg delete product <id>`,
|
||||
command: `wg product delete <id>`,
|
||||
|
||||
//function to be executed
|
||||
callback : (input) => {
|
||||
@@ -69,7 +69,7 @@ const commands = [
|
||||
return message;
|
||||
}
|
||||
|
||||
if(logic.deleteProduct(input,selected_website) == false)
|
||||
if(logic.deleteProduct(input['id'],selected_website) == false)
|
||||
{
|
||||
let message = [
|
||||
`No product with the given id`
|
||||
@@ -99,7 +99,7 @@ const commands = [
|
||||
return message;
|
||||
}
|
||||
// Find the product with the given id
|
||||
selected_product = selected_website.products.getData(input);
|
||||
selected_product = selected_website.products.getData(input['id']);
|
||||
if(selected_product == null)
|
||||
{
|
||||
logic.addProduct(id,selected_website);
|
||||
@@ -188,7 +188,7 @@ const commands = [
|
||||
];
|
||||
return message;
|
||||
}
|
||||
selected_product.name= input;
|
||||
selected_product.name= input['product-name'];
|
||||
let message = [
|
||||
'The product name has been set to '+ given_name
|
||||
];
|
||||
@@ -211,7 +211,7 @@ const commands = [
|
||||
];
|
||||
return message;
|
||||
}
|
||||
selected_product.cost= input;
|
||||
selected_product.cost= input['product-cost'];
|
||||
let message = [
|
||||
'The product cost has been set to '+ given_cost
|
||||
];
|
||||
@@ -234,7 +234,7 @@ const commands = [
|
||||
];
|
||||
return message;
|
||||
}
|
||||
selected_product.desc = input;
|
||||
selected_product.desc = input['product-desc'];
|
||||
let message = [
|
||||
'The product description has been set to : '+ given_desc
|
||||
];
|
||||
@@ -257,7 +257,7 @@ const commands = [
|
||||
];
|
||||
return message;
|
||||
}
|
||||
selected_product.image = input;
|
||||
selected_product.image = input['product-image'];
|
||||
let message = [
|
||||
'The product image has been set to : '+ given_image
|
||||
];
|
||||
|
||||
@@ -91,6 +91,21 @@ describe('Command', () => {
|
||||
|
||||
});
|
||||
|
||||
it('Test : equals() with different message', () => {
|
||||
|
||||
let message = 'wg website p12';
|
||||
|
||||
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';
|
||||
|
||||
Reference in New Issue
Block a user