From fb2545994cbc3c29a8261f5b275d4149d7a919ac Mon Sep 17 00:00:00 2001 From: Bernat Date: Thu, 27 Jun 2019 12:38:30 +0200 Subject: [PATCH] Refactor #1563 fixtures item --- db/dump/fixtures.sql | 36 +++++++++++-------- .../01_descriptor.spec.js | 13 ++++--- .../back/methods/client/specs/getCard.spec.js | 2 +- .../back/methods/client/specs/getDebt.spec.js | 2 +- .../back/methods/client/specs/summary.spec.js | 2 +- .../methods/invoiceOut/specs/book.spec.js | 10 ++++-- .../methods/invoiceOut/specs/filter.spec.js | 8 ++--- 7 files changed, 43 insertions(+), 30 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 231bdf819..00c749600 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -383,11 +383,11 @@ INSERT INTO `vn`.`company`(`id`, `code`, `supplierAccountFk`, `workerManagerFk`, INSERT INTO `vn`.`invoiceOut`(`id`, `serial`, `amount`, `issued`,`clientFk`, `created`, `companyFk`, `dued`, `booked`, `bankFk`, `pdf`) VALUES - (1, 'T', 156.09, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), 101, CURDATE(), 442, DATE_ADD(CURDATE(), INTERVAL -2 MONTH), CURDATE(), 1, 1), - (2, 'T', 208.35, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 102, CURDATE(), 442, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), CURDATE(), 1, 1), - (3, 'T', 20.02, CURDATE(), 103, CURDATE(), 442, CURDATE(), NULL, 1, 1), - (4, 'T', 20.02, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), 103, CURDATE(), 442, DATE_ADD(CURDATE(), INTERVAL +1 MONTH), NULL, 1, 1), - (5, 'A', 20.22, DATE_ADD(CURDATE(), INTERVAL +2 MONTH), 103, CURDATE(), 442, DATE_ADD(CURDATE(), INTERVAL +2 MONTH), NULL, 1, 1); + (1, 'T', 1014.24, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 101, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 442, DATE_ADD(CURDATE(), INTERVAL -1 MONTH), DATE_ADD(CURDATE(), INTERVAL -1 MONTH), 1, 1), + (2, 'T', 121.36, CURDATE(), 102, CURDATE(), 442, CURDATE(), CURDATE(), 1, 1), + (3, 'T', 8.88, CURDATE(), 103, CURDATE(), 442, CURDATE(), CURDATE(), 1, 1), + (4, 'T', 8.88, CURDATE(), 103, CURDATE(), 442, CURDATE(), CURDATE(), 1, 1), + (5, 'A', 8.88, CURDATE(), 103, CURDATE(), 442, CURDATE(), CURDATE(), 1, 1); UPDATE `vn`.`invoiceOut` SET ref = 'T1111111' WHERE id = 1; UPDATE `vn`.`invoiceOut` SET ref = 'T2222222' WHERE id = 2; @@ -397,16 +397,22 @@ UPDATE `vn`.`invoiceOut` SET ref = 'A1111111' WHERE id = 5; INSERT INTO `vn`.`invoiceOutTax` (`invoiceOutFk`, `taxableBase`, `vat`, `pgcFk`) VALUES - (1, 100, 10, 4722000010), - (1, 200, 21, 4722000021), - (2, 100, 10, 4722000010), - (2, 200, 21, 4722000021), - (3, 100, 10, 4722000010), - (3, 200, 21, 4722000021), - (4, 100, 10, 4722000010), - (4, 200, 21, 4722000021), - (5, 100, 10, 4722000010), - (5, 200, 21, 4722000021); + (1, 895.76, 89.58, 4722000010), + (1, 33.80, 7.10, 4722000021), + (2, 110.33, 11.03, 4770000010), + (3, 8.07, 0.81, 4770000010), + (4, 8.07, 0.81, 4770000010), + (5, 8.07, 0.81, 4770000010); + +INSERT INTO `vn`.`invoiceOutExpence`(`id`, `invoiceOutFk`, `amount` `expenceFk` `created`) + VALUES + (1, 1, 813.06, 2000000000, CURDATE()), + (2, 1, 33.80, 4751000000, CURDATE()), + (3, 1, 70.70, 6210000567, CURDATE()), + (4, 2, 110.33, 2000000000, CURDATE()), + (5, 3, 8.07, 2000000000, CURDATE()), + (6, 4, 8.07, 2000000000, CURDATE()), + (7, 5, 8.07, 2000000000, CURDATE()); INSERT INTO `vn`.`taxArea` (`code`, `claveOperacionFactura`, `CodigoTransaccion`) VALUES diff --git a/e2e/paths/09-invoice-out-module/01_descriptor.spec.js b/e2e/paths/09-invoice-out-module/01_descriptor.spec.js index e1f408409..a00d6387d 100644 --- a/e2e/paths/09-invoice-out-module/01_descriptor.spec.js +++ b/e2e/paths/09-invoice-out-module/01_descriptor.spec.js @@ -3,6 +3,7 @@ import createNightmare from '../../helpers/nightmare'; describe('InvoiceOut descriptor path', () => { const nightmare = createNightmare(); + let bookedDate; describe('as Administrative', () => { beforeAll(() => { @@ -113,21 +114,23 @@ describe('InvoiceOut descriptor path', () => { it(`should search and access to the invoiceOut summary`, async() => { const url = await nightmare - .accessToSearchResult('A1111111') + .accessToSearchResult('T1111111') .waitForURL('/summary') .parsedUrl(); expect(url.hash).toContain('/summary'); }); - it(`should check the invoiceOut isn't booked yet in the summary data`, async() => { + it(`should check the invoiceOut is booked in the summary data`, async() => { const result = await nightmare .waitToGetProperty(selectors.invoiceOutSummary.bookedLabel, 'innerText'); - expect(result).toEqual('-'); + bookedDate = result; + + expect(result.length).toBeGreaterThan(1); }); - it('should book the invoiceOut using the descriptor more menu', async() => { + it('should re-book the invoiceOut using the descriptor more menu', async() => { const result = await nightmare .waitToClick(selectors.invoiceOutDescriptor.moreMenu) .waitToClick(selectors.invoiceOutDescriptor.moreMenuBookInvoiceOut) @@ -141,7 +144,7 @@ describe('InvoiceOut descriptor path', () => { const result = await nightmare .waitToGetProperty(selectors.invoiceOutSummary.bookedLabel, 'innerText'); - expect(result.length).toBeGreaterThan(1); + expect(result).not.toEqual(bookedDate); }); }); diff --git a/modules/client/back/methods/client/specs/getCard.spec.js b/modules/client/back/methods/client/specs/getCard.spec.js index e6028caee..85cceaf6b 100644 --- a/modules/client/back/methods/client/specs/getCard.spec.js +++ b/modules/client/back/methods/client/specs/getCard.spec.js @@ -7,6 +7,6 @@ describe('Client get', () => { expect(result.id).toEqual(101); expect(result.name).toEqual('Bruce Wayne'); - expect(result.debt).toEqual(79.05); + expect(result.debt).toEqual(937.2); }); }); diff --git a/modules/client/back/methods/client/specs/getDebt.spec.js b/modules/client/back/methods/client/specs/getDebt.spec.js index 49b7fb501..1572545a7 100644 --- a/modules/client/back/methods/client/specs/getDebt.spec.js +++ b/modules/client/back/methods/client/specs/getDebt.spec.js @@ -4,7 +4,7 @@ describe('client getDebt()', () => { it('should return the client debt', async() => { let result = await app.models.Client.getDebt(101); - expect(result.debt).toEqual(79.05); + expect(result.debt).toEqual(937.2); }); }); diff --git a/modules/client/back/methods/client/specs/summary.spec.js b/modules/client/back/methods/client/specs/summary.spec.js index bbd0c994e..154dbe1e7 100644 --- a/modules/client/back/methods/client/specs/summary.spec.js +++ b/modules/client/back/methods/client/specs/summary.spec.js @@ -17,7 +17,7 @@ describe('client summary()', () => { it('should return a summary object containing debt', async() => { let result = await app.models.Client.summary(101); - expect(result.debt.debt).toEqual(79.05); + expect(result.debt.debt).toEqual(937.2); }); it('should return a summary object containing averageInvoiced', async() => { diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js index 383e952b6..345e29125 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/book.spec.js @@ -1,10 +1,12 @@ const app = require('vn-loopback/server/server'); describe('invoiceOut book()', () => { - const invoiceOutId = 5; + const invoiceOutId = 1; let invoiceOutRef; let OriginalInvoiceOut; let updatedInvoiceOut; + let bookedDate; + afterAll(async done => { updatedInvoiceOut.updateAttributes({booked: OriginalInvoiceOut.booked, hasPdf: OriginalInvoiceOut.hasPdf}); @@ -14,7 +16,9 @@ describe('invoiceOut book()', () => { it('should check that invoice out booked is untainted', async() => { const invoiceOut = await app.models.InvoiceOut.findById(invoiceOutId); - expect(invoiceOut.booked).toBeNull(); + bookedDate = invoiceOut.booked; + + expect(invoiceOut.booked).toBeDefined(); expect(invoiceOut.hasPdf).toBeTruthy(); }); @@ -26,7 +30,7 @@ describe('invoiceOut book()', () => { updatedInvoiceOut = await app.models.InvoiceOut.findById(invoiceOutId); - expect(updatedInvoiceOut.booked).toEqual(jasmine.any(Object)); + expect(updatedInvoiceOut.booked).not.toEqual(bookedDate); expect(updatedInvoiceOut.hasPdf).toBeFalsy(); }); }); diff --git a/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js b/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js index c3a009dde..09f67eced 100644 --- a/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js +++ b/modules/invoiceOut/back/methods/invoiceOut/specs/filter.spec.js @@ -45,7 +45,7 @@ describe('InvoiceOut filter()', () => { it('should return the invoice out matching amount', async() => { let ctx = { args: { - amount: 208.35, + amount: 121.36, } }; @@ -58,14 +58,14 @@ describe('InvoiceOut filter()', () => { it('should return the invoice out matching min and max', async() => { let ctx = { args: { - min: 100, - max: 300, + min: 0, + max: 100, } }; let result = await app.models.InvoiceOut.filter(ctx); - expect(result.length).toEqual(2); + expect(result.length).toEqual(3); }); // #1428 cuadrar formato de horas