Untitled
unknown
plain_text
2 years ago
1.4 kB
10
Indexable
const chai = require('chai');
const sinon = require('sinon');
const salesModels = require('../../../src/models/sales.models');
const { SALES_MOCK, SALES_MOCK_NOTFOUND, SINGLE_SALE_MOCK } = require('../mocks/SALES_MOCKS');
const { expect } = chai;
describe('Tests /models/sales.models', function () {
describe('When sales/sale exists', 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();
});
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();
});
});
describe('When sales/sale DOES NOT exists', function () {
it('Returns "Sale not found" if a sale does not exist in the table SALES', async function () {
const stub = sinon.stub(salesModels, 'getSaleById').returns(SALES_MOCK_NOTFOUND);
const sale = await salesModels.getSaleById(5);
expect(sale).to.deep.equal(SALES_MOCK_NOTFOUND);
stub.restore();
});
});
});
Editor is loading...
Leave a Comment