salix/modules/ticket/back/methods/sale/specs/updatePrice.spec.js

73 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-01-24 08:08:28 +00:00
const app = require('vn-loopback/server/server');
2018-08-14 10:48:12 +00:00
describe('sale updatePrice()', () => {
let originalSale;
let originalSalesPersonMana;
let createdSaleComponent;
let saleId = 13;
afterAll(async done => {
2019-06-05 13:05:07 +00:00
await originalSale.save();
await app.models.SaleComponent.updateAll({componentFk: 37, saleFk: saleId}, {value: 0});
await originalSalesPersonMana.save();
done();
2019-05-29 12:59:26 +00:00
});
2018-08-14 10:48:12 +00:00
beforeAll(async done => {
originalSale = await app.models.Sale.findById(saleId);
originalSalesPersonMana = await app.models.WorkerMana.findById(18);
2018-08-14 10:48:12 +00:00
done();
2018-08-14 10:48:12 +00:00
});
it('should throw an error if the ticket is not editable', async() => {
let immutableSaleId = 1;
let price = 5;
2018-08-14 10:48:12 +00:00
await app.models.Sale.updatePrice(immutableSaleId, price)
.catch(response => {
expect(response).toEqual(new Error(`The sales of this ticket can't be modified`));
error = response;
});
expect(error).toBeDefined();
2019-05-29 12:59:26 +00:00
});
2018-08-14 10:48:12 +00:00
2019-05-29 12:59:26 +00:00
it('should return 0 if the price is an empty string', async() => {
let price = '';
await app.models.Sale.updatePrice(saleId, price);
let saleUpdated = await app.models.Sale.findById(saleId);
2018-08-14 10:48:12 +00:00
2019-05-29 12:59:26 +00:00
expect(saleUpdated.price).toEqual(0);
2018-08-14 10:48:12 +00:00
});
2019-05-29 12:59:26 +00:00
it('should now set price as a decimal number in a string', async() => {
let price = '8';
2019-05-29 12:59:26 +00:00
await app.models.Sale.updatePrice(saleId, price);
let saleUpdated = await app.models.Sale.findById(saleId);
2019-05-29 12:59:26 +00:00
expect(saleUpdated.price).toEqual(8);
2019-05-29 12:59:26 +00:00
});
it('should set price as a decimal number and check the sale has the mana component', async() => {
let price = 5.5;
let manaComponentId = 37;
2019-05-29 12:59:26 +00:00
await app.models.Sale.updatePrice(saleId, price);
let saleUpdated = await app.models.Sale.findById(saleId);
createdSaleComponent = await app.models.SaleComponent.findOne({where: {saleFk: saleId, componentFk: manaComponentId}});
2019-05-29 12:59:26 +00:00
expect(saleUpdated.price).toEqual(5.5);
expect(createdSaleComponent.value).toEqual(4.200);
});
it('should check that the mana of salesPerson changed', async() => {
let updatedSalesPersonMana = await app.models.WorkerMana.findById(18);
2019-05-29 12:59:26 +00:00
expect(updatedSalesPersonMana.amount).not.toEqual(originalSalesPersonMana.amount);
2019-05-29 12:59:26 +00:00
});
2018-08-14 10:48:12 +00:00
});