Advertisement
iWantAMcLaren

bookstore

Oct 25th, 2019
542
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {npm i chai/mocha --save}
  2. mocha tests -> bdd , ${file}
  3. module.exports = BookStore;
  4. const BookStore = require('./BookStore.js');
  5. const  expect = require('chai').expect;
  6. const  assert = require('chai').assert;
  7.  
  8. describe("BookStore",()=>{
  9.     describe("Constructor Tests",()=>{
  10.         it("Creation", ()=>{
  11.         let x = new BookStore("Pesho");
  12.         expect(x.name === "Pesho").to.be.true;
  13.         })
  14.         it("Constructor Test => expect [] from books", ()=>{
  15.             let x = new BookStore("Pesho");
  16.             expect(x.books.length === 0).to.be.true;
  17.             })
  18.             it("Constructor Test => expect [] from workers", ()=>{
  19.                 let x = new BookStore("Pesho");
  20.                 expect(x.workers.length === 0).to.be.true;
  21.                 })
  22.                 it("Creation", ()=>{
  23.                     let x = new BookStore();
  24.                     expect(x instanceof BookStore).to.be.true
  25.                     })
  26.     })
  27.     describe("stockBooks() Tests",()=>{
  28.         it("Does it push elements",()=>{
  29.             let input = ["asd-asd"];
  30.             let x = new BookStore("Pesho");
  31.             x.stockBooks(input);
  32.             expect(x.books.length === 1).to.true;
  33.         })
  34.         it("what it returns",()=>{
  35.             let input = ["asd-asd"];;
  36.             let x = new BookStore("Pesho");
  37.            expect(x.stockBooks(input)).to.equal(x.books)
  38.         })
  39.         it("Does it push elements",()=>{
  40.             let input = [];
  41.             let x = new BookStore("Pesho");
  42.             x.stockBooks(input);
  43.             expect(x.books.length === 0).to.true;
  44.         })
  45.         it("Does it push elements",()=>{
  46.             let input = ["asd-asd","dsa-dsa"];
  47.             let x = new BookStore("Pesho");
  48.             x.stockBooks(input);
  49.             x.stockBooks(input);
  50.             expect(x.books.length === 4).to.true;
  51.         })
  52.         it("Does it push elements",()=>{
  53.             let input = ["asd-asd"];
  54.             let x = new BookStore("Pesho");
  55.             let y = x.stockBooks(input);
  56.             expect(x.books === y).to.be.true;;
  57.         })
  58.     })
  59.     describe("hire()  Tests",()=>{
  60.         it("Does it add workers",()=>{
  61.             let x = new BookStore("Pesho");
  62.             x.hire("Pesho","chistach");
  63.             expect(x.workers.length === 1).to.true;
  64.         })
  65.         it("Does print message",()=>{
  66.             let x = new BookStore("Pesho");
  67.             expect(x.hire("Pesho","chistach")).to.equal(`Pesho started work at Pesho as chistach`);
  68.         })
  69.         it("Error test This person is our employee",()=>{
  70.             let x = new BookStore("Pesho");
  71.             x.hire("Pesho","chistach");
  72.             expect(()=> x.hire("Pesho","chistach")).to.Throw('This person is our employee');
  73.         })
  74.  
  75.     })
  76.     describe("fire()  Tests",()=>{
  77.         it("Does it remove workers",()=>{
  78.             let x = new BookStore("Pesho");
  79.             x.hire("Pesho","chistach");
  80.             x.fire("Pesho");
  81.             expect(x.workers.length === 0).to.true;
  82.         })
  83.         it("Does it remove workers",()=>{
  84.             let x = new BookStore("Pesho");
  85.             x.hire("Pesho","chistach");
  86.             expect(x.fire("Pesho")).to.equal("Pesho is fired");
  87.         })
  88.         it("Does it remove workers",()=>{
  89.             let x = new BookStore("Pesho");
  90.             x.hire("Pesho","chistach");
  91.             x.fire("Pesho")
  92.             expect(()=> x.fire("Pesho")).to.Throw("Pesho doesn't work here");
  93.         })
  94.     })
  95.  
  96.     describe("sellBook() Tests",()=>{
  97.         it("Does it sell",()=>{
  98.             let input = ["asd-asd"];
  99.             let x = new BookStore("Pesho");
  100.             x.hire("Pesho","chistach");
  101.             x.stockBooks(input);
  102.             x.sellBook("asd","Pesho");
  103.             expect(x.books.length === 0).to.true;
  104.         })
  105.         it("Has pesho sold the book",()=>{
  106.             let input = ["asd-asd"];
  107.             let x = new BookStore("Pesho");
  108.             x.hire("Pesho","chistach");
  109.             x.stockBooks(input);
  110.             x.sellBook("asd","Pesho");
  111.             let y = x.workers[0];
  112.             expect(y.booksSold).to.equal(1);
  113.         })
  114.         it("throw This book is out of stock",()=>{
  115.             let input = ["asd-asd"];
  116.             let x = new BookStore("Pesho");
  117.             x.hire("Pesho","chistach");
  118.             x.stockBooks(input);
  119.             x.sellBook("asd","Pesho")
  120.             expect(()=> x.sellBook("asd","Pesho")).to.Throw('This book is out of stock');
  121.         })
  122.         it("throw Pesho is not working here",()=>{
  123.             let input = ["asd-asd"];
  124.             let x = new BookStore("Pesho");
  125.             x.stockBooks(input);
  126.             expect(()=> x.sellBook("asd","Pesho")).to.Throw(`Pesho is not working here`);
  127.         })
  128.  
  129.     })
  130.     describe("print method tests",()=>{
  131.         it("how it prints",()=>{
  132.             let x = new BookStore("Pesho");
  133.             x.hire("Pesho","chistach");
  134.             let y = x.printWorkers();
  135.             expect(y).to.equal(`Name:Pesho Position:chistach BooksSold:0`);
  136.         })
  137.     })
  138. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement