Advertisement
Todorov_Stanimir

02. Book Store JS Advanced Retake - 08 August 2019

Oct 23rd, 2019
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. describe("class BookStore", () => {
  2.     let store;
  3.     beforeEach(function () {
  4.         store = new BookStore('Store');
  5.     });
  6.  
  7.     describe("check constructor of class", function () {
  8.  
  9.         it("shoud inirialize properties correctly", function () {
  10.             //test 1
  11.             expect(store.name).to.equal('Store');
  12.             //test 2
  13.             expect(store.books).to.be.a('array')
  14.             expect(store.workers).to.be.a('array');
  15.             expect(store.books.length).to.equal(0);
  16.             expect(store.workers.length).to.equal(0);
  17.         });
  18.     })
  19.  
  20.     describe("check method stockBooks", function () {
  21.         it("shoud add this books to store.books and return all books", function () {
  22.             let result = store.stockBooks(['Inferno-Dan Braun']);
  23.             //test 3, 4
  24.             expect(store.books.length).to.equal(1);
  25.             expect(store.books[0]).to.deep.equal({ title: 'Inferno', author: 'Dan Braun' });
  26.             expect(result).to.deep.equal([{ title: 'Inferno', author: 'Dan Braun' }]);
  27.         });
  28.     });
  29.  
  30.     describe("check method hire", function () {
  31.         it("shoud add person like worker and return object with his info", function () {
  32.             let result = store.hire('George', 'seller');
  33.             //test 8
  34.             expect(store.workers.length).to.equal(1);
  35.             expect(store.workers[0]).to.deep.equal({ name: 'George', position: 'seller', booksSold: 0 });
  36.             expect(result).to.equal(`George started work at Store as seller`)
  37.         });
  38.         it("shoud return Error if worker is added in workers", function () {
  39.             store.hire('George', 'seller');
  40.             let result = () => {
  41.                 store.hire('George', 'seller')
  42.             }
  43.             //test 5, 6, 7
  44.             expect(result).to.throw('This person is our employee');
  45.         });
  46.     });
  47.     describe("check method fire", function () {
  48.         it("shoud return an Error if the worker does not exist", function () {
  49.  
  50.             let result = () => { store.fire('George') }
  51.             //test
  52.             expect(result).to.throw(`George doesn't work here`);
  53.        });
  54.        it("shoud delete person like worker and return 'name worker is fired'", function () {
  55.            store.hire('George', 'seller');
  56.            let result = store.fire('George');
  57.            //test 9, 10, 11
  58.            expect(store.workers.length).to.equal(0);
  59.            expect(store.workers).to.deep.equal([]);
  60.            expect(result).to.equal(`George is fired`)
  61.        });
  62.    });
  63.  
  64.    describe("check method sellBook", function () {
  65.        it("shoud return an Error if the book or worker does not exists", function () {
  66.            store.hire('George', 'seller');
  67.            store.stockBooks(['Inferno-Dan Braun'])
  68.            let result = () => { store.sellBook('Inferno', 'Worker1') };
  69.            let result2 = () => { store.sellBook('Book1', 'George') }
  70.            //test
  71.            expect(result2).to.throw('This book is out of stock');
  72.            expect(result).to.throw(`Worker1 is not working here`);
  73.        });
  74.        it("shoud remove book from books, and increase booksSold of current worker", function () {
  75.            store.hire('George', 'seller');
  76.            store.stockBooks(['Inferno-Dan Braun'])
  77.            let result = store.sellBook('Inferno', 'George')
  78.            //test 12, 13, 14
  79.            expect(store.books).to.deep.equal([]);
  80.            expect(store.books.length).to.equal(0);
  81.            expect(store.workers).to.deep.equal([{ name: 'George', position: 'seller', booksSold: 1 }])
  82.        });
  83.    });
  84.    describe("check method printWorkers", function () {
  85.        it("shoud return all workers", function () {
  86.            store.stockBooks(['Inferno-Dan Braun', 'Harry Potter-J.Rowling', 'Uncle Toms Cabin-Hariet Stow', 'The Jungle-Upton Sinclear']);
  87.            store.hire('George', 'seller');
  88.            store.hire('Ina', 'seller');
  89.            store.hire('Tom', 'juniorSeller');
  90.  
  91.            store.sellBook('Inferno', 'Ina');
  92.            store.stockBooks(['Harry Potter-J.Rowling']);
  93.  
  94.            store.fire('Tom');
  95.            let result = store.printWorkers();
  96.            //test
  97.            expect(result).to.equal('Name:George Position:seller BooksSold:0\nName:Ina Position:seller BooksSold:1');
  98.        });
  99.    });
  100.  
  101. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement