Advertisement
Lulunga

exam prep 02. Book Store Unit my sol

Oct 26th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe("test", function () {
  2.     let store;
  3.     beforeEach(function () {
  4.         store = new BookStore('Store');
  5.     });
  6.     describe("Constructor tests", function () {
  7.         it("It should initialize properties correctly", () => {
  8.             expect(store).to.be.an.instanceof(BookStore);
  9.             expect(store.name).to.equal('Store');
  10.             expect(store.books).to.deep.equal([]);
  11.             expect(store.workers).to.deep.equal([]);
  12.         });
  13.     });
  14.  
  15.     describe("Stockbooks tests", function () {
  16.         it("Should push correctly", () => {
  17.             const expectedBook = {//arrange
  18.                 "title": "Inferno",
  19.                 "author": "Dan Braun"
  20.             };
  21.             store.stockBooks(['Inferno-Dan Braun']);//act
  22.             //assert
  23.             expect(store.books.length).to.equal(1);
  24.             expect(store.books[0]).to.deep.equal({ title: 'Inferno', author: 'Dan Braun' });
  25.             expect(store.books[0].author).to.equal('Dan Braun');
  26.             expect(store.books[0].title).to.equal('Inferno');
  27.  
  28.         });
  29.  
  30.     });
  31.  
  32.     describe("Hire tests", function () {
  33.         it("Hiring a new worker", () => {
  34.             let worker = {
  35.                 name: 'George',
  36.                 position: 'seller',
  37.                 booksSold: 0
  38.             };
  39.             expect(store.hire('George', 'seller')).to.equal("George started work at Store as seller");
  40.             expect(store.workers.length).to.equal(1);
  41.             expect(store.workers[0]).to.deep.equal(worker);
  42.         });
  43.         it("If the worker is already hired", () => {
  44.             store.hire('George', 'seller');
  45.             expect(() => store.hire('George', 'seller')).to.throw();
  46.         });
  47.     });
  48.     describe("Fire tests", function () {
  49.         it("Fire an existing worker", () => {
  50.             store.hire('Tom', 'seller');
  51.             expect(store.fire('Tom')).to.equal("Tom is fired");
  52.             expect(store.workers.length).to.equal(0);
  53.         });
  54.         it("Firing non-existing  worker", () => {
  55.             expect(() => store.fire('Tom')).to.throw();
  56.         });
  57.     });
  58.  
  59.     describe("Selling books tests", () => {
  60.  
  61.         it("Selling book with incorrect worker and title", () => {
  62.             store.hire('Tom', 'seller');
  63.             store.stockBooks(['Inferno-Dan Braun']);
  64.             expect(() => store.sellBook('Infernoku', 'Ina')).to.throw();
  65.         });
  66.         it("Selling book with correct title and existing worker", () => {
  67.             store.hire('Tom', 'seller');
  68.             store.stockBooks(['Inferno-Dan Braun']);
  69.             expect(store.sellBook('Inferno', 'Tom'));
  70.             expect(store.workers[0].booksSold).to.equal(1);
  71.             expect(store.books.length).to.equal(0);
  72.         });
  73.     });
  74.  
  75.     describe("Printing tests", function () {
  76.  
  77.         it("Printing workers", () => {
  78.             store.hire('Daria', 'vacharox');
  79.             store.hire('Tom', 'seller');
  80.  
  81.             expect(store.printWorkers()).to.equal(`Name:Daria Position:vacharox BooksSold:0\nName:Tom Position:seller BooksSold:0`);
  82.         });
  83.  
  84.     });
  85.  
  86. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement