#1486 back test updateDiscount

This commit is contained in:
Carlos Jimenez Ruiz 2019-05-30 08:57:25 +02:00
parent cfcadc4f28
commit 80d5c923cc
1 changed files with 82 additions and 0 deletions

View File

@ -0,0 +1,82 @@
const app = require('vn-loopback/server/server');
// #1486 back test updateDiscount
xdescribe('sale updateDiscount()', () => {
let originalSale;
let createdSaleComponent;
afterAll(async done => {
originalSale.save();
createdSaleComponent.destroy();
done();
});
it('should throw an error if any sale discount is not a number', async() => {
let error;
const ticketId = 1;
const sales = [
{discount: 'pepinillos'}
];
try {
await app.models.Sale.updateDiscount(ticketId, sales);
} catch (err) {
error = err;
}
expect(error.message).toEqual('The value should be a number');
});
it('should throw an error if the ticket is invoiced already', async() => {
let error;
const ticketId = 7;
const sales = [
{discount: 100}
];
try {
await app.models.Sale.updateDiscount(ticketId, sales);
} catch (err) {
error = err;
}
expect(error.message).toEqual(`The sales of this ticket can't be modified`);
});
it('should update the discount if the salesPerson has mana', async() => {
const saleId = 1;
originalSale = await app.models.Sale.findById(saleId);
let manaDiscount = await app.models.ComponentRate.findOne({where: {code: 'mana'}});
let componentId = manaDiscount.id;
createdSaleComponent = await app.models.SaleComponent.findOne({
where: {
componentFk: componentId,
saleFk: saleId
}
});
expect(createdSaleComponent).toBeNull();
const ticketId = 8;
const sales = [
{
id: saleId,
discount: 100}
];
await app.models.Sale.updateDiscount(ticketId, sales);
let updatedSale = await app.models.Sale.findById(saleId);
createdSaleComponent = await app.models.SaleComponent.findOne({
where: {
componentFk: componentId,
saleFk: saleId
}
});
expect(createdSaleComponent.componentFk).toEqual(componentId);
expect(updatedSale.discount).toEqual(100);
});
});