Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
1.3 kB
2
Indexable
Never
describe('Quando a venda é inserida com sucesso', function () {
    it('Deve ser possível inserir uma venda', async function () {
      const req = {
        body: INSERT_ONE_SALE_MOCK,
      };
      const res = {
        status: sinon.stub().returnsThis(),
        json: sinon.stub().returnsThis(),
      };
      const stub = sinon.stub(salesService, 'insertProductIntoSale').resolves(RESULT_INSERT_ONE_SALE_MOCK);
      const stub2 = sinon.stub(salesService, 'getSaleByIdService').resolves(RESULT_NEW_INSERT_ONE_SALE_MOCK);
      await salesController.insertSale(req, res);
      expect(res.status).to.have.been.calledWith(201);
      stub.restore();
      stub2.restore();
    });

    it('Deve ser possível inserir duas vendas', async function () {
      const req = {
        body: INSERT_TWO_SALES_MOCK,
      };
      const res = {
        status: sinon.stub().returnsThis(),
        json: sinon.stub().returnsThis(),
      };
      const stub = sinon.stub(salesService, 'insertProductIntoSale').resolves(RESULT_INSERT_TWO_SALES_MOCK);
      const stub2 = sinon.stub(salesService, 'getSaleByIdService').resolves(RESULT_NEW_INSERT_TWO_SALES_MOCK);
      await salesController.insertSale(req, res);
      expect(res.status).to.have.been.calledWith(201);
      stub.restore();
      stub2.restore();
    });
  });
Leave a Comment