Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into dev
gitea/salix/dev This commit looks good Details

This commit is contained in:
Carlos Jimenez Ruiz 2019-05-30 08:57:38 +02:00
commit ed3024e144
2 changed files with 114 additions and 23 deletions

View File

@ -73,6 +73,7 @@
</vn-horizontal> </vn-horizontal>
<vn-horizontal> <vn-horizontal>
<vn-input-number vn-one min="0" <vn-input-number vn-one min="0"
step="0.01"
label="Density" label="Density"
field="$ctrl.item.density"> field="$ctrl.item.density">
</vn-input-number> </vn-input-number>

View File

@ -1,31 +1,121 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
describe('sale updatePrice()', () => { // #1489 updatePrice backTest
it('should throw an error if the price is not a number', async() => { xdescribe('sale updatePrice()', () => {
let error; 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);
let params = {price: `this price is so wrong!`}; expect(saleUpdated.price).toEqual(0);
await app.models.Sale.updatePrice(params)
.catch(response => {
expect(response).toEqual(new Error('The value should be a number'));
error = response;
});
expect(error).toBeDefined();
}); });
it(`should throw an error if the price is undefined`, async() => { it('should set price as a decimal number', async() => {
let error; let params = {
price: 5.5,
id: 13,
ticketFk: 8
};
await app.models.Sale.updatePrice(params);
let saleUpdated = await app.models.Sale.findById(params.id);
let params = {ticketFk: 1, price: undefined}; expect(saleUpdated.price).toEqual(5.5);
await app.models.Sale.updatePrice(params)
.catch(response => {
expect(response).toEqual(new Error('The value should be a number'));
error = response;
});
expect(error).toBeDefined();
}); });
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);
expect(saleUpdated.price).toEqual(5.5);
});
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);
expect(saleUpdated.price).toEqual(0);
});
it('should este crea mana', 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);
expect(saleUpdated.price).toEqual(5.5);
});
it('should este no crea el mana', async() => {
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();
// });
}); });