From 65981099b62c914080a0e2ecdf9872d1f8be5830 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 26 Sep 2019 09:05:18 +0200 Subject: [PATCH] #1719 claim.detail cambiar descuento falla --- e2e/helpers/selectors.js | 2 +- .../methods/sale/specs/updateConcept.spec.js | 39 +++++++++++++++++++ .../ticket/back/methods/sale/updateConcept.js | 2 +- .../ticket-tracking/specs/changeState.spec.js | 2 +- .../ticket/specs/transferSales.spec.js | 4 +- .../ticket/specs/updateEditableTicket.spec.js | 2 +- 6 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 modules/ticket/back/methods/sale/specs/updateConcept.spec.js diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 41825e5ec..9be6bc0dd 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -309,7 +309,7 @@ export default { ticketSummary: { header: 'vn-ticket-summary > vn-card > div > h5', state: 'vn-ticket-summary vn-label-value[label="State"] > section > span', - route: 'vn-ticket-summary vn-label-value[label="Route"] > section > span', + route: 'vn-ticket-summary vn-label-value[label="Route"] > section > a', total: 'vn-ticket-summary vn-one.taxes > p:nth-child(3) > strong', sale: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr', firstSaleItemId: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span', diff --git a/modules/ticket/back/methods/sale/specs/updateConcept.spec.js b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js new file mode 100644 index 000000000..ab27bfdca --- /dev/null +++ b/modules/ticket/back/methods/sale/specs/updateConcept.spec.js @@ -0,0 +1,39 @@ +const app = require('vn-loopback/server/server'); + +describe('sale updateConcept()', () => { + const saleId = 1; + let originalSale; + + beforeAll(async done => { + originalSale = await app.models.Sale.findById(saleId); + + done(); + }); + + afterAll(async done => { + await originalSale.save(); + + done(); + }); + + + it('should throw if ID was undefined', async() => { + const newConcept = 'I am he new concept'; + + await app.models.Sale.updateConcept(undefined, newConcept) + .catch(response => { + expect(response).toEqual(new Error(`Model::findById requiere el argumento id`)); + error = response; + }); + + expect(error).toBeDefined(); + }); + + it('should update the sale concept', async() => { + const newConcept = 'I am the new concept'; + + let response = await app.models.Sale.updateConcept(saleId, newConcept); + + expect(response.concept).toEqual(newConcept); + }); +}); diff --git a/modules/ticket/back/methods/sale/updateConcept.js b/modules/ticket/back/methods/sale/updateConcept.js index 8bbe235b7..d95cf1202 100644 --- a/modules/ticket/back/methods/sale/updateConcept.js +++ b/modules/ticket/back/methods/sale/updateConcept.js @@ -25,7 +25,7 @@ module.exports = Self => { }); Self.updateConcept = async(id, newConcept) => { - let currentLine = await Self.app.models.Sale.findOne({where: {id: id}}); + let currentLine = await Self.app.models.Sale.findById(id); return await currentLine.updateAttributes({concept: newConcept}); }; diff --git a/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js b/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js index 74a1ebde0..3c6c51252 100644 --- a/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js +++ b/modules/ticket/back/methods/ticket-tracking/specs/changeState.spec.js @@ -17,7 +17,7 @@ describe('ticket changeState()', () => { done(); }); - it('should throw an error if the ticket is not editable and the user isnt production', async() => { + it('should throw if the ticket is not editable and the user isnt production', async() => { let ctx = {req: {accessToken: {userId: 18}}}; let params = {ticketFk: 2, stateFk: 3}; diff --git a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js index 6e8496f43..17996649e 100644 --- a/modules/ticket/back/methods/ticket/specs/transferSales.spec.js +++ b/modules/ticket/back/methods/ticket/specs/transferSales.spec.js @@ -8,11 +8,11 @@ describe('sale transferSales()', () => { done(); }); - it('should throw an error if the ticket is not editable', async() => { + it('should throw an error as the ticket is not editable', async() => { const ctx = {req: {accessToken: {userId: 101}}}; let error; - const currentTicketId = 10; + const currentTicketId = 1; const receiverTicketId = undefined; const sales = []; diff --git a/modules/ticket/back/methods/ticket/specs/updateEditableTicket.spec.js b/modules/ticket/back/methods/ticket/specs/updateEditableTicket.spec.js index e8007a0ce..16d8d1edb 100644 --- a/modules/ticket/back/methods/ticket/specs/updateEditableTicket.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateEditableTicket.spec.js @@ -13,7 +13,7 @@ describe('ticket updateEditableTicket()', () => { done(); }); - it('should throw an error if the ticket is not editable', async() => { + it('should now throw an error if the ticket is not editable', async() => { let error; let ctx = {req: {accessToken: {userId: 9}}};