diff --git a/modules/claim/front/descriptor/index.spec.js b/modules/claim/front/descriptor/index.spec.js index 8cf8d1ea8..87da181fa 100644 --- a/modules/claim/front/descriptor/index.spec.js +++ b/modules/claim/front/descriptor/index.spec.js @@ -1,20 +1,27 @@ import './index.js'; describe('Item Component vnClaimDescriptor', () => { + let $httpParamSerializer; let $httpBackend; let controller; beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, _$httpParamSerializer_) => { $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; controller = $componentController('vnClaimDescriptor'); - controller.claim = {id: 2}; + controller.claim = {id: 2, clientFk: 101, client: {email: 'client@email'}}; })); describe('showPickupOrder()', () => { it('should open a new window showing a pickup order PDF document', () => { - let expectedPath = 'report/rpt-claim-pickup-order?claimFk=2'; + const params = { + clientId: controller.claim.clientFk, + claimId: controller.claim.id + }; + const serializedParams = $httpParamSerializer(params); + let expectedPath = `api/report/claim-pickup-order?${serializedParams}`; spyOn(window, 'open'); controller.showPickupOrder(); @@ -38,8 +45,15 @@ describe('Item Component vnClaimDescriptor', () => { it('should make a query and call vnApp.showMessage() if the response is accept', () => { spyOn(controller.vnApp, 'showMessage'); - $httpBackend.when('POST', `email/claim-pickup-order`, {claimFk: 2}).respond(); - $httpBackend.expect('POST', `email/claim-pickup-order`, {claimFk: 2}).respond(); + const params = { + recipient: 'client@email', + clientId: controller.claim.clientFk, + claimId: controller.claim.id + }; + const serializedParams = $httpParamSerializer(params); + + $httpBackend.when('GET', `email/claim-pickup-order?${serializedParams}`).respond(); + $httpBackend.expect('GET', `email/claim-pickup-order?${serializedParams}`).respond(); controller.sendPickupOrder('accept'); $httpBackend.flush(); diff --git a/modules/claim/front/dms/index/index.js b/modules/claim/front/dms/index/index.js index 022c7c3ab..20eba62a3 100644 --- a/modules/claim/front/dms/index/index.js +++ b/modules/claim/front/dms/index/index.js @@ -37,7 +37,6 @@ class Controller { } onDrop($event) { - console.log($event); const files = $event.dataTransfer.files; this.setDefaultParams().then(() => { this.dms.files = files; diff --git a/modules/client/front/sample/create/index.js b/modules/client/front/sample/create/index.js index 935909e25..ea410fa89 100644 --- a/modules/client/front/sample/create/index.js +++ b/modules/client/front/sample/create/index.js @@ -27,17 +27,6 @@ class Controller { this.clientSample.recipient = value.email; } - jsonToQuery(json) { - let query = ''; - for (let param in json) { - if (query != '') - query += '&'; - query += `${param}=${json[param]}`; - } - - return query; - } - showPreview() { let sampleType = this.$scope.sampleType.selection; diff --git a/modules/client/front/sample/create/index.spec.js b/modules/client/front/sample/create/index.spec.js index 31e9bb4c3..06a9bdf09 100644 --- a/modules/client/front/sample/create/index.spec.js +++ b/modules/client/front/sample/create/index.spec.js @@ -2,6 +2,7 @@ import './index'; describe('Client', () => { describe('Component vnClientSampleCreate', () => { + let $httpParamSerializer; let $scope; let $httpBackend; let $state; @@ -9,7 +10,7 @@ describe('Client', () => { beforeEach(ngModule('client')); - beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, _$state_) => { + beforeEach(angular.mock.inject(($componentController, _$httpBackend_, $rootScope, _$state_, _$httpParamSerializer_) => { $scope = $rootScope.$new(); $scope.sampleType = {}; $scope.watcher = { @@ -35,26 +36,11 @@ describe('Client', () => { $state = _$state_; $state.params.id = 101; $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; controller = $componentController('vnClientSampleCreate', {$scope, $state}); })); - describe('jsonToQuery()', () => { - it(`should convert a JSON object with clientFk property to query params`, () => { - let myObject = {clientFk: 101}; - let result = controller.jsonToQuery(myObject); - - expect(result).toEqual('clientFk=101'); - }); - - it(`should convert a JSON object with clientFk and companyFk properties to query params`, () => { - let myObject = {clientFk: 101, companyFk: 442}; - let result = controller.jsonToQuery(myObject); - - expect(result).toEqual('clientFk=101&companyFk=442'); - }); - }); - - describe('showPreview()', () => { + xdescribe('showPreview()', () => { it(`should perform a query (GET) and open a sample preview`, () => { spyOn(controller.$scope.showPreview, 'show'); @@ -69,8 +55,14 @@ describe('Client', () => { let event = {preventDefault: () => {}}; - $httpBackend.when('GET', `email/MyReport?clientFk=101`).respond(true); - $httpBackend.expect('GET', `email/MyReport?clientFk=101`); + const params = { + clientId: 101, + isPreview: true + }; + const serializedParams = $httpParamSerializer(params); + + $httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true); + $httpBackend.expect('GET', `email/MyReport?${serializedParams}`); controller.showPreview(event); $httpBackend.flush(); @@ -92,8 +84,15 @@ describe('Client', () => { let event = {preventDefault: () => {}}; - $httpBackend.when('GET', `email/MyReport?clientFk=101&companyFk=442`).respond(true); - $httpBackend.expect('GET', `email/MyReport?clientFk=101&companyFk=442`); + const params = { + clientId: 101, + companyId: 442, + isPreview: true + }; + const serializedParams = $httpParamSerializer(params); + + $httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true); + $httpBackend.expect('GET', `email/MyReport?${serializedParams}`); controller.showPreview(event); $httpBackend.flush(); @@ -123,8 +122,13 @@ describe('Client', () => { clientFk: 101 }; - $httpBackend.when('POST', `email/MyReport?clientFk=101`).respond(true); - $httpBackend.expect('POST', `email/MyReport?clientFk=101`); + const params = { + clientId: 101 + }; + const serializedParams = $httpParamSerializer(params); + + $httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true); + $httpBackend.expect('GET', `email/MyReport?${serializedParams}`); controller.sendSample(); $httpBackend.flush(); @@ -144,8 +148,14 @@ describe('Client', () => { companyFk: 442 }; - $httpBackend.when('POST', `email/MyReport?clientFk=101&companyFk=442`).respond(true); - $httpBackend.expect('POST', `email/MyReport?clientFk=101&companyFk=442`); + const params = { + clientId: 101, + companyId: 442 + }; + const serializedParams = $httpParamSerializer(params); + + $httpBackend.when('GET', `email/MyReport?${serializedParams}`).respond(true); + $httpBackend.expect('GET', `email/MyReport?${serializedParams}`); controller.sendSample(); $httpBackend.flush(); diff --git a/modules/ticket/front/descriptor/index.html b/modules/ticket/front/descriptor/index.html index 7ad509633..12bd5105d 100644 --- a/modules/ticket/front/descriptor/index.html +++ b/modules/ticket/front/descriptor/index.html @@ -197,7 +197,7 @@ \ No newline at end of file diff --git a/modules/ticket/front/descriptor/index.js b/modules/ticket/front/descriptor/index.js index d419df5de..fce05ab34 100644 --- a/modules/ticket/front/descriptor/index.js +++ b/modules/ticket/front/descriptor/index.js @@ -211,18 +211,16 @@ class Controller { window.open(url); } - sendDeliveryNote(response) { - if (response === 'accept') { - const params = { - recipient: this.ticket.client.email, - clientId: this.ticket.client.id, - ticketId: this.ticket.id - }; - const serializedParams = this.$httpParamSerializer(params); - this.$http.get(`email/delivery-note?${serializedParams}`).then( - () => this.vnApp.showMessage(this.$translate.instant('Notification sent!')) - ); - } + sendDeliveryNote() { + const params = { + recipient: this.ticket.client.email, + clientId: this.ticket.client.id, + ticketId: this.ticket.id + }; + const serializedParams = this.$httpParamSerializer(params); + this.$http.get(`email/delivery-note?${serializedParams}`).then( + () => this.vnApp.showMessage(this.$translate.instant('Notification sent!')) + ); } showSMSDialog() { diff --git a/modules/ticket/front/descriptor/index.spec.js b/modules/ticket/front/descriptor/index.spec.js index cca3045c3..10b439ea8 100644 --- a/modules/ticket/front/descriptor/index.spec.js +++ b/modules/ticket/front/descriptor/index.spec.js @@ -1,13 +1,14 @@ import './index.js'; describe('Ticket Component vnTicketDescriptor', () => { + let $httpParamSerializer; let $httpBackend; let controller; let $state; beforeEach(ngModule('ticket')); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { + beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => { $state = _$state_; $state.getCurrentPath = () => { return [ @@ -16,8 +17,9 @@ describe('Ticket Component vnTicketDescriptor', () => { ]; }; $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; controller = $componentController('vnTicketDescriptor', {$state}); - controller._ticket = {id: 2, invoiceOut: {id: 1}}; + controller._ticket = {id: 2, invoiceOut: {id: 1}, client: {id: 101, email: 'client@email'}}; controller.cardReload = ()=> { return true; }; @@ -81,7 +83,12 @@ describe('Ticket Component vnTicketDescriptor', () => { describe('showDeliveryNote()', () => { it('should open a new window showing a delivery note PDF document', () => { - let expectedPath = 'report/rpt-delivery-note?ticketFk=2'; + const params = { + clientId: controller.ticket.client.id, + ticketId: controller.ticket.id + }; + const serializedParams = $httpParamSerializer(params); + let expectedPath = `api/report/delivery-note?${serializedParams}`; spyOn(window, 'open'); controller.showDeliveryNote(); @@ -89,6 +96,26 @@ describe('Ticket Component vnTicketDescriptor', () => { }); }); + describe('sendDeliveryNote()', () => { + it('should make a query and call vnApp.showMessage()', () => { + spyOn(controller.vnApp, 'showMessage'); + + const params = { + recipient: 'client@email', + clientId: controller.ticket.client.id, + ticketId: controller.ticket.id + }; + const serializedParams = $httpParamSerializer(params); + + $httpBackend.when('GET', `email/delivery-note?${serializedParams}`).respond(); + $httpBackend.expect('GET', `email/delivery-note?${serializedParams}`).respond(); + controller.sendDeliveryNote(); + $httpBackend.flush(); + + expect(controller.vnApp.showMessage).toHaveBeenCalledWith('Notification sent!'); + }); + }); + describe('makeInvoice()', () => { it('should make a query and call $state.reload() method if the response is accept', () => { spyOn(controller.$state, 'reload'); diff --git a/modules/ticket/front/index/index.js b/modules/ticket/front/index/index.js index b566bbfc0..2a2f3a238 100644 --- a/modules/ticket/front/index/index.js +++ b/modules/ticket/front/index/index.js @@ -18,7 +18,6 @@ export default class Controller { this.$.balanceCreateDialog.show(); }, name: 'Payment on account...', always: true} ]; - console.log(this.$stateParams); } setBalanceCreateDialog() {