From 7abceb856429fc1c06aac4b259c3351cadd12bcb Mon Sep 17 00:00:00 2001 From: vicent Date: Tue, 26 Apr 2022 13:08:06 +0200 Subject: [PATCH] refactor: add frontTest --- .../invoiceOut/front/descriptor-menu/index.js | 42 +++++++-------- .../front/descriptor-menu/index.spec.js | 29 +++++++++++ modules/ticket/front/descriptor-menu/index.js | 32 ++++++------ .../front/descriptor-menu/index.spec.js | 51 +++---------------- 4 files changed, 75 insertions(+), 79 deletions(-) diff --git a/modules/invoiceOut/front/descriptor-menu/index.js b/modules/invoiceOut/front/descriptor-menu/index.js index 92a69c894b..3d6dc54fee 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.js +++ b/modules/invoiceOut/front/descriptor-menu/index.js @@ -117,35 +117,37 @@ class Controller extends Section { }); } - async refundInvoiceOut() { + refundInvoiceOut() { let filter = { where: {refFk: this.invoiceOut.ref} }; - await this.$http.get('Tickets', {filter}) + this.$http.get('Tickets', {filter}) .then(res => { this.tickets = res.data; this.ticketsIds = []; for (let ticket of this.tickets) this.ticketsIds.push(ticket.id); + + filter = { + where: {ticketFk: {inq: this.ticketsIds}} + }; + this.$http.get('Sales', {filter}) + .then(res => { + this.sales = res.data; + this.$http.get('TicketServices', {filter}) + .then(res => { + this.services = res.data; + const params = { + sales: this.sales, + services: this.services + }; + const query = `Sales/refund`; + return this.$http.post(query, params).then(res => { + this.$state.go('ticket.card.sale', {id: res.data}); + }); + }); + }); }); - - filter = { - where: {ticketFk: {inq: this.ticketsIds}} - }; - await this.$http.get('Sales', {filter}) - .then(res => this.sales = res.data); - - await this.$http.get('TicketServices', {filter}) - .then(res => this.services = res.data); - - const params = { - sales: this.sales, - services: this.services - }; - const query = `Sales/refund`; - return this.$http.post(query, params).then(res => { - this.$state.go('ticket.card.sale', {id: res.data}); - }); } } diff --git a/modules/invoiceOut/front/descriptor-menu/index.spec.js b/modules/invoiceOut/front/descriptor-menu/index.spec.js index fced12e0d5..4abb195450 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.spec.js +++ b/modules/invoiceOut/front/descriptor-menu/index.spec.js @@ -122,4 +122,33 @@ describe('vnInvoiceOutDescriptorMenu', () => { expect(controller.vnApp.showMessage).toHaveBeenCalled(); }); }); + + describe('refundInvoiceOut()', () => { + it('should make a query and go to ticket.card.sale', () => { + controller.$state.go = jest.fn(); + + const invoiceOut = { + id: 1, + ref: 'T1111111' + }; + controller.invoiceOut = invoiceOut; + const tickets = [{id: 1}]; + const sales = [{id: 1}]; + const services = [{id: 2}]; + + $httpBackend.expectGET(`Tickets`).respond(tickets); + $httpBackend.expectGET(`Sales`).respond(sales); + $httpBackend.expectGET(`TicketServices`).respond(services); + + const expectedParams = { + sales: sales, + services: services + }; + $httpBackend.expectPOST(`Sales/refund`, expectedParams).respond(); + controller.refundInvoiceOut(); + $httpBackend.flush(); + + expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: undefined}); + }); + }); }); diff --git a/modules/ticket/front/descriptor-menu/index.js b/modules/ticket/front/descriptor-menu/index.js index a539901c53..3f8edc6081 100644 --- a/modules/ticket/front/descriptor-menu/index.js +++ b/modules/ticket/front/descriptor-menu/index.js @@ -273,24 +273,26 @@ class Controller extends Section { .then(() => this.vnApp.showSuccess(this.$t('Data saved!'))); } - async refund() { + refund() { const filter = { where: {ticketFk: this.id} }; - await this.$http.get('Sales', {filter}) - .then(res => this.sales = res.data); - - await this.$http.get('TicketServices', {filter}) - .then(res => this.services = res.data); - - const params = { - sales: this.sales, - services: this.services - }; - const query = `Sales/refund`; - return this.$http.post(query, params).then(res => { - this.$state.go('ticket.card.sale', {id: res.data}); - }); + this.$http.get('Sales', {filter}) + .then(res => { + this.sales = res.data; + this.$http.get('TicketServices', {filter}) + .then(res => { + this.services = res.data; + const params = { + sales: this.sales, + services: this.services + }; + const query = `Sales/refund`; + return this.$http.post(query, params).then(res => { + this.$state.go('ticket.card.sale', {id: res.data}); + }); + }); + }); } } diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index 8e8880e3e5..13f5292c56 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -264,51 +264,14 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { describe('refund()', () => { it('should make a query and go to ticket.card.sale', () => { - jest.spyOn(controller.$state, 'go').mockReturnValue(); + controller.$state.go = jest.fn(); - const sales = [{ - id: 13, - concept: 'Melee weapon combat fist 15cm', - quantity: 10, - price: 7.08, - discount: 0, - reserved: false, - isPicked: 0, - created: '2022-04-21T22:00:00.000Z', - itemFk: 2, - ticketFk: 8 - }, - { - id: 14, - concept: 'Ranged weapon longbow 2m', - quantity: 2, - price: 103.49, - discount: 0, - reserved: false, - isPicked: 0, - created: '2022-04-21T22:00:00.000Z', - itemFk: 1, - ticketFk: 8 - }]; + controller._id = ticket.id; + const sales = [{id: 1}]; + const services = [{id: 2}]; - const services = [{ - id: 5, - ticketFk: 8, - description: 'Documentos', - quantity: 1, - price: 2, - taxClassFk: 1, - ticketServiceTypeFk: 1 - }]; - - const filter = { - where: {ticketFk: ticket.id} - }; - const serializedParams = $httpParamSerializer({filter}); - console.log(serializedParams); - - $httpBackend.expect('GET', `Sales?${serializedParams}`).respond(); - $httpBackend.expectGET(`TicketServices?filter=${serializedParams}`).respond(); + $httpBackend.expectGET(`Sales`).respond(sales); + $httpBackend.expectGET(`TicketServices`).respond(services); const expectedParams = { sales: sales, @@ -318,7 +281,7 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { controller.refund(); $httpBackend.flush(); - expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: {ticketId: ticket.id}}); + expect(controller.$state.go).toHaveBeenCalledWith('ticket.card.sale', {id: undefined}); }); });