Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe("class BookStore", () => {
- let store;
- beforeEach(function () {
- store = new BookStore('Store');
- });
- describe("check constructor of class", function () {
- it("shoud inirialize properties correctly", function () {
- //test 1
- expect(store.name).to.equal('Store');
- //test 2
- expect(store.books).to.be.a('array')
- expect(store.workers).to.be.a('array');
- expect(store.books.length).to.equal(0);
- expect(store.workers.length).to.equal(0);
- });
- })
- describe("check method stockBooks", function () {
- it("shoud add this books to store.books and return all books", function () {
- let result = store.stockBooks(['Inferno-Dan Braun']);
- //test 3, 4
- expect(store.books.length).to.equal(1);
- expect(store.books[0]).to.deep.equal({ title: 'Inferno', author: 'Dan Braun' });
- expect(result).to.deep.equal([{ title: 'Inferno', author: 'Dan Braun' }]);
- });
- });
- describe("check method hire", function () {
- it("shoud add person like worker and return object with his info", function () {
- let result = store.hire('George', 'seller');
- //test 8
- expect(store.workers.length).to.equal(1);
- expect(store.workers[0]).to.deep.equal({ name: 'George', position: 'seller', booksSold: 0 });
- expect(result).to.equal(`George started work at Store as seller`)
- });
- it("shoud return Error if worker is added in workers", function () {
- store.hire('George', 'seller');
- let result = () => {
- store.hire('George', 'seller')
- }
- //test 5, 6, 7
- expect(result).to.throw('This person is our employee');
- });
- });
- describe("check method fire", function () {
- it("shoud return an Error if the worker does not exist", function () {
- let result = () => { store.fire('George') }
- //test
- expect(result).to.throw(`George doesn't work here`);
- });
- it("shoud delete person like worker and return 'name worker is fired'", function () {
- store.hire('George', 'seller');
- let result = store.fire('George');
- //test 9, 10, 11
- expect(store.workers.length).to.equal(0);
- expect(store.workers).to.deep.equal([]);
- expect(result).to.equal(`George is fired`)
- });
- });
- describe("check method sellBook", function () {
- it("shoud return an Error if the book or worker does not exists", function () {
- store.hire('George', 'seller');
- store.stockBooks(['Inferno-Dan Braun'])
- let result = () => { store.sellBook('Inferno', 'Worker1') };
- let result2 = () => { store.sellBook('Book1', 'George') }
- //test
- expect(result2).to.throw('This book is out of stock');
- expect(result).to.throw(`Worker1 is not working here`);
- });
- it("shoud remove book from books, and increase booksSold of current worker", function () {
- store.hire('George', 'seller');
- store.stockBooks(['Inferno-Dan Braun'])
- let result = store.sellBook('Inferno', 'George')
- //test 12, 13, 14
- expect(store.books).to.deep.equal([]);
- expect(store.books.length).to.equal(0);
- expect(store.workers).to.deep.equal([{ name: 'George', position: 'seller', booksSold: 1 }])
- });
- });
- describe("check method printWorkers", function () {
- it("shoud return all workers", function () {
- store.stockBooks(['Inferno-Dan Braun', 'Harry Potter-J.Rowling', 'Uncle Toms Cabin-Hariet Stow', 'The Jungle-Upton Sinclear']);
- store.hire('George', 'seller');
- store.hire('Ina', 'seller');
- store.hire('Tom', 'juniorSeller');
- store.sellBook('Inferno', 'Ina');
- store.stockBooks(['Harry Potter-J.Rowling']);
- store.fire('Tom');
- let result = store.printWorkers();
- //test
- expect(result).to.equal('Name:George Position:seller BooksSold:0\nName:Ina Position:seller BooksSold:1');
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement