Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- describe("test", function () {
- let store;
- beforeEach(function () {
- store = new BookStore('Store');
- });
- describe("Constructor tests", function () {
- it("It should initialize properties correctly", () => {
- expect(store).to.be.an.instanceof(BookStore);
- expect(store.name).to.equal('Store');
- expect(store.books).to.deep.equal([]);
- expect(store.workers).to.deep.equal([]);
- });
- });
- describe("Stockbooks tests", function () {
- it("Should push correctly", () => {
- const expectedBook = {//arrange
- "title": "Inferno",
- "author": "Dan Braun"
- };
- store.stockBooks(['Inferno-Dan Braun']);//act
- //assert
- expect(store.books.length).to.equal(1);
- expect(store.books[0]).to.deep.equal({ title: 'Inferno', author: 'Dan Braun' });
- expect(store.books[0].author).to.equal('Dan Braun');
- expect(store.books[0].title).to.equal('Inferno');
- });
- });
- describe("Hire tests", function () {
- it("Hiring a new worker", () => {
- let worker = {
- name: 'George',
- position: 'seller',
- booksSold: 0
- };
- expect(store.hire('George', 'seller')).to.equal("George started work at Store as seller");
- expect(store.workers.length).to.equal(1);
- expect(store.workers[0]).to.deep.equal(worker);
- });
- it("If the worker is already hired", () => {
- store.hire('George', 'seller');
- expect(() => store.hire('George', 'seller')).to.throw();
- });
- });
- describe("Fire tests", function () {
- it("Fire an existing worker", () => {
- store.hire('Tom', 'seller');
- expect(store.fire('Tom')).to.equal("Tom is fired");
- expect(store.workers.length).to.equal(0);
- });
- it("Firing non-existing worker", () => {
- expect(() => store.fire('Tom')).to.throw();
- });
- });
- describe("Selling books tests", () => {
- it("Selling book with incorrect worker and title", () => {
- store.hire('Tom', 'seller');
- store.stockBooks(['Inferno-Dan Braun']);
- expect(() => store.sellBook('Infernoku', 'Ina')).to.throw();
- });
- it("Selling book with correct title and existing worker", () => {
- store.hire('Tom', 'seller');
- store.stockBooks(['Inferno-Dan Braun']);
- expect(store.sellBook('Inferno', 'Tom'));
- expect(store.workers[0].booksSold).to.equal(1);
- expect(store.books.length).to.equal(0);
- });
- });
- describe("Printing tests", function () {
- it("Printing workers", () => {
- store.hire('Daria', 'vacharox');
- store.hire('Tom', 'seller');
- expect(store.printWorkers()).to.equal(`Name:Daria Position:vacharox BooksSold:0\nName:Tom Position:seller BooksSold:0`);
- });
- });
- })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement