2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-08-14 10:48:12 +00:00
|
|
|
|
2019-06-11 10:23:55 +00:00
|
|
|
describe('sale updatePrice()', () => {
|
2019-06-03 06:01:24 +00:00
|
|
|
let originalSale;
|
|
|
|
let originalSalesPersonMana;
|
|
|
|
let createdSaleComponent;
|
2019-06-14 10:27:41 +00:00
|
|
|
let saleId = 7;
|
2019-06-19 12:40:47 +00:00
|
|
|
let manaComponentId;
|
2019-06-03 06:01:24 +00:00
|
|
|
|
2019-06-19 12:40:47 +00:00
|
|
|
beforeAll(async done => {
|
2019-12-27 07:01:53 +00:00
|
|
|
let component = await app.models.Component.findOne({where: {code: 'mana'}});
|
|
|
|
manaComponentId = component.id;
|
2019-06-19 12:40:47 +00:00
|
|
|
originalSale = await app.models.Sale.findById(saleId);
|
|
|
|
originalSalesPersonMana = await app.models.WorkerMana.findById(18);
|
2019-06-03 06:01:24 +00:00
|
|
|
|
|
|
|
done();
|
2019-05-29 12:59:26 +00:00
|
|
|
});
|
2018-08-14 10:48:12 +00:00
|
|
|
|
2019-06-19 12:40:47 +00:00
|
|
|
afterAll(async done => {
|
|
|
|
await originalSale.save();
|
|
|
|
await app.models.SaleComponent.updateAll({componentFk: manaComponentId, saleFk: saleId}, {value: 0});
|
|
|
|
await originalSalesPersonMana.save();
|
2018-08-14 10:48:12 +00:00
|
|
|
|
2019-06-03 06:01:24 +00:00
|
|
|
done();
|
2018-08-14 10:48:12 +00:00
|
|
|
});
|
|
|
|
|
2019-06-19 12:40:47 +00:00
|
|
|
|
2019-06-03 06:01:24 +00:00
|
|
|
it('should throw an error if the ticket is not editable', async() => {
|
2019-07-22 11:14:00 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: 9}}};
|
2019-06-03 06:01:24 +00:00
|
|
|
let immutableSaleId = 1;
|
|
|
|
let price = 5;
|
2018-08-14 10:48:12 +00:00
|
|
|
|
2019-07-22 11:14:00 +00:00
|
|
|
await app.models.Sale.updatePrice(ctx, immutableSaleId, price)
|
2019-06-03 06:01:24 +00:00
|
|
|
.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() => {
|
2019-07-22 11:14:00 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: 9}}};
|
2019-06-03 06:01:24 +00:00
|
|
|
let price = '';
|
|
|
|
|
2019-07-22 11:14:00 +00:00
|
|
|
await app.models.Sale.updatePrice(ctx, saleId, price);
|
2019-06-03 06:01:24 +00:00
|
|
|
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
|
|
|
|
2019-06-03 06:01:24 +00:00
|
|
|
it('should now set price as a decimal number in a string', async() => {
|
2019-07-22 11:14:00 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: 9}}};
|
2019-06-03 06:01:24 +00:00
|
|
|
let price = '8';
|
2019-05-29 12:59:26 +00:00
|
|
|
|
2019-07-22 11:14:00 +00:00
|
|
|
await app.models.Sale.updatePrice(ctx, saleId, price);
|
2019-06-03 06:01:24 +00:00
|
|
|
let saleUpdated = await app.models.Sale.findById(saleId);
|
2019-05-29 12:59:26 +00:00
|
|
|
|
2019-06-03 06:01:24 +00:00
|
|
|
expect(saleUpdated.price).toEqual(8);
|
2019-05-29 12:59:26 +00:00
|
|
|
});
|
|
|
|
|
2019-06-03 06:01:24 +00:00
|
|
|
it('should set price as a decimal number and check the sale has the mana component', async() => {
|
2019-07-22 11:14:00 +00:00
|
|
|
let ctx = {req: {accessToken: {userId: 9}}};
|
2019-10-15 05:23:34 +00:00
|
|
|
let price = 5.4;
|
2019-05-29 12:59:26 +00:00
|
|
|
|
2019-07-22 11:14:00 +00:00
|
|
|
await app.models.Sale.updatePrice(ctx, saleId, price);
|
2019-06-03 06:01:24 +00:00
|
|
|
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
|
|
|
|
2019-09-17 11:52:29 +00:00
|
|
|
expect(saleUpdated.price).toBe(price);
|
2019-10-15 05:23:34 +00:00
|
|
|
expect(createdSaleComponent.value).toEqual(-2.04);
|
2019-06-03 06:01:24 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
2019-06-03 06:01:24 +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
|
|
|
});
|