salix/modules/item/front/request/index.spec.js

121 lines
4.0 KiB
JavaScript
Raw Normal View History

2019-07-25 07:55:09 +00:00
import './index.js';
describe('Item', () => {
describe('Component vnItemRequest', () => {
let $scope;
let controller;
let $httpBackend;
beforeEach(ngModule('item'));
2019-07-25 07:55:09 +00:00
2020-07-23 14:46:16 +00:00
beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => {
2019-07-25 07:55:09 +00:00
$httpBackend = _$httpBackend_;
$scope = $rootScope.$new();
controller = $componentController('vnItemRequest', {$element: null, $scope});
2019-07-25 07:55:09 +00:00
}));
afterAll(() => {
$scope.$destroy();
$element.remove();
});
2019-07-25 07:55:09 +00:00
describe('getState()', () => {
it(`should return an string depending to the isOK value`, () => {
let isOk = null;
let result = controller.getState(isOk);
expect(result).toEqual('Pending');
2019-07-25 07:55:09 +00:00
isOk = 1;
result = controller.getState(isOk);
expect(result).toEqual('Accepted');
2019-07-25 07:55:09 +00:00
isOk = 0;
result = controller.getState(isOk);
expect(result).toEqual('Denied');
2019-07-25 07:55:09 +00:00
});
});
describe('confirmRequest()', () => {
it(`should do nothing if the request does't have itemFk or saleQuantity`, () => {
let request = {};
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
2019-07-25 07:55:09 +00:00
controller.confirmRequest(request);
expect(controller.vnApp.showSuccess).not.toHaveBeenCalled();
2019-07-25 07:55:09 +00:00
});
it('should perform a query and call vnApp.showSuccess() and refresh if the conditions are met', () => {
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
2019-07-25 07:55:09 +00:00
2019-10-22 11:44:36 +00:00
const expectedResult = {concept: 'Melee Weapon'};
2019-07-25 07:55:09 +00:00
let request = {itemFk: 1, saleQuantity: 1, id: 1};
$httpBackend.expectPOST(`TicketRequests/${request.id}/confirm`).respond(expectedResult);
2019-07-25 07:55:09 +00:00
controller.confirmRequest(request);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2019-07-25 07:55:09 +00:00
});
});
describe('changeQuantity()', () => {
it(`should call confirmRequest() if there's no sale id in the request`, () => {
let request = {};
2020-02-26 12:22:52 +00:00
jest.spyOn(controller, 'confirmRequest');
2019-07-25 07:55:09 +00:00
controller.changeQuantity(request);
expect(controller.confirmRequest).toHaveBeenCalledWith(jasmine.any(Object));
});
it(`should perform a query and call vnApp.showSuccess() if the conditions are met`, () => {
let request = {saleFk: 1, saleQuantity: 1};
2020-02-26 12:22:52 +00:00
jest.spyOn(controller.vnApp, 'showSuccess');
2019-07-25 07:55:09 +00:00
$httpBackend.expectPATCH(`Sales/${request.saleFk}`).respond();
2019-07-25 07:55:09 +00:00
controller.changeQuantity(request);
$httpBackend.flush();
expect(controller.vnApp.showSuccess).toHaveBeenCalled();
2019-07-25 07:55:09 +00:00
});
});
describe('compareDate()', () => {
it(`should return "success" if receives a future date`, () => {
let date = '3019-02-18T11:00:00.000Z';
let result = controller.compareDate(date);
expect(result).toEqual('success');
});
it(`should return "warning" if date is today`, () => {
2023-01-16 14:18:24 +00:00
let date = Date.vnNew();
2019-07-25 07:55:09 +00:00
let result = controller.compareDate(date);
expect(result).toEqual('warning');
});
});
2020-03-24 16:27:21 +00:00
describe('onDenyAccept()', () => {
it(`should deny the request`, () => {
const request = {
id: 1,
response: 'new'
};
2019-07-25 07:55:09 +00:00
$httpBackend.expectPOST(`TicketRequests/${request.id}/deny`)
.respond({response: 'denied'});
2020-03-24 16:27:21 +00:00
controller.onDenyAccept(request);
2019-07-25 07:55:09 +00:00
$httpBackend.flush();
2020-03-24 16:27:21 +00:00
expect(request.response).toBe('denied');
2019-07-25 07:55:09 +00:00
});
});
});
});