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 = {
|
2021-06-23 11:24:23 +00:00
|
|
|
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
|
|
|
|
2022-03-30 10:45:01 +00:00
|
|
|
const now = new Date('2022-01-19');
|
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
|
|
|
|
2020-06-12 07:18:19 +00:00
|
|
|
const expectedParams = {
|
2021-06-23 11:24:23 +00:00
|
|
|
recipientId: 1101,
|
2020-06-12 07:18:19 +00:00
|
|
|
from: now,
|
|
|
|
to: now
|
|
|
|
};
|
|
|
|
const serializedParams = $httpParamSerializer(expectedParams);
|
|
|
|
const path = `api/report/campaign-metrics?${serializedParams}`;
|
2020-06-10 11:35:41 +00:00
|
|
|
|
2020-06-12 07:18:19 +00:00
|
|
|
expect(window.open).toHaveBeenCalledWith(path);
|
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', () => {
|
2022-03-30 10:45:01 +00:00
|
|
|
const now = new Date('2022-01-19');
|
2020-06-12 07:18:19 +00:00
|
|
|
controller.$.model.userParams = {
|
|
|
|
from: now,
|
|
|
|
to: now
|
|
|
|
};
|
|
|
|
const expectedParams = {
|
2021-06-23 11:24:23 +00:00
|
|
|
recipientId: 1101,
|
2020-06-12 07:18:19 +00:00
|
|
|
from: now,
|
|
|
|
to: now
|
|
|
|
};
|
2020-06-10 11:35:41 +00:00
|
|
|
|
2020-06-12 07:18:19 +00:00
|
|
|
const serializedParams = $httpParamSerializer(expectedParams);
|
|
|
|
const path = `email/campaign-metrics?${serializedParams}`;
|
2020-06-10 11:35:41 +00:00
|
|
|
|
2020-06-12 07:18:19 +00:00
|
|
|
$httpBackend.expect('GET', path).respond({});
|
|
|
|
controller.sendEmail();
|
|
|
|
$httpBackend.flush();
|
2020-06-10 11:35:41 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|