2019-07-25 07:55:09 +00:00
|
|
|
import './index.js';
|
|
|
|
import crudModel from 'core/mocks/crud-model';
|
|
|
|
|
|
|
|
describe('Item', () => {
|
|
|
|
describe('Component vnItemRequest', () => {
|
|
|
|
let $scope;
|
2019-10-24 10:44:36 +00:00
|
|
|
let $element;
|
2019-07-25 07:55:09 +00:00
|
|
|
let controller;
|
|
|
|
let $httpBackend;
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
beforeEach(ngModule('item'));
|
2019-07-25 07:55:09 +00:00
|
|
|
|
|
|
|
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.model = crudModel;
|
|
|
|
$scope.denyReason = {hide: () => {}};
|
2019-10-24 10:44:36 +00:00
|
|
|
$element = angular.element('<vn-item-request></vn-item-request>');
|
|
|
|
controller = $componentController('vnItemRequest', {$element, $scope});
|
2019-07-25 07:55:09 +00:00
|
|
|
}));
|
|
|
|
|
2019-10-24 10:44:36 +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('Nueva');
|
|
|
|
|
|
|
|
isOk = 1;
|
|
|
|
result = controller.getState(isOk);
|
|
|
|
|
|
|
|
expect(result).toEqual('Aceptada');
|
|
|
|
|
|
|
|
isOk = 0;
|
|
|
|
result = controller.getState(isOk);
|
|
|
|
|
|
|
|
expect(result).toEqual('Denegada');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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.toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
let model = controller.$.model;
|
2020-02-26 12:22:52 +00:00
|
|
|
jest.spyOn(model, 'refresh');
|
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};
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('POST', `TicketRequests/${request.id}/confirm`).respond(expectedResult);
|
|
|
|
$httpBackend.expect('POST', `TicketRequests/${request.id}/confirm`).respond(expectedResult);
|
2019-07-25 07:55:09 +00:00
|
|
|
controller.confirmRequest(request);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('PATCH', `Sales/${request.saleFk}/`).respond();
|
|
|
|
$httpBackend.expect('PATCH', `Sales/${request.saleFk}/`).respond();
|
2019-07-25 07:55:09 +00:00
|
|
|
controller.changeQuantity(request);
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
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`, () => {
|
|
|
|
let date = new Date();
|
|
|
|
|
|
|
|
let result = controller.compareDate(date);
|
|
|
|
|
|
|
|
expect(result).toEqual('warning');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('denyRequest()', () => {
|
|
|
|
it(`should perform a query and call vnApp.showSuccess(), refresh(), hide() and set denyObservation to null in the controller`, () => {
|
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 request = {id: 1};
|
|
|
|
const expectedResult = {isOk: false, attenderFk: 106, response: 'Denied!'};
|
|
|
|
controller.selectedRequest = request;
|
2019-07-25 07:55:09 +00:00
|
|
|
|
2019-10-24 22:53:53 +00:00
|
|
|
$httpBackend.when('POST', `TicketRequests/${request.id}/deny`).respond(expectedResult);
|
|
|
|
$httpBackend.expect('POST', `TicketRequests/${request.id}/deny`).respond(expectedResult);
|
2019-10-30 15:57:14 +00:00
|
|
|
controller.denyRequest('accept');
|
2019-07-25 07:55:09 +00:00
|
|
|
$httpBackend.flush();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|