Updated unit tests
This commit is contained in:
parent
245b32a47f
commit
9e3186c0df
|
@ -2,15 +2,11 @@ const app = require('vn-loopback/server/server');
|
|||
|
||||
describe('campaign upcoming()', () => {
|
||||
it('should return the upcoming campaign but from the last year', async() => {
|
||||
let response = await app.models.Campaign.upcoming();
|
||||
|
||||
const lastYearDate = new Date();
|
||||
lastYearDate.setFullYear(lastYearDate.getFullYear() - 1);
|
||||
const lastYear = lastYearDate.getFullYear();
|
||||
|
||||
const response = await app.models.Campaign.upcoming();
|
||||
const campaignDated = response.dated;
|
||||
const campaignYear = campaignDated.getFullYear();
|
||||
const now = new Date();
|
||||
|
||||
expect(campaignYear).toEqual(lastYear);
|
||||
expect(campaignDated).toEqual(jasmine.any(Date));
|
||||
expect(campaignDated).toBeLessThanOrEqual(now);
|
||||
});
|
||||
});
|
||||
|
|
|
@ -3,27 +3,22 @@ import watcher from 'core/mocks/watcher';
|
|||
|
||||
describe('Supplier', () => {
|
||||
describe('Component vnSupplierFiscalData', () => {
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
let $element;
|
||||
let controller;
|
||||
|
||||
beforeEach(ngModule('supplier'));
|
||||
|
||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
|
||||
$httpBackend = _$httpBackend_;
|
||||
beforeEach(inject(($componentController, $rootScope) => {
|
||||
$scope = $rootScope.$new();
|
||||
$scope.watcher = watcher;
|
||||
$scope.watcher.orgData = {id: 101, isEqualizated: false, isTaxDataChecked: false};
|
||||
$scope.watcher.orgData = {id: 1};
|
||||
$element = angular.element('<vn-supplier-fiscal-data></supplier-fiscal-data>');
|
||||
controller = $componentController('vnClientFiscalData', {$element, $scope});
|
||||
controller = $componentController('vnSupplierFiscalData', {$element, $scope});
|
||||
controller.card = {reload: () => {}};
|
||||
controller.client = {
|
||||
id: 101,
|
||||
email: 'batman@gothamcity.com',
|
||||
phone: '1111111111',
|
||||
isEqualizated: false,
|
||||
isTaxDataChecked: false
|
||||
controller.supplier = {
|
||||
id: 1,
|
||||
name: 'Batman'
|
||||
};
|
||||
|
||||
controller._province = {};
|
||||
|
@ -31,110 +26,9 @@ describe('Supplier', () => {
|
|||
controller._postcode = {};
|
||||
}));
|
||||
|
||||
describe('onSubmit()', () => {
|
||||
it('should call the save() method directly', () => {
|
||||
jest.spyOn(controller, 'save');
|
||||
|
||||
controller.onSubmit();
|
||||
|
||||
expect(controller.save).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it('should call the checkExistingClient() if the isTaxDataChecked property is checked', () => {
|
||||
jest.spyOn(controller, 'save');
|
||||
jest.spyOn(controller, 'checkExistingClient');
|
||||
|
||||
controller.client.isTaxDataChecked = true;
|
||||
controller.onSubmit();
|
||||
|
||||
expect(controller.save).not.toHaveBeenCalledWith();
|
||||
expect(controller.checkExistingClient).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkExistingClient()', () => {
|
||||
it(`should make a HTTP GET query filtering by email, phone and mobile`, () => {
|
||||
controller.client.mobile = 222222222;
|
||||
const filterObj = {
|
||||
where: {
|
||||
and: [
|
||||
{or: [
|
||||
{email: controller.client.email},
|
||||
{phone: controller.client.phone},
|
||||
{mobile: controller.client.mobile}
|
||||
]},
|
||||
{id: {neq: controller.client.id}}
|
||||
]
|
||||
}
|
||||
};
|
||||
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
||||
$httpBackend.expect('GET', `Clients/findOne?filter=${filter}`).respond(404);
|
||||
controller.checkExistingClient();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
|
||||
it(`should show a save confirmation and then set the despiteOfClient property`, () => {
|
||||
controller.$.confirmDuplicatedClient = {show: () => {}};
|
||||
jest.spyOn(controller.$.confirmDuplicatedClient, 'show');
|
||||
|
||||
const filterObj = {
|
||||
where: {
|
||||
and: [
|
||||
{or: [{email: controller.client.email}, {phone: controller.client.phone}]},
|
||||
{id: {neq: controller.client.id}}
|
||||
]
|
||||
}
|
||||
};
|
||||
const expectedClient = {id: 102};
|
||||
const filter = encodeURIComponent(JSON.stringify(filterObj));
|
||||
$httpBackend.expect('GET', `Clients/findOne?filter=${filter}`).respond(expectedClient);
|
||||
controller.checkExistingClient();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.$.confirmDuplicatedClient.show).toHaveBeenCalledWith();
|
||||
expect(controller.client.despiteOfClient).toEqual(102);
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkEtChanges()', () => {
|
||||
it(`should show a propagation confirmation if isEqualizated property is changed and invoice by address is checked`, () => {
|
||||
controller.$.propagateIsEqualizated = {show: () => {}};
|
||||
jest.spyOn(controller.$.propagateIsEqualizated, 'show');
|
||||
|
||||
const orgData = $scope.watcher.orgData;
|
||||
orgData.hasToInvoiceByAddress = true;
|
||||
controller.client.isEqualizated = true;
|
||||
|
||||
controller.checkEtChanges(orgData);
|
||||
|
||||
expect(controller.$.propagateIsEqualizated.show).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it(`should call to the onAcceptEt() method if isEqualizated property is changed and invoice by address isn't checked`, () => {
|
||||
jest.spyOn(controller, 'onAcceptEt');
|
||||
|
||||
const orgData = $scope.watcher.orgData;
|
||||
orgData.hasToInvoiceByAddress = false;
|
||||
controller.client.isEqualizated = true;
|
||||
|
||||
controller.checkEtChanges(orgData);
|
||||
|
||||
expect(controller.onAcceptEt).toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
|
||||
describe('onAcceptEt()', () => {
|
||||
it('should request to patch the propagation of tax status', () => {
|
||||
controller.client = {id: 123, isEqualizated: false};
|
||||
$httpBackend.expectPATCH(`Clients/${controller.client.id}/addressesPropagateRe`, {isEqualizated: controller.client.isEqualizated}).respond('done');
|
||||
controller.onAcceptEt();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
|
||||
describe('province() setter', () => {
|
||||
it(`should set countryFk property`, () => {
|
||||
controller.client.countryFk = null;
|
||||
controller.supplier.countryFk = null;
|
||||
controller.province = {
|
||||
id: 1,
|
||||
name: 'New york',
|
||||
|
@ -144,7 +38,7 @@ describe('Supplier', () => {
|
|||
}
|
||||
};
|
||||
|
||||
expect(controller.client.countryFk).toEqual(2);
|
||||
expect(controller.supplier.countryFk).toEqual(2);
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -164,7 +58,7 @@ describe('Supplier', () => {
|
|||
postcodes: []
|
||||
};
|
||||
|
||||
expect(controller.client.provinceFk).toEqual(1);
|
||||
expect(controller.supplier.provinceFk).toEqual(1);
|
||||
});
|
||||
|
||||
it(`should set provinceFk property and fill the postalCode if there's just one`, () => {
|
||||
|
@ -182,8 +76,8 @@ describe('Supplier', () => {
|
|||
postcodes: [{code: '46001'}]
|
||||
};
|
||||
|
||||
expect(controller.client.provinceFk).toEqual(1);
|
||||
expect(controller.client.postcode).toEqual('46001');
|
||||
expect(controller.supplier.provinceFk).toEqual(1);
|
||||
expect(controller.supplier.postCode).toEqual('46001');
|
||||
});
|
||||
});
|
||||
|
||||
|
@ -206,9 +100,9 @@ describe('Supplier', () => {
|
|||
}
|
||||
};
|
||||
|
||||
expect(controller.client.city).toEqual('New York');
|
||||
expect(controller.client.provinceFk).toEqual(1);
|
||||
expect(controller.client.countryFk).toEqual(2);
|
||||
expect(controller.supplier.city).toEqual('New York');
|
||||
expect(controller.supplier.provinceFk).toEqual(1);
|
||||
expect(controller.supplier.countryFk).toEqual(2);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue