Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.5 kB
1
Indexable
Never
const chai = require('chai');
const sinon = require('sinon');
const salesModels = require('../../../src/models/sales.models');
const { SALES_MOCK, SERVICES_SALE_NOTFOUND_MOCK, SINGLE_SALE_MOCK } = require('../mocks/SALES_MOCKS');

const { expect } = chai;

describe('Tests /services/sales.services', function () {
  afterEach(function () {
    sinon.restore();
  });

  describe('Tests getAllSales from /services/sales.services', function () {
    it('Returns all the sales from the table SALES as an array', async function () {
      const stub = sinon.stub(salesModels, 'getAllSales').returns(SALES_MOCK);
      const sales = await salesModels.getAllSales();
      expect(sales).to.be.an('array');
      expect(sales).to.deep.equal(SALES_MOCK);
      stub.restore();
    });
  });

  describe('Tests getSaleById from /services/sales.services', function () {
    it('Returns a single sale when the ID is found in the table SALES', async function () {
      const stub = sinon.stub(salesModels, 'getSaleById').returns(SINGLE_SALE_MOCK);
      const sale = await salesModels.getSaleById(1);
      expect(sale).to.deep.equal(SINGLE_SALE_MOCK);
      stub.restore();
    });

    it('Returns "Sale not found" if a sale does not exist in the table SALES', async function () {
      const stub = sinon.stub(salesModels, 'getSaleById').returns(SERVICES_SALE_NOTFOUND_MOCK);
      const sale = await salesModels.getSaleById(6);

      expect(sale).to.deep.equal(SERVICES_SALE_NOTFOUND_MOCK);

      stub.restore();
    });
  });
});
Leave a Comment