Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import { assert } from 'chai';
- import { isProductAvailable, canAffordProduct, getRecommendedProducts } from './onlineStore';
- describe('Online Store test suit', () => {
- describe('isProductAvailable', () => {
- it('throws error if product is not a string or stockQuantity is not a number', () => {
- assert.throw(() => isProductAvailable(123, 'stock'), Error, 'Invalid input.');
- assert.throw(() => isProductAvailable('product', 'stock'), Error, 'Invalid input.');
- });
- it('returns out of stock message if stockQuantity is less than or equal to 0', () => {
- assert.equal(isProductAvailable('product', 0), 'Sorry, product is currently out of stock.');
- assert.equal(isProductAvailable('product', -1), 'Sorry, product is currently out of stock.');
- });
- it('returns available for purchase message if stockQuantity is greater than 0', () => {
- assert.equal(isProductAvailable('product', 1), 'Great! product is available for purchase.');
- assert.equal(isProductAvailable('product', 10), 'Great! product is available for purchase.');
- });
- });
- describe('canAffordProduct', () => {
- it('throws error if productPrice is not a number or accountBalance is not a number', () => {
- assert.throw(() => canAffordProduct('price', 100), Error, 'Invalid input.');
- assert.throw(() => canAffordProduct(100, 'balance'), Error, 'Invalid input.');
- });
- it('returns insufficient funds message if accountBalance is less than productPrice', () => {
- assert.equal(canAffordProduct(100, 50), "You don't have sufficient funds to buy this product.");
- assert.equal(canAffordProduct(1000, 500), "You don't have sufficient funds to buy this product.");
- });
- it('returns remaining balance message if accountBalance is greater than or equal to productPrice', () => {
- assert.equal(canAffordProduct(100, 150), 'Product purchased. Your remaining balance is $50.');
- assert.equal(canAffordProduct(1000, 1500), 'Product purchased. Your remaining balance is $500.');
- });
- });
- describe('getRecommendedProducts', () => {
- it('throws error if productList is not an array or category is not a string', () => {
- assert.throw(() => getRecommendedProducts('productList', 'category'), Error, 'Invalid input.');
- assert.throw(() => getRecommendedProducts(['product'], 123), Error, 'Invalid input.');
- });
- it('returns no recommended products message if there are no recommended products in the category', () => {
- const productList = [
- {name: 'product1', category: 'category1'},
- {name: 'product2', category: 'category2'},
- {name: 'product3', category: 'category3'}
- ];
- assert.equal(getRecommendedProducts(productList, 'category4'), 'Sorry, we currently have no recommended products in the category4 category.');
- });
- it('returns recommended products message if there are recommended products in the category', () => {
- const productList = [
- {name: 'product1', category: 'category1'},
- {name: 'product2', category: 'category2'},
- {name: 'product3', category: 'category1'}
- ];
- assert.equal(getRecommendedProducts(productList, 'category1'), 'Recommended products in the category1 category: product1, product3');
- assert.equal(getRecommendedProducts(productList, 'category2'), 'Recommended products in the category2 category: product2');
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement