Updated unit test
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
07dbeaf515
commit
4d90006aa6
|
@ -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('<vn-supplier-consumption></vn-supplier-consumption');
|
||||
controller = $componentController('vnSupplierConsumption', {$element, $scope});
|
||||
controller.$.model = crudModel;
|
||||
controller.$params = {id: supplierId};
|
||||
controller.supplier = {
|
||||
id: 2
|
||||
id: supplierId
|
||||
};
|
||||
}));
|
||||
|
||||
|
@ -47,7 +49,42 @@ describe('Supplier', () => {
|
|||
});
|
||||
|
||||
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({});
|
||||
|
|
Loading…
Reference in New Issue