Advertisement
Marin171

JS

Jun 13th, 2023
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.98 KB | None | 0 0
  1. const {assert} = require('chai');
  2. const flowerShop = require('./flowerShop');
  3.  
  4. describe('flowerShop test suit', () => {
  5. describe('calcPriceOfFlowers', () => {
  6. it('returns the multiplies price and quantity rounded to second digit', () => {
  7. const flower = 'Tulip';
  8. const price = 2;
  9. const quantity = 5;
  10. const sum = (price * quantity).toFixed(2);
  11. assert.equal(flowerShop.calcPriceOfFlowers(flower, price, quantity), `You need $${sum} to buy ${flower}!`)
  12. });
  13.  
  14. it('In case of submitted invalid parameters, throw an error \"Invalid input!\"', () => {
  15. assert.throws(() => flowerShop.calcPriceOfFlowers(), Error, 'Invalid input!');
  16. assert.throws(() => flowerShop.calcPriceOfFlowers(1, 1, 1), Error, 'Invalid input!');
  17. assert.throws(() => flowerShop.calcPriceOfFlowers('flower', '1', 1), Error, 'Invalid input!');
  18. assert.throws(() => flowerShop.calcPriceOfFlowers('flower', 1, '1'), Error, 'Invalid input!');
  19. assert.throws(() => flowerShop.calcPriceOfFlowers('flower', 1.1, 1), Error, 'Invalid input!');
  20. assert.throws(() => flowerShop.calcPriceOfFlowers('flower', 1, 1.1), Error, 'Invalid input!');
  21. });
  22. });
  23. describe('checkFlowersAvailable', () => {
  24. it('If present in the array, the function return available message', () => {
  25. const flowers = ["Rose", "Lily", "Orchid"];
  26. assert.equal(flowerShop.checkFlowersAvailable('Rose', flowers), 'The Rose are available!');
  27. assert.equal(flowerShop.checkFlowersAvailable('Lily', flowers), 'The Lily are available!');
  28. });
  29.  
  30. it('If not present in the array, the function return unavailable message', () => {
  31. const flowers = ["Rose", "Lily", "Orchid"];
  32. assert.equal(flowerShop.checkFlowersAvailable('Tulip', flowers), 'The Tulip are sold! You need to purchase more!');
  33. assert.equal(flowerShop.checkFlowersAvailable('Cactus', flowers), 'The Cactus are sold! You need to purchase more!');
  34. });
  35. });
  36. describe('sellFlowers', () => {
  37. it('return the changed array of flowers as a string, joined by " / "', () => {
  38. const flowers = ["Rose", "Lily", "Orchid"];
  39. assert.equal(flowerShop.sellFlowers(flowers, 1), 'Rose / Orchid');
  40. assert.equal(flowerShop.sellFlowers(flowers, 0), 'Lily / Orchid');
  41. assert.equal(flowerShop.sellFlowers(flowers, 2), 'Rose / Lily');
  42. });
  43.  
  44. it('In case of submitted invalid parameters, throw an error \"Invalid input!\"', () => {
  45. assert.throws(()=>flowerShop.sellFlowers(), Error, 'Invalid input!');
  46. assert.throws(()=>flowerShop.sellFlowers('', 0), Error, 'Invalid input!');
  47. assert.throws(()=>flowerShop.sellFlowers([1,2,3], -1), Error, 'Invalid input!');
  48. assert.throws(()=>flowerShop.sellFlowers([1,2,3], 3), Error, 'Invalid input!');
  49. });
  50. });
  51. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement