georgiev955

03. Recipe Selection

Sep 25th, 2023
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const recipeSelection = require('./recipeSelection');
  2. const assert = require('chai').assert;
  3. const expect = require('chai').expect;
  4.  
  5. describe("Tests recipeSelection functionallity", function () {
  6.  
  7.     describe("Test isTypeSuitable functionallity", function () {
  8.         it("Validate input", function () {
  9.             expect(() => { recipeSelection.isTypeSuitable("Vegetarian", 2) }).to.throw('Invalid input');
  10.         });
  11.         it("If the dietaryRestriction is 'Vegetarian' and the type is 'Meat'", function () {
  12.             assert.equal(recipeSelection.isTypeSuitable("Meat", "Vegetarian"), "This recipe is not suitable for vegetarians");
  13.         });
  14.         it("If the dietaryRestriction is 'Vegan' and the type is either 'Meat' or 'Dairy'", function () {
  15.             assert.equal(recipeSelection.isTypeSuitable("Meat", "Vegan"), "This recipe is not suitable for vegans");
  16.             assert.equal(recipeSelection.isTypeSuitable("Dairy", "Vegan"), "This recipe is not suitable for vegans");
  17.         });
  18.         it("In any other case if the two params are strings", function () {
  19.             assert.equal(recipeSelection.isTypeSuitable('Meat', 'Person'), "This recipe is suitable for your dietary restriction");
  20.         })
  21.     });
  22.  
  23.     describe("Test isItAffordable functionallity", function () {
  24.         it("Validate input", function () {
  25.             expect(() => { recipeSelection.isItAffordable('price', 'budget') }).to.throw('Invalid input');
  26.         });
  27.         it("If the remaining budget is less than 0", function () {
  28.             assert.equal(recipeSelection.isItAffordable(10, 5), "You don't have enough budget to afford this recipe");
  29.         });
  30.         it("If the remainin budget is more or equal to 0", function () {
  31.             assert.equal(recipeSelection.isItAffordable(10, 10), "Recipe ingredients bought. You have 0$ left");
  32.         });
  33.     });
  34.  
  35.     describe("Test getRecipesByCategory functionallity", function () {
  36.         it("Validate input", function () {
  37.             expect(() => { recipeSelection.getRecipesByCategory([{ title: " Spicy Tofu Stir-Fry ", category: " Asian " }, { title: "Spaghetti", category: "Italian" }], 2) }).to.throw('Invalid input');
  38.             expect(() => { recipeSelection.getRecipesByCategory({}, 'Italian') }).to.throw('Invalid input');
  39.         });
  40.         it("Extract the array of titles", function () {
  41.             assert(recipeSelection.getRecipesByCategory([{ title: " Spicy Tofu Stir-Fry ", category: " Asian " }, { title: "Spaghetti", category: "Italian" }, { title: "Pizza", category: "Italian" } ], 'Italian'), ['Spaghetti', 'Pizza']);
  42.         });
  43.     });
  44. });
Advertisement
Add Comment
Please, Sign In to add comment