Updated unit test
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2021-04-30 14:27:50 +02:00
parent 07dbeaf515
commit 4d90006aa6
1 changed files with 40 additions and 2 deletions

View File

@ -7,6 +7,7 @@ describe('Supplier', () => {
let controller; let controller;
let $httpParamSerializer; let $httpParamSerializer;
let $httpBackend; let $httpBackend;
const supplierId = 2;
beforeEach(ngModule('supplier')); beforeEach(ngModule('supplier'));
@ -17,8 +18,9 @@ describe('Supplier', () => {
const $element = angular.element('<vn-supplier-consumption></vn-supplier-consumption'); const $element = angular.element('<vn-supplier-consumption></vn-supplier-consumption');
controller = $componentController('vnSupplierConsumption', {$element, $scope}); controller = $componentController('vnSupplierConsumption', {$element, $scope});
controller.$.model = crudModel; controller.$.model = crudModel;
controller.$params = {id: supplierId};
controller.supplier = { controller.supplier = {
id: 2 id: supplierId
}; };
})); }));
@ -47,7 +49,42 @@ describe('Supplier', () => {
}); });
describe('sendEmail()', () => { 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', () => { 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(); const now = new Date();
controller.$.model.userParams = { controller.$.model.userParams = {
from: now, from: now,
@ -55,11 +92,12 @@ describe('Supplier', () => {
}; };
const expectedParams = { const expectedParams = {
recipientId: 2, recipientId: 2,
recipient: 'batman@gothamcity.com',
from: now, from: now,
to: now to: now
}; };
const serializedParams = $httpParamSerializer(expectedParams); serializedParams = $httpParamSerializer(expectedParams);
const path = `email/supplier-campaign-metrics?${serializedParams}`; const path = `email/supplier-campaign-metrics?${serializedParams}`;
$httpBackend.expect('GET', path).respond({}); $httpBackend.expect('GET', path).respond({});