From c8bad23621874429ece02e0a5ce9ade65a0b9ed6 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 4 Oct 2022 07:41:40 +0200 Subject: [PATCH] Tests --- modules/claim/front/descriptor/index.spec.js | 14 ++--- .../client/front/consumption/index.spec.js | 19 +++---- modules/client/front/notification/index.js | 2 +- .../client/front/notification/index.spec.js | 5 +- modules/client/front/sample/create/index.js | 52 ------------------- .../client/front/sample/create/index.spec.js | 10 ++-- modules/entry/front/descriptor/index.spec.js | 7 +-- .../front/descriptor-menu/index.spec.js | 21 ++------ .../supplier/front/consumption/index.spec.js | 10 ++-- .../front/descriptor-menu/index.spec.js | 24 ++++----- modules/ticket/front/index/index.js | 7 +-- modules/ticket/front/index/index.spec.js | 4 +- 12 files changed, 49 insertions(+), 126 deletions(-) diff --git a/modules/claim/front/descriptor/index.spec.js b/modules/claim/front/descriptor/index.spec.js index 669a73954..e6785d3d8 100644 --- a/modules/claim/front/descriptor/index.spec.js +++ b/modules/claim/front/descriptor/index.spec.js @@ -24,12 +24,13 @@ describe('Item Component vnClaimDescriptor', () => { window.open = jasmine.createSpy('open'); const params = { - recipientId: claim.clientFk, - claimId: claim.id + recipientId: claim.clientFk }; controller.showPickupOrder(); - expect(controller.vnReport.show).toHaveBeenCalledWith('claim-pickup-order', params); + const expectedPath = `Claims/${claim.id}/claim-pickup-pdf`; + + expect(controller.vnReport.show).toHaveBeenCalledWith(expectedPath, params); }); }); @@ -39,12 +40,13 @@ describe('Item Component vnClaimDescriptor', () => { const params = { recipient: claim.client.email, - recipientId: claim.clientFk, - claimId: claim.id + recipientId: claim.clientFk }; controller.sendPickupOrder(); - expect(controller.vnEmail.send).toHaveBeenCalledWith('claim-pickup-order', params); + const expectedPath = `Claims/${claim.id}/claim-pickup-email`; + + expect(controller.vnEmail.send).toHaveBeenCalledWith(expectedPath, params); }); }); diff --git a/modules/client/front/consumption/index.spec.js b/modules/client/front/consumption/index.spec.js index 16b764b56..33cbce58f 100644 --- a/modules/client/front/consumption/index.spec.js +++ b/modules/client/front/consumption/index.spec.js @@ -34,15 +34,16 @@ describe('Client', () => { controller.showReport(); + const clientId = controller.client.id; const expectedParams = { - recipientId: 1101, + recipientId: clientId, from: now, to: now }; const serializedParams = $httpParamSerializer(expectedParams); - const path = `api/report/campaign-metrics?${serializedParams}`; + const expectedPath = `api/Clients/${clientId}/campaign-metrics-pdf?${serializedParams}`; - expect(window.open).toHaveBeenCalledWith(path); + expect(window.open).toHaveBeenCalledWith(expectedPath); }); }); @@ -53,16 +54,10 @@ describe('Client', () => { from: now, to: now }; - const expectedParams = { - recipientId: 1101, - from: now, - to: now - }; + const clientId = controller.client.id; + const expectedPath = `Clients/${clientId}/campaign-metrics-email`; - const serializedParams = $httpParamSerializer(expectedParams); - const path = `email/campaign-metrics?${serializedParams}`; - - $httpBackend.expect('GET', path).respond({}); + $httpBackend.expect('POST', expectedPath).respond({}); controller.sendEmail(); $httpBackend.flush(); }); diff --git a/modules/client/front/notification/index.js b/modules/client/front/notification/index.js index d61c8f771..e70af12b2 100644 --- a/modules/client/front/notification/index.js +++ b/modules/client/front/notification/index.js @@ -85,7 +85,7 @@ export default class Controller extends Section { this.$http.post('ClientConsumptionQueues', {params}) .then(() => this.$.filters.hide()) - .then(() => this.vnApp.showSuccess(this.$t('Notifications queued'))); + .then(() => this.vnApp.showSuccess(this.$t('Notifications sent!'))); } exprBuilder(param, value) { diff --git a/modules/client/front/notification/index.spec.js b/modules/client/front/notification/index.spec.js index 8847357f7..ea082c403 100644 --- a/modules/client/front/notification/index.spec.js +++ b/modules/client/front/notification/index.spec.js @@ -61,7 +61,6 @@ describe('Client notification', () => { controller.$.filters = {hide: () => {}}; controller.campaign = { - id: 1, from: new Date(), to: new Date() }; @@ -71,10 +70,10 @@ describe('Client notification', () => { data[1].$checked = true; const params = Object.assign({ - clientIds: [1101, 1102] + clients: [1101, 1102] }, controller.campaign); - $httpBackend.expect('POST', `schedule/consumption`, params).respond(200, params); + $httpBackend.expect('POST', `ClientConsumptionQueues`, {params}).respond(200, params); controller.onSendClientConsumption(); $httpBackend.flush(); diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index df0211d06..4e6256ee6 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -40,58 +40,6 @@ class Controller extends Section { this.$.watcher.realSubmit().then(() => this.send()); } - // showPreview() { - // this.send(true, res => { - // this.$.showPreview.show(); - // const dialog = document.body.querySelector('div.vn-dialog'); - // const body = dialog.querySelector('tpl-body'); - // const scroll = dialog.querySelector('div:first-child'); - - // body.innerHTML = res.data; - // scroll.scrollTop = 0; - // }); - // } - - // sendSample() { - // this.send(false, () => { - // this.vnApp.showSuccess(this.$t('Notification sent!')); - // this.$state.go('client.card.sample.index'); - // }); - // } - - // send(isPreview, cb) { - // const sampleType = this.$.sampleType.selection; - // const params = { - // recipientId: this.$params.id, - // recipient: this.clientSample.recipient, - // replyTo: this.clientSample.replyTo - // }; - - // if (!params.recipient) - // return this.vnApp.showError(this.$t('Email cannot be blank')); - - // if (!sampleType) - // return this.vnApp.showError(this.$t('Choose a sample')); - - // if (sampleType.hasCompany && !this.clientSample.companyFk) - // return this.vnApp.showError(this.$t('Choose a company')); - - // if (sampleType.hasCompany) - // params.companyId = this.clientSample.companyFk; - - // if (sampleType.datepickerEnabled && !this.clientSample.from) - // return this.vnApp.showError(this.$t('Choose a date')); - - // if (sampleType.datepickerEnabled) - // params.from = this.clientSample.from; - - // let query = `email/${sampleType.code}`; - // if (isPreview) - // query = `email/${sampleType.code}/preview`; - - // this.$http.get(query, {params}).then(cb); - // } - validateParams(params) { const sampleType = this.$.sampleType.selection; diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index 781025fd2..6e9da54ef 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -40,6 +40,7 @@ describe('Client', () => { $httpParamSerializer = _$httpParamSerializer_; $element = angular.element(''); controller = $componentController('vnClientSampleCreate', {$element, $scope}); + controller.client = {id: 1101}; const element = document.createElement('div'); document.body.querySelector = () => { return { @@ -51,11 +52,11 @@ describe('Client', () => { })); describe('onSubmit()', () => { - it(`should call sendSample() method`, () => { - jest.spyOn(controller, 'sendSample'); + it(`should call send() method`, () => { + jest.spyOn(controller, 'send'); controller.onSubmit(); - expect(controller.sendSample).toHaveBeenCalledWith(); + expect(controller.send).toHaveBeenCalledWith(); }); }); @@ -65,7 +66,8 @@ describe('Client', () => { controller.$.sampleType.selection = { hasCompany: false, - code: 'MyReport' + code: 'MyReport', + model: 'Clients' }; controller.clientSample = { recipientId: 1101 diff --git a/modules/entry/front/descriptor/index.spec.js b/modules/entry/front/descriptor/index.spec.js index 84defea3b..714bb9f3c 100644 --- a/modules/entry/front/descriptor/index.spec.js +++ b/modules/entry/front/descriptor/index.spec.js @@ -17,13 +17,10 @@ describe('Entry Component vnEntryDescriptor', () => { jest.spyOn(controller.vnReport, 'show'); window.open = jasmine.createSpy('open'); - const params = { - clientId: controller.vnConfig.storage.currentUserWorkerId, - entryId: entry.id - }; controller.showEntryReport(); + const expectedPath = `Entries/${entry.id}/entry-order-pdf`; - expect(controller.vnReport.show).toHaveBeenCalledWith('entry-order', params); + expect(controller.vnReport.show).toHaveBeenCalledWith(expectedPath); }); }); diff --git a/modules/invoiceOut/front/descriptor-menu/index.spec.js b/modules/invoiceOut/front/descriptor-menu/index.spec.js index da7c87894..d2ccfa117 100644 --- a/modules/invoiceOut/front/descriptor-menu/index.spec.js +++ b/modules/invoiceOut/front/descriptor-menu/index.spec.js @@ -41,11 +41,10 @@ describe('vnInvoiceOutDescriptorMenu', () => { jest.spyOn(window, 'open').mockReturnThis(); const expectedParams = { - recipientId: invoiceOut.client.id, - refFk: invoiceOut.ref + recipientId: invoiceOut.client.id }; const serializedParams = $httpParamSerializer(expectedParams); - const expectedPath = `api/csv/invoice/download?${serializedParams}`; + const expectedPath = `api/InvoiceOuts/${invoiceOut.ref}/invoice-csv?${serializedParams}`; controller.showCsvInvoice(); expect(window.open).toHaveBeenCalledWith(expectedPath); @@ -84,14 +83,8 @@ describe('vnInvoiceOutDescriptorMenu', () => { jest.spyOn(controller.vnApp, 'showMessage'); const $data = {email: 'brucebanner@gothamcity.com'}; - const expectedParams = { - recipient: $data.email, - recipientId: invoiceOut.client.id, - refFk: invoiceOut.ref - }; - const serializedParams = $httpParamSerializer(expectedParams); - $httpBackend.expectGET(`email/invoice?${serializedParams}`).respond(); + $httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.ref}/invoice-email`).respond(); controller.sendPdfInvoice($data); $httpBackend.flush(); @@ -104,14 +97,8 @@ describe('vnInvoiceOutDescriptorMenu', () => { jest.spyOn(controller.vnApp, 'showMessage'); const $data = {email: 'brucebanner@gothamcity.com'}; - const expectedParams = { - recipient: $data.email, - recipientId: invoiceOut.client.id, - refFk: invoiceOut.ref - }; - const serializedParams = $httpParamSerializer(expectedParams); - $httpBackend.expectGET(`csv/invoice/send?${serializedParams}`).respond(); + $httpBackend.expectPOST(`InvoiceOuts/${invoiceOut.ref}/invoice-csv-email`).respond(); controller.sendCsvInvoice($data); $httpBackend.flush(); diff --git a/modules/supplier/front/consumption/index.spec.js b/modules/supplier/front/consumption/index.spec.js index d095a174b..ebf19ccec 100644 --- a/modules/supplier/front/consumption/index.spec.js +++ b/modules/supplier/front/consumption/index.spec.js @@ -42,7 +42,7 @@ describe('Supplier', () => { to: now }; const serializedParams = $httpParamSerializer(expectedParams); - const path = `api/report/supplier-campaign-metrics?${serializedParams}`; + const path = `api/Suppliers/${supplierId}/campaign-metrics-pdf?${serializedParams}`; expect(window.open).toHaveBeenCalledWith(path); }); @@ -66,7 +66,8 @@ describe('Supplier', () => { controller.sendEmail(); $httpBackend.flush(); - expect(controller.vnApp.showError).toHaveBeenCalledWith(`This supplier doesn't have a contact with an email address`); + expect(controller.vnApp.showError) + .toHaveBeenCalledWith(`This supplier doesn't have a contact with an email address`); }); it('should make a GET query sending the report', () => { @@ -91,16 +92,15 @@ describe('Supplier', () => { to: now }; const expectedParams = { - recipientId: 2, recipient: 'batman@gothamcity.com', from: now, to: now }; serializedParams = $httpParamSerializer(expectedParams); - const path = `email/supplier-campaign-metrics?${serializedParams}`; + const path = `Suppliers/${supplierId}/campaign-metrics-email`; - $httpBackend.expect('GET', path).respond({}); + $httpBackend.expect('POST', path).respond({}); controller.sendEmail(); $httpBackend.flush(); }); diff --git a/modules/ticket/front/descriptor-menu/index.spec.js b/modules/ticket/front/descriptor-menu/index.spec.js index 2d08a7846..091b9a2cf 100644 --- a/modules/ticket/front/descriptor-menu/index.spec.js +++ b/modules/ticket/front/descriptor-menu/index.spec.js @@ -124,12 +124,11 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { jest.spyOn(window, 'open').mockReturnThis(); const type = 'deliveryNote'; const expectedParams = { - ticketId: ticket.id, recipientId: ticket.client.id, type: type }; const serializedParams = $httpParamSerializer(expectedParams); - const expectedPath = `api/report/delivery-note?${serializedParams}`; + const expectedPath = `api/tickets/${ticket.id}/delivery-note-pdf?${serializedParams}`; controller.showPdfDeliveryNote(type); expect(window.open).toHaveBeenCalledWith(expectedPath); @@ -143,12 +142,13 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { const $data = {email: 'brucebanner@gothamcity.com'}; const params = { recipient: $data.email, - recipientId: ticket.client.id, - ticketId: ticket.id + recipientId: ticket.client.id }; controller.sendPdfDeliveryNote($data); - expect(controller.vnEmail.send).toHaveBeenCalledWith('delivery-note', params); + const expectedPath = `tickets/${ticket.id}/delivery-note-email`; + + expect(controller.vnEmail.send).toHaveBeenCalledWith(expectedPath, params); }); }); @@ -157,11 +157,10 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { jest.spyOn(window, 'open').mockReturnThis(); const expectedParams = { - ticketId: ticket.id, recipientId: ticket.client.id }; const serializedParams = $httpParamSerializer(expectedParams); - const expectedPath = `api/csv/delivery-note/download?${serializedParams}`; + const expectedPath = `api/tickets/${ticket.id}/delivery-note-csv?${serializedParams}`; controller.showCsvDeliveryNote(); expect(window.open).toHaveBeenCalledWith(expectedPath); @@ -170,21 +169,18 @@ describe('Ticket Component vnTicketDescriptorMenu', () => { describe('sendCsvDeliveryNote()', () => { it('should make a query to the csv delivery-note send endpoint and show a message snackbar', () => { - jest.spyOn(controller.vnApp, 'showMessage'); + jest.spyOn(controller.vnEmail, 'send'); const $data = {email: 'brucebanner@gothamcity.com'}; const expectedParams = { - ticketId: ticket.id, recipient: $data.email, recipientId: ticket.client.id, }; - const serializedParams = $httpParamSerializer(expectedParams); - - $httpBackend.expectGET(`csv/delivery-note/send?${serializedParams}`).respond(); controller.sendCsvDeliveryNote($data); - $httpBackend.flush(); - expect(controller.vnApp.showMessage).toHaveBeenCalled(); + const expectedPath = `tickets/${ticket.id}/delivery-note-csv-email`; + + expect(controller.vnEmail.send).toHaveBeenCalledWith(expectedPath, expectedParams); }); }); diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index 2df4de0a5..3039a2a03 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -29,11 +29,8 @@ export default class Controller extends Section { } openDeliveryNotes(ids) { - for (let id of ids) { - this.vnReport.show('delivery-note', { - ticketId: id, - }); - } + for (let id of ids) + this.vnReport.show(`Tickets/${id}/delivery-note-pdf`); } openBalanceDialog() { diff --git a/modules/ticket/front/index/index.spec.js b/modules/ticket/front/index/index.spec.js index b966ca8c4..84473686c 100644 --- a/modules/ticket/front/index/index.spec.js +++ b/modules/ticket/front/index/index.spec.js @@ -96,8 +96,8 @@ describe('Component vnTicketIndex', () => { controller.setDelivered(); $httpBackend.flush(); - expect($window.open).toHaveBeenCalledWith(`api/report/delivery-note?ticketId=${tickets[1].id}`); - expect($window.open).toHaveBeenCalledWith(`api/report/delivery-note?ticketId=${tickets[2].id}`); + expect($window.open).toHaveBeenCalledWith(`Tickets/${tickets[1].id}/delivery-note-pdf`); + expect($window.open).toHaveBeenCalledWith(`Tickets/${tickets[2].id}/delivery-note-pdf`); }); });