2021-01-18 15:32:54 +00:00
|
|
|
import './index';
|
|
|
|
|
|
|
|
describe('fixed price', () => {
|
|
|
|
describe('Component vnFixedPrice', () => {
|
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
|
|
|
beforeEach(ngModule('item'));
|
|
|
|
|
|
|
|
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
const $scope = $rootScope.$new();
|
|
|
|
const $element = angular.element('<vn-fixed-price></vn-fixed-price>');
|
|
|
|
controller = $componentController('vnFixedPrice', {$element, $scope});
|
|
|
|
}));
|
|
|
|
|
|
|
|
describe('upsertPrice()', () => {
|
|
|
|
it('should do nothing if one or more required arguments are missing', () => {
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
controller.upsertPrice({});
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).not.toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should perform an http request to update the price', () => {
|
2023-01-16 14:18:24 +00:00
|
|
|
const now = Date.vnNew();
|
2021-01-18 15:32:54 +00:00
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
|
|
|
|
$httpBackend.expectPATCH('FixedPrices/upsertFixedPrice').respond();
|
|
|
|
controller.upsertPrice({
|
|
|
|
itemFk: 1,
|
|
|
|
started: now,
|
|
|
|
ended: now,
|
|
|
|
rate2: 1,
|
|
|
|
rate3: 2
|
|
|
|
});
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('removePrice()', () => {
|
|
|
|
it(`should only remove the created instance by the model as it doesn't have an ID yet`, () => {
|
|
|
|
const $index = 0;
|
|
|
|
controller.$ = {
|
|
|
|
model: {
|
|
|
|
remove: () => {},
|
|
|
|
data: [{
|
|
|
|
foo: 'bar'
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
jest.spyOn(controller.$.model, 'remove');
|
|
|
|
|
2022-03-16 13:58:07 +00:00
|
|
|
$httpBackend.expectGET('Warehouses').respond();
|
|
|
|
|
2021-01-18 15:32:54 +00:00
|
|
|
controller.removePrice($index);
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).not.toHaveBeenCalled();
|
|
|
|
expect(controller.$.model.remove).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should remove the instance performing an delete http request', () => {
|
|
|
|
const $index = 0;
|
|
|
|
controller.$ = {
|
|
|
|
model: {
|
|
|
|
remove: () => {},
|
|
|
|
data: [{
|
|
|
|
id: '1'
|
|
|
|
}]
|
|
|
|
}
|
|
|
|
};
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
jest.spyOn(controller.$.model, 'remove');
|
|
|
|
|
|
|
|
const query = `FixedPrices/${controller.$.model.data[0].id}`;
|
|
|
|
$httpBackend.expectDELETE(query).respond();
|
|
|
|
controller.removePrice($index);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
|
|
|
|
expect(controller.$.model.remove).toHaveBeenCalled();
|
|
|
|
});
|
|
|
|
});
|
2022-12-19 14:06:59 +00:00
|
|
|
|
|
|
|
describe('recalculateRate2()', () => {
|
|
|
|
it(`should rate2 recalculate`, () => {
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
|
|
|
const price = {
|
|
|
|
id: 1,
|
|
|
|
itemFk: 1,
|
|
|
|
rate2: 2,
|
|
|
|
rate3: 2
|
|
|
|
};
|
|
|
|
const response = {rate2: 1};
|
|
|
|
controller.recalculateRate2(price);
|
|
|
|
|
|
|
|
const query = `FixedPrices/getRate2?fixedPriceId=${price.id}&rate3=${price.rate3}`;
|
|
|
|
$httpBackend.expectGET(query).respond(response);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(price.rate2).toEqual(response.rate2);
|
|
|
|
});
|
|
|
|
});
|
2021-01-18 15:32:54 +00:00
|
|
|
});
|
|
|
|
});
|