salix/modules/client/front/consumption/index.spec.js

68 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2020-06-10 11:35:41 +00:00
import './index.js';
import crudModel from 'core/mocks/crud-model';
2020-06-12 07:18:19 +00:00
describe('Client', () => {
describe('Component vnClientConsumption', () => {
2020-06-10 11:35:41 +00:00
let $scope;
let controller;
2020-06-12 07:18:19 +00:00
let $httpParamSerializer;
let $httpBackend;
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
beforeEach(ngModule('client'));
2020-06-10 11:35:41 +00:00
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, $rootScope, _$httpParamSerializer_, _$httpBackend_) => {
2020-06-10 11:35:41 +00:00
$scope = $rootScope.$new();
2020-06-12 07:18:19 +00:00
$httpParamSerializer = _$httpParamSerializer_;
$httpBackend = _$httpBackend_;
const $element = angular.element('<vn-client-consumption></vn-client-consumption');
controller = $componentController('vnClientConsumption', {$element, $scope});
2020-06-10 11:35:41 +00:00
controller.$.model = crudModel;
2020-06-12 07:18:19 +00:00
controller.client = {
id: 1101
2020-06-12 07:18:19 +00:00
};
2020-06-10 11:35:41 +00:00
}));
2020-06-12 07:18:19 +00:00
describe('showReport()', () => {
it('should call the window.open function', () => {
jest.spyOn(window, 'open').mockReturnThis();
2020-06-10 11:35:41 +00:00
2023-01-16 14:18:24 +00:00
const now = Date.vnNew();
2020-06-12 07:18:19 +00:00
controller.$.model.userParams = {
from: now,
to: now
};
2020-06-10 11:35:41 +00:00
2020-06-12 07:18:19 +00:00
controller.showReport();
2020-06-10 11:35:41 +00:00
2022-10-04 05:41:40 +00:00
const clientId = controller.client.id;
2020-06-12 07:18:19 +00:00
const expectedParams = {
2022-10-04 05:41:40 +00:00
recipientId: clientId,
2020-06-12 07:18:19 +00:00
from: now,
to: now
};
const serializedParams = $httpParamSerializer(expectedParams);
2022-10-04 05:41:40 +00:00
const expectedPath = `api/Clients/${clientId}/campaign-metrics-pdf?${serializedParams}`;
2020-06-10 11:35:41 +00:00
2022-10-04 05:41:40 +00:00
expect(window.open).toHaveBeenCalledWith(expectedPath);
2020-06-10 11:35:41 +00:00
});
});
2020-06-12 07:18:19 +00:00
describe('sendEmail()', () => {
it('should make a GET query sending the report', () => {
2023-01-16 14:18:24 +00:00
const now = Date.vnNew();
2020-06-12 07:18:19 +00:00
controller.$.model.userParams = {
from: now,
to: now
};
2022-10-04 05:41:40 +00:00
const clientId = controller.client.id;
const expectedPath = `Clients/${clientId}/campaign-metrics-email`;
2020-06-10 11:35:41 +00:00
2022-10-04 05:41:40 +00:00
$httpBackend.expect('POST', expectedPath).respond({});
2020-06-12 07:18:19 +00:00
controller.sendEmail();
$httpBackend.flush();
2020-06-10 11:35:41 +00:00
});
});
});
});