This commit is contained in:
Javi Gallego 2020-12-29 17:00:22 +01:00
parent 0c7ddd863d
commit 3db3d65600
1 changed files with 30 additions and 14 deletions

View File

@ -8,35 +8,44 @@ fdescribe('Receipt createReceipt', () => {
const description = 'Receipt description';
it('should create a new receipt', async() => {
const ctx = {
const bankFk = 1;
let ctx = {
args: {
clientFk: clientFk,
payed: payed,
companyFk: companyFk,
bankFk: 1,
bankFk: bankFk,
amountPaid: amountPaid,
description: description
}
};
const receipt = await app.models.Receipt.createReceipt(ctx);
console.log(receipt);
console.log(ctx.args);
delete ctx.args.payed;
expect(receipt).toEqual(jasmine.objectContaining(ctx.args));
const till = await models.Till.findOne({
where: {
bankFk: bankFk,
in: amountPaid,
dated: payed,
number: clientFk
}
});
// restores
await receipt.destroy();
// destroy till
await till.destroy();
});
it('should throw Invalid account if compensationAccount does not belongs to a client nor a supplier', async() => {
const bankFk = 3;
const ctx = {
args: {
clientFk: clientFk,
payed: payed,
companyFk: companyFk,
bankFk: 3,
bankFk: bankFk,
amountPaid: amountPaid,
description: description,
compensationAccount: 'non existing account'
@ -51,16 +60,16 @@ fdescribe('Receipt createReceipt', () => {
expect(err).toBeDefined();
expect(err.message).toEqual('Invalid account');
// validar que no ha creado el receipt porque el rollback ha funcionado
});
it('should create a new receipt with a compensation for a client', async() => {
const bankFk = 3;
const ctx = {
args: {
clientFk: clientFk,
payed: payed,
companyFk: companyFk,
bankFk: 3,
bankFk: bankFk,
amountPaid: amountPaid,
description: description,
compensationAccount: '4300000001'
@ -76,20 +85,28 @@ fdescribe('Receipt createReceipt', () => {
}
});
const till = await models.Till.findOne({
where: {
bankFk: bankFk,
in: amountPaid,
dated: payed,
number: clientFk
}
});
expect(receipt).toEqual(jasmine.objectContaining(ctx.args));
expect(receiptCompensated.amountPaid).toEqual(-receiptCompensated.amountPaid);
// jasmine.objectContaining vs expect.objectContaining
expect(receipt.amountPaid).toEqual(-receiptCompensated.amountPaid);
// restores
await receipt.destroy();
await receiptCompensated.destroy();
// destroy till
// destroy XDiario
await till.destroy();
});
it('should create a new receipt with a compensation for a supplier', async() => {
const ctx = {
args: {
clientFk: clientFk,
payed: payed,
companyFk: companyFk,
bankFk: 3,
@ -111,7 +128,6 @@ fdescribe('Receipt createReceipt', () => {
expect(receipt).toEqual(jasmine.objectContaining(ctx.args));
// expect(receiptCompensated.amountPaid).toEqual(receiptCompensated.amountPaid);
// jasmine.objectContaining vs expect.objectContaining
// restores
await receipt.destroy();