2021-06-29 06:59:55 +00:00
|
|
|
import './index.js';
|
|
|
|
import watcher from 'core/mocks/watcher';
|
|
|
|
import crudModel from 'core/mocks/crud-model';
|
2022-05-12 06:27:04 +00:00
|
|
|
const UserError = require('vn-loopback/util/user-error');
|
2021-06-29 06:59:55 +00:00
|
|
|
|
|
|
|
describe('InvoiceIn', () => {
|
|
|
|
describe('Component tax', () => {
|
|
|
|
let controller;
|
|
|
|
let $scope;
|
|
|
|
let vnApp;
|
2022-05-09 12:34:20 +00:00
|
|
|
let $httpBackend;
|
2021-06-29 06:59:55 +00:00
|
|
|
|
|
|
|
beforeEach(ngModule('invoiceIn'));
|
|
|
|
|
2022-05-09 12:34:20 +00:00
|
|
|
beforeEach(inject(($componentController, $rootScope, _vnApp_, _$httpBackend_) => {
|
|
|
|
$httpBackend = _$httpBackend_;
|
2021-06-29 06:59:55 +00:00
|
|
|
vnApp = _vnApp_;
|
|
|
|
jest.spyOn(vnApp, 'showError');
|
|
|
|
$scope = $rootScope.$new();
|
|
|
|
$scope.model = crudModel;
|
|
|
|
$scope.watcher = watcher;
|
2021-09-08 07:44:46 +00:00
|
|
|
|
2021-06-29 06:59:55 +00:00
|
|
|
const $element = angular.element('<vn-invoice-in-tax></vn-invoice-in-tax>');
|
|
|
|
controller = $componentController('vnInvoiceInTax', {$element, $scope});
|
2022-05-09 12:34:20 +00:00
|
|
|
controller.$.model = crudModel;
|
2021-06-29 06:59:55 +00:00
|
|
|
controller.invoiceIn = {id: 1};
|
|
|
|
}));
|
|
|
|
|
2021-08-10 06:18:52 +00:00
|
|
|
describe('taxRate()', () => {
|
2021-06-29 06:59:55 +00:00
|
|
|
it('should set tax rate with the Sage tax type value', () => {
|
2021-08-10 06:18:52 +00:00
|
|
|
const taxRateSelection = {
|
2021-06-29 06:59:55 +00:00
|
|
|
rate: 21
|
|
|
|
};
|
2021-08-10 06:18:52 +00:00
|
|
|
const invoiceInTax = {
|
|
|
|
taxableBase: 200
|
|
|
|
};
|
2021-06-29 06:59:55 +00:00
|
|
|
|
2021-08-10 06:18:52 +00:00
|
|
|
const taxRate = controller.taxRate(invoiceInTax, taxRateSelection);
|
2021-06-29 06:59:55 +00:00
|
|
|
|
2021-08-10 06:18:52 +00:00
|
|
|
expect(taxRate).toEqual(42);
|
2021-06-29 06:59:55 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('onSubmit()', () => {
|
|
|
|
it('should make HTTP POST request to save tax values', () => {
|
|
|
|
controller.card = {reload: () => {}};
|
|
|
|
jest.spyOn($scope.watcher, 'check');
|
|
|
|
jest.spyOn($scope.watcher, 'notifySaved');
|
|
|
|
jest.spyOn($scope.watcher, 'updateOriginalData');
|
|
|
|
jest.spyOn(controller.card, 'reload');
|
|
|
|
jest.spyOn($scope.model, 'save');
|
|
|
|
|
|
|
|
controller.onSubmit();
|
|
|
|
|
|
|
|
expect($scope.model.save).toHaveBeenCalledWith();
|
|
|
|
expect($scope.watcher.updateOriginalData).toHaveBeenCalledWith();
|
|
|
|
expect($scope.watcher.check).toHaveBeenCalledWith();
|
|
|
|
expect($scope.watcher.notifySaved).toHaveBeenCalledWith();
|
|
|
|
expect(controller.card.reload).toHaveBeenCalledWith();
|
|
|
|
});
|
|
|
|
});
|
2022-05-09 12:34:20 +00:00
|
|
|
|
|
|
|
describe('onResponse()', () => {
|
|
|
|
it('should return success message', () => {
|
2022-05-12 06:27:04 +00:00
|
|
|
controller.expense = {
|
2022-05-09 12:34:20 +00:00
|
|
|
code: 7050000005,
|
|
|
|
isWithheld: 0,
|
|
|
|
description: 'Test'
|
|
|
|
};
|
|
|
|
|
2022-05-12 06:27:04 +00:00
|
|
|
const data = [{
|
|
|
|
id: controller.expense.code,
|
|
|
|
isWithheld: controller.expense.isWithheld,
|
|
|
|
name: controller.expense.description
|
2022-05-09 12:34:20 +00:00
|
|
|
}];
|
|
|
|
|
|
|
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
2022-05-12 06:27:04 +00:00
|
|
|
$httpBackend.expect('POST', `Expenses`, data).respond();
|
2022-05-09 12:34:20 +00:00
|
|
|
|
|
|
|
controller.onResponse();
|
|
|
|
$httpBackend.flush();
|
|
|
|
|
2022-05-12 06:27:04 +00:00
|
|
|
expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Expense saved!');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an error if code is empty', () => {
|
|
|
|
controller.expense = {
|
|
|
|
code: null,
|
|
|
|
isWithheld: 0,
|
|
|
|
description: 'Test'
|
|
|
|
};
|
|
|
|
|
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
|
|
|
controller.onResponse();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The code can't be empty`);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return an error if description is empty', () => {
|
|
|
|
controller.expense = {
|
|
|
|
code: 7050000005,
|
|
|
|
isWithheld: 0,
|
|
|
|
description: null
|
|
|
|
};
|
|
|
|
|
|
|
|
jest.spyOn(controller.vnApp, 'showError');
|
|
|
|
controller.onResponse();
|
|
|
|
|
|
|
|
expect(controller.vnApp.showError).toHaveBeenCalledWith(`The description can't be empty`);
|
2022-05-09 12:34:20 +00:00
|
|
|
});
|
|
|
|
});
|
2021-06-29 06:59:55 +00:00
|
|
|
});
|
|
|
|
});
|
2022-05-09 12:34:20 +00:00
|
|
|
|