From 4d90006aa6b50f82a284ca25b40378c6352228c4 Mon Sep 17 00:00:00 2001 From: joan Date: Fri, 30 Apr 2021 14:27:50 +0200 Subject: [PATCH] Updated unit test --- .../supplier/front/consumption/index.spec.js | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/modules/supplier/front/consumption/index.spec.js b/modules/supplier/front/consumption/index.spec.js index 35eb6935c..d095a174b 100644 --- a/modules/supplier/front/consumption/index.spec.js +++ b/modules/supplier/front/consumption/index.spec.js @@ -7,6 +7,7 @@ describe('Supplier', () => { let controller; let $httpParamSerializer; let $httpBackend; + const supplierId = 2; beforeEach(ngModule('supplier')); @@ -17,8 +18,9 @@ describe('Supplier', () => { const $element = angular.element(' { }); describe('sendEmail()', () => { + it('should throw an error', () => { + jest.spyOn(controller.vnApp, 'showError'); + + const expectedParams = { + filter: { + where: { + supplierFk: supplierId, + email: {neq: null} + }, + limit: 1 + } + }; + const serializedParams = $httpParamSerializer(expectedParams); + $httpBackend.expectGET(`SupplierContacts?${serializedParams}`).respond({}); + controller.sendEmail(); + $httpBackend.flush(); + + 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', () => { + let serializedParams; + const params = { + filter: { + where: { + supplierFk: supplierId, + email: {neq: null} + }, + limit: 1 + } + }; + serializedParams = $httpParamSerializer(params); + $httpBackend.whenGET(`SupplierContacts?${serializedParams}`).respond([ + {id: 1, email: 'batman@gothamcity.com'} + ]); + const now = new Date(); controller.$.model.userParams = { from: now, @@ -55,11 +92,12 @@ describe('Supplier', () => { }; const expectedParams = { recipientId: 2, + recipient: 'batman@gothamcity.com', from: now, to: now }; - const serializedParams = $httpParamSerializer(expectedParams); + serializedParams = $httpParamSerializer(expectedParams); const path = `email/supplier-campaign-metrics?${serializedParams}`; $httpBackend.expect('GET', path).respond({});