Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.5 kB
2
Indexable
Never
const chai = require('chai');
const sinon = require('sinon');
const modelSales = require('../../../src/models/model.sales');
const {
  SalesIdOne,
  salesNotFoundMock,
  mocksSales,
} = require('../mocks/sales.mocks');

const { expect } = chai;

describe('Realiza teste da Sales', function () {
  it('Na models verifica se retorna todos os sales ', async function () {
    const stubAll = sinon.stub(modelSales, 'getSalesAll').returns(mocksSales);
    const salesAll = await modelSales.getSalesAll();
    expect(salesAll).to.be.deep.equal(mocksSales);

    stubAll.restore();
  });

  it('Verifica se retorna um sale pelo id', async function () {
    const stubId = sinon.stub(modelSales, 'getSalesId').returns(SalesIdOne);
    const salesId = await modelSales.getSalesId(1);
    expect(salesId).to.be.deep.equal(SalesIdOne);

    stubId.restore();
  });

  it('Verifica se retorna o erro " Sale not found" caso nao exista venda', async function () {
    const stubId = sinon.stub(modelSales, 'getSalesId').returns(salesNotFoundMock);
    const salesId = await modelSales.getSalesId(7);
    expect(salesId).to.be.deep.equal(salesNotFoundMock);

    stubId.restore();
  });

  it('Verifca se retorna uma unica venda com sucesso', async function () {
    const stubId = sinon.stub(modelSales, 'getSalesId').returns(SalesIdOne);
    const salesId = await modelSales.getSalesId(1);
    expect(salesId).to.be.deep.equal(SalesIdOne);

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