2019-01-24 08:08:28 +00:00
|
|
|
const app = require('vn-loopback/server/server');
|
2018-08-14 10:48:12 +00:00
|
|
|
|
2019-05-29 12:59:26 +00:00
|
|
|
// #1489 updatePrice backTest
|
|
|
|
xdescribe('sale updatePrice()', () => {
|
|
|
|
it('should set price to 0 if the params price is undefined', async() => {
|
|
|
|
let params = {
|
|
|
|
price: undefined,
|
|
|
|
id: 13,
|
|
|
|
ticketFk: 8
|
|
|
|
};
|
|
|
|
await app.models.Sale.updatePrice(params);
|
|
|
|
let saleUpdated = await app.models.Sale.findById(params.id);
|
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 set price as a decimal number', async() => {
|
|
|
|
let params = {
|
|
|
|
price: 5.5,
|
|
|
|
id: 13,
|
|
|
|
ticketFk: 8
|
|
|
|
};
|
|
|
|
await app.models.Sale.updatePrice(params);
|
|
|
|
let saleUpdated = await app.models.Sale.findById(params.id);
|
2018-08-14 10:48:12 +00:00
|
|
|
|
2019-05-29 12:59:26 +00:00
|
|
|
expect(saleUpdated.price).toEqual(5.5);
|
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 params = {
|
|
|
|
price: '5.5',
|
|
|
|
id: 13,
|
|
|
|
ticketFk: 8
|
|
|
|
};
|
|
|
|
await app.models.Sale.updatePrice(params);
|
|
|
|
let saleUpdated = await app.models.Sale.findById(params.id);
|
2018-08-14 10:48:12 +00:00
|
|
|
|
2019-05-29 12:59:26 +00:00
|
|
|
expect(saleUpdated.price).toEqual(5.5);
|
|
|
|
});
|
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 params = {
|
|
|
|
price: '',
|
|
|
|
id: 13,
|
|
|
|
ticketFk: 8
|
|
|
|
};
|
|
|
|
await app.models.Sale.updatePrice(params);
|
|
|
|
let saleUpdated = await app.models.Sale.findById(params.id);
|
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-05-30 06:06:52 +00:00
|
|
|
it('should este crea mana', async() => {
|
2019-05-29 12:59:26 +00:00
|
|
|
let params = {
|
|
|
|
price: 5.5,
|
|
|
|
id: 13,
|
|
|
|
ticketFk: 8
|
|
|
|
};
|
|
|
|
await app.models.Sale.updatePrice(params);
|
|
|
|
let saleUpdated = await app.models.Sale.findById(params.id);
|
|
|
|
|
|
|
|
expect(saleUpdated.price).toEqual(5.5);
|
|
|
|
});
|
|
|
|
|
2019-05-30 06:06:52 +00:00
|
|
|
it('should este no crea el mana', async() => {
|
2019-05-29 12:59:26 +00:00
|
|
|
let params = {
|
|
|
|
price: 5.5,
|
|
|
|
id: 13,
|
|
|
|
ticketFk: 8
|
|
|
|
};
|
|
|
|
let todosLosComponentes = await app.models.SaleComponent.find({where: {saleFk: 13}});
|
|
|
|
|
|
|
|
expect(todosLosComponentes[0].value).toEqual('');
|
|
|
|
expect(todosLosComponentes[1].value).toEqual('');
|
|
|
|
expect(todosLosComponentes[2].value).toEqual('');
|
|
|
|
expect(todosLosComponentes[3].value).toEqual('');
|
|
|
|
expect(todosLosComponentes[4].value).toEqual('');
|
|
|
|
|
|
|
|
await app.models.Sale.updatePrice(params);
|
|
|
|
todosLosComponentes = await app.models.SaleComponent.find({where: {saleFk: 13}});
|
|
|
|
let saleUpdated = await app.models.Sale.findById(params.id);
|
|
|
|
|
|
|
|
expect(saleUpdated.price).toEqual(5.5);
|
|
|
|
|
|
|
|
expect(todosLosComponentes[0].value).toEqual('');
|
|
|
|
expect(todosLosComponentes[1].value).toEqual('');
|
|
|
|
expect(todosLosComponentes[2].value).toEqual('');
|
|
|
|
expect(todosLosComponentes[3].value).toEqual('');
|
|
|
|
expect(todosLosComponentes[4].value).toEqual('');
|
|
|
|
});
|
|
|
|
// 2 let componentToUse;
|
|
|
|
// if (usesMana)
|
|
|
|
// componentToUse = 37;
|
|
|
|
// 3else
|
|
|
|
// componentToUse = 34;
|
|
|
|
|
|
|
|
// 4 if (saleComponent)
|
|
|
|
// saleComponent.updateAttributes({value: saleComponent.value + value});
|
|
|
|
// 5 else {
|
|
|
|
// await Self.app.models.SaleComponent.create({
|
|
|
|
// saleFk: params.id,
|
|
|
|
// componentFk: componentToUse,
|
|
|
|
// value: value
|
|
|
|
// });
|
|
|
|
// }
|
|
|
|
|
|
|
|
// it(`should throw an error if the price is undefined`, async() => {
|
|
|
|
// let error;
|
|
|
|
|
|
|
|
// let params = {ticketFk: 1, price: undefined};
|
|
|
|
|
|
|
|
// await app.models.Sale.updatePrice(params)
|
|
|
|
// .catch(response => {
|
|
|
|
// expect(response).toEqual(new Error('The value should be a number'));
|
|
|
|
// error = response;
|
|
|
|
// });
|
|
|
|
|
|
|
|
// expect(error).toBeDefined();
|
|
|
|
// });
|
2018-08-14 10:48:12 +00:00
|
|
|
});
|