add test
This commit is contained in:
parent
4811254ccb
commit
2f87ac8c96
|
@ -1,6 +1,6 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethod('createInvoiceIn', {
|
Self.remoteMethod('createInvoiceIn', {
|
||||||
description: 'create a invoce in from a agency terms',
|
description: 'create a invoce in from one or more agency terms',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [{
|
||||||
arg: 'rows',
|
arg: 'rows',
|
||||||
|
@ -12,7 +12,7 @@ module.exports = Self => {
|
||||||
arg: 'dms',
|
arg: 'dms',
|
||||||
type: ['object'],
|
type: ['object'],
|
||||||
required: true,
|
required: true,
|
||||||
description: 'The dms files'
|
description: 'the dms file'
|
||||||
}],
|
}],
|
||||||
returns: {
|
returns: {
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
describe('AgencyTerm createInvoiceIn()', () => {
|
||||||
|
const rows = [
|
||||||
|
{
|
||||||
|
routeFk: 2,
|
||||||
|
supplierFk: 1,
|
||||||
|
created: '2022-03-02T23:00:00.000Z',
|
||||||
|
totalPrice: 165
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const dms = [
|
||||||
|
{
|
||||||
|
id: 7,
|
||||||
|
file: '7.pdf',
|
||||||
|
contentType: 'application/pdf',
|
||||||
|
reference: '1',
|
||||||
|
description: 'Plants SL',
|
||||||
|
hasFile: false,
|
||||||
|
companyFk: 442,
|
||||||
|
dmsTypeFk: 1,
|
||||||
|
warehouseFk: 1,
|
||||||
|
workerFk: 9
|
||||||
|
}
|
||||||
|
];
|
||||||
|
const userId = 1;
|
||||||
|
const activeCtx = {
|
||||||
|
accessToken: {userId: userId},
|
||||||
|
};
|
||||||
|
const ctx = {req: activeCtx};
|
||||||
|
|
||||||
|
it('should make a global invoicing', async() => {
|
||||||
|
const tx = await models.AgencyTerm.beginTransaction({});
|
||||||
|
const options = {transaction: tx};
|
||||||
|
|
||||||
|
try {
|
||||||
|
const invoiceInId = 10;
|
||||||
|
const invoiceInDueDayId = 11;
|
||||||
|
const invoiceInTaxId = 12;
|
||||||
|
|
||||||
|
const oldInvoiceIn = await models.AgencyTerm.findById(invoiceInId, null, options);
|
||||||
|
const oldInvoiceInDueDay = await models.AgencyTerm.findById(invoiceInDueDayId, null, options);
|
||||||
|
const oldInvoiceInTax = await models.AgencyTerm.findById(invoiceInTaxId, null, options);
|
||||||
|
|
||||||
|
const [newInvoiceIn] = await models.Ticket.rawSql('SELECT MAX(id) id FROM invoiceIn', null, options);
|
||||||
|
// const [newInvoiceInDueDay] = await models.AgencyTerm.rawSql('SELECT MAX(id) id FROM invoiceInDueDay', null, options);
|
||||||
|
// const [newInvoiceInTax] = await models.AgencyTerm.rawSql('SELECT MAX(id) id FROM invoiceInTax', null, options);
|
||||||
|
|
||||||
|
await models.AgencyTerm.createInvoiceIn(rows, dms, options);
|
||||||
|
|
||||||
|
// expect(newInvoiceIn.id).toEqual(oldInvoiceIn.id + 1);
|
||||||
|
// expect(newInvoiceInDueDay.id).toEqual(oldInvoiceInDueDay.id + 1);
|
||||||
|
// expect(newInvoiceInTax.id).toEqual(oldInvoiceInTax.id + 1);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -0,0 +1,26 @@
|
||||||
|
const models = require('vn-loopback/server/server').models;
|
||||||
|
|
||||||
|
xdescribe('AgencyTerm filter()', () => {
|
||||||
|
const authUserId = 9;
|
||||||
|
|
||||||
|
it('should all return the tickets matching the filter', async() => {
|
||||||
|
const tx = await models.AgencyTerm.beginTransaction({});
|
||||||
|
|
||||||
|
try {
|
||||||
|
const options = {transaction: tx};
|
||||||
|
const filter = {};
|
||||||
|
const ctx = {req: {accessToken: {userId: authUserId}}, args: {filter: filter}};
|
||||||
|
|
||||||
|
const agencyTerms = await models.AgencyTerm.filter(ctx, null, options);
|
||||||
|
const firstAgencyTerm = agencyTerms[0];
|
||||||
|
|
||||||
|
expect(firstAgencyTerm.routeFk).toEqual(1);
|
||||||
|
expect(agencyTerms.length).toEqual(3);
|
||||||
|
|
||||||
|
await tx.rollback();
|
||||||
|
} catch (e) {
|
||||||
|
await tx.rollback();
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
|
@ -10,7 +10,6 @@ class Controller extends Section {
|
||||||
hasFile: false,
|
hasFile: false,
|
||||||
hasFileAttached: false
|
hasFileAttached: false
|
||||||
};
|
};
|
||||||
this.addedDms;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get route() {
|
get route() {
|
||||||
|
@ -83,7 +82,6 @@ class Controller extends Section {
|
||||||
this.$http(options).then(res => {
|
this.$http(options).then(res => {
|
||||||
if (res) {
|
if (res) {
|
||||||
let addedDms = res.data;
|
let addedDms = res.data;
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
||||||
this.$.watcher.updateOriginalData();
|
this.$.watcher.updateOriginalData();
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
|
@ -94,7 +92,7 @@ class Controller extends Section {
|
||||||
this.$http.post('AgencyTerms/createInvoiceIn', params)
|
this.$http.post('AgencyTerms/createInvoiceIn', params)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.$state.go('route.agencyTerm.index');
|
this.$state.go('route.agencyTerm.index');
|
||||||
this.vnApp.showSuccess(this.$t('InvoiceIn created'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,64 +1,53 @@
|
||||||
import './index';
|
import './index';
|
||||||
|
import watcher from 'core/mocks/watcher.js';
|
||||||
|
|
||||||
describe('Client', () => {
|
describe('AgencyTerm', () => {
|
||||||
describe('Component vnClientDmsCreate', () => {
|
describe('Component vnAgencyTermCreateInvoiceIn', () => {
|
||||||
let controller;
|
let controller;
|
||||||
let $scope;
|
let $scope;
|
||||||
let $httpBackend;
|
let $httpBackend;
|
||||||
let $httpParamSerializer;
|
let $httpParamSerializer;
|
||||||
|
|
||||||
beforeEach(ngModule('client'));
|
beforeEach(ngModule('route'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
beforeEach(inject(($componentController, $rootScope, _$httpBackend_, _$httpParamSerializer_) => {
|
||||||
$scope = $rootScope.$new();
|
$scope = $rootScope.$new();
|
||||||
$httpBackend = _$httpBackend_;
|
$httpBackend = _$httpBackend_;
|
||||||
$httpParamSerializer = _$httpParamSerializer_;
|
$httpParamSerializer = _$httpParamSerializer_;
|
||||||
const $element = angular.element('<vn-client-create></vn-client-create>');
|
const $element = angular.element('<vn-agency-term-create-invoice-in></vn-agency-term-create-invoice-in>');
|
||||||
controller = $componentController('vnClientDmsCreate', {$element, $scope});
|
controller = $componentController('vnAgencyTermCreateInvoiceIn', {$element});
|
||||||
controller._client = {id: 1101, name: 'Bruce wayne'};
|
controller._route = {
|
||||||
|
id: 1
|
||||||
|
};
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('client() setter', () => {
|
describe('$onChanges()', () => {
|
||||||
it('should set the client data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
it('should update the params data when $params.q is defined', () => {
|
||||||
|
controller.$params = {q: '{"supplierName": "Plants SL","rows": null}'};
|
||||||
|
|
||||||
|
const params = {q: '{"supplierName": "Plants SL", "rows": null}'};
|
||||||
|
const json = JSON.parse(params.q);
|
||||||
|
|
||||||
|
controller.$onChanges();
|
||||||
|
|
||||||
|
expect(controller.params).toEqual(json);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('route() setter', () => {
|
||||||
|
it('should set the ticket data and then call setDefaultParams() and getAllowedContentTypes()', () => {
|
||||||
jest.spyOn(controller, 'setDefaultParams');
|
jest.spyOn(controller, 'setDefaultParams');
|
||||||
jest.spyOn(controller, 'getAllowedContentTypes');
|
jest.spyOn(controller, 'getAllowedContentTypes');
|
||||||
controller.client = {
|
controller.route = {
|
||||||
id: 15,
|
id: 1
|
||||||
name: 'Bruce wayne'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
expect(controller.client).toBeDefined();
|
expect(controller.route).toBeDefined();
|
||||||
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
expect(controller.setDefaultParams).toHaveBeenCalledWith();
|
||||||
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
expect(controller.getAllowedContentTypes).toHaveBeenCalledWith();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('setDefaultParams()', () => {
|
|
||||||
it('should perform a GET query and define the dms property on controller', () => {
|
|
||||||
const params = {filter: {
|
|
||||||
where: {code: 'paymentsLaw'}
|
|
||||||
}};
|
|
||||||
let serializedParams = $httpParamSerializer(params);
|
|
||||||
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 12, code: 'paymentsLaw'});
|
|
||||||
controller.setDefaultParams();
|
|
||||||
$httpBackend.flush();
|
|
||||||
|
|
||||||
expect(controller.dms).toBeDefined();
|
|
||||||
expect(controller.dms.reference).toEqual(1101);
|
|
||||||
expect(controller.dms.dmsTypeId).toEqual(12);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('onFileChange()', () => {
|
|
||||||
it('should set dms hasFileAttached property to true if has any files', () => {
|
|
||||||
const files = [{id: 1, name: 'MyFile'}];
|
|
||||||
controller.onFileChange(files);
|
|
||||||
$scope.$apply();
|
|
||||||
|
|
||||||
expect(controller.dms.hasFileAttached).toBeTruthy();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('getAllowedContentTypes()', () => {
|
describe('getAllowedContentTypes()', () => {
|
||||||
it('should make an HTTP GET request to get the allowed content types', () => {
|
it('should make an HTTP GET request to get the allowed content types', () => {
|
||||||
const expectedResponse = ['image/png', 'image/jpg'];
|
const expectedResponse = ['image/png', 'image/jpg'];
|
||||||
|
@ -70,5 +59,49 @@ describe('Client', () => {
|
||||||
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
|
expect(controller.allowedContentTypes).toEqual('image/png, image/jpg');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('setDefaultParams()', () => {
|
||||||
|
it('should perform a GET query and define the dms property on controller', () => {
|
||||||
|
const params2 = {filter: {
|
||||||
|
where: {code: 'invoiceIn'}
|
||||||
|
}};
|
||||||
|
let serializedParams = $httpParamSerializer(params2);
|
||||||
|
$httpBackend.expect('GET', `DmsTypes/findOne?${serializedParams}`).respond({id: 1, code: 'invoiceIn'});
|
||||||
|
controller.params = {supplierName: 'Plants SL'};
|
||||||
|
controller.setDefaultParams();
|
||||||
|
$httpBackend.flush();
|
||||||
|
|
||||||
|
expect(controller.dms).toBeDefined();
|
||||||
|
expect(controller.dms.dmsTypeId).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onSubmit()', () => {
|
||||||
|
it('should make an HTTP POST request to save the form data', () => {
|
||||||
|
controller.$.watcher = watcher;
|
||||||
|
|
||||||
|
jest.spyOn(controller.$.watcher, 'updateOriginalData');
|
||||||
|
const files = [{id: 1, name: 'MyFile'}];
|
||||||
|
controller.dms = {files};
|
||||||
|
const serializedParams = $httpParamSerializer(controller.dms);
|
||||||
|
const query = `dms/uploadFile?${serializedParams}`;
|
||||||
|
controller.params = {rows: null};
|
||||||
|
|
||||||
|
$httpBackend.expect('POST', query).respond({});
|
||||||
|
$httpBackend.expect('POST', 'AgencyTerms/createInvoiceIn').respond({});
|
||||||
|
controller.onSubmit();
|
||||||
|
$httpBackend.flush();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('onFileChange()', () => {
|
||||||
|
it('should set dms hasFileAttached property to true if has any files', () => {
|
||||||
|
const files = [{id: 1, name: 'MyFile'}];
|
||||||
|
controller.onFileChange(files);
|
||||||
|
$scope.$apply();
|
||||||
|
|
||||||
|
expect(controller.dms.hasFileAttached).toBeTruthy();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -99,10 +99,11 @@ class Controller extends Section {
|
||||||
|
|
||||||
createInvoiceIn() {
|
createInvoiceIn() {
|
||||||
const rowsToCreateInvoiceIn = [];
|
const rowsToCreateInvoiceIn = [];
|
||||||
const supplier = this.checked[0].supplierFk;
|
const supplierFk = this.checked[0].supplierFk;
|
||||||
|
|
||||||
for (let agencyTerm of this.checked) {
|
for (let agencyTerm of this.checked) {
|
||||||
if (supplier == agencyTerm.supplierFk) {
|
let hasSameSupplier = supplierFk == agencyTerm.supplierFk;
|
||||||
|
if (hasSameSupplier) {
|
||||||
rowsToCreateInvoiceIn.push({
|
rowsToCreateInvoiceIn.push({
|
||||||
routeFk: agencyTerm.routeFk,
|
routeFk: agencyTerm.routeFk,
|
||||||
supplierFk: agencyTerm.supplierFk,
|
supplierFk: agencyTerm.supplierFk,
|
||||||
|
|
|
@ -1,29 +1,93 @@
|
||||||
import './index.js';
|
import './index.js';
|
||||||
|
import crudModel from 'core/mocks/crud-model';
|
||||||
|
|
||||||
describe('Item', () => {
|
describe('AgencyTerm', () => {
|
||||||
describe('Component vnItemIndex', () => {
|
describe('Component vnAgencyTermIndex', () => {
|
||||||
let controller;
|
let controller;
|
||||||
let $httpBackend;
|
let $window;
|
||||||
let $scope;
|
|
||||||
|
|
||||||
beforeEach(ngModule('item'));
|
beforeEach(ngModule('route'));
|
||||||
|
|
||||||
beforeEach(inject(($componentController, _$httpBackend_, $rootScope) => {
|
beforeEach(inject(($componentController, _$window_) => {
|
||||||
$httpBackend = _$httpBackend_;
|
$window = _$window_;
|
||||||
$scope = $rootScope.$new();
|
const $element = angular.element('<vn-agency-term-index></vn-agency-term-index>');
|
||||||
const $element = angular.element('<vn-item-index></vn-item-index>');
|
controller = $componentController('vnAgencyTermIndex', {$element});
|
||||||
controller = $componentController('vnItemIndex', {$element, $scope});
|
controller.$.model = crudModel;
|
||||||
|
controller.$.model.data = [
|
||||||
|
{supplierFk: 1, totalPrice: null},
|
||||||
|
{supplierFk: 1},
|
||||||
|
{supplierFk: 2}
|
||||||
|
];
|
||||||
}));
|
}));
|
||||||
|
|
||||||
describe('onCloneAccept()', () => {
|
describe('checked() getter', () => {
|
||||||
it('should perform a post query and then call go() then update itemSelected in the controller', () => {
|
it('should return the checked lines', () => {
|
||||||
|
const data = controller.$.model.data;
|
||||||
|
data[0].checked = true;
|
||||||
|
|
||||||
|
const checkedRows = controller.checked;
|
||||||
|
|
||||||
|
const firstCheckedRow = checkedRows[0];
|
||||||
|
|
||||||
|
expect(firstCheckedRow.supplierFk).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('totalCheked() getter', () => {
|
||||||
|
it('should return the total checked lines', () => {
|
||||||
|
const data = controller.$.model.data;
|
||||||
|
data[0].checked = true;
|
||||||
|
|
||||||
|
const checkedRows = controller.totalChecked;
|
||||||
|
|
||||||
|
expect(checkedRows).toEqual(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('preview()', () => {
|
||||||
|
it('should show the dialog summary', () => {
|
||||||
|
controller.$.summary = {show: () => {}};
|
||||||
|
jest.spyOn(controller.$.summary, 'show');
|
||||||
|
|
||||||
|
let event = new MouseEvent('click', {
|
||||||
|
view: $window,
|
||||||
|
bubbles: true,
|
||||||
|
cancelable: true
|
||||||
|
});
|
||||||
|
const route = {id: 1};
|
||||||
|
|
||||||
|
controller.preview(event, route);
|
||||||
|
|
||||||
|
expect(controller.$.summary.show).toHaveBeenCalledWith();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('createInvoiceIn()', () => {
|
||||||
|
it('should throw an error if are checked more than one autonomous', () => {
|
||||||
|
jest.spyOn(controller.vnApp, 'showError');
|
||||||
|
const data = controller.$.model.data;
|
||||||
|
data[0].checked = true;
|
||||||
|
data[2].checked = true;
|
||||||
|
|
||||||
|
controller.createInvoiceIn();
|
||||||
|
|
||||||
|
expect(controller.vnApp.showError).toHaveBeenCalled();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should call the function go() on $state to go to the file managment', () => {
|
||||||
jest.spyOn(controller.$state, 'go');
|
jest.spyOn(controller.$state, 'go');
|
||||||
|
const data = controller.$.model.data;
|
||||||
|
data[0].checked = true;
|
||||||
|
|
||||||
$httpBackend.expectRoute('POST', `Items/:id/clone`).respond({id: 99});
|
controller.createInvoiceIn();
|
||||||
controller.onCloneAccept(1);
|
|
||||||
$httpBackend.flush();
|
|
||||||
|
|
||||||
expect(controller.$state.go).toHaveBeenCalledWith('item.card.tags', {id: 99});
|
delete data[0].checked;
|
||||||
|
const params = JSON.stringify({
|
||||||
|
supplierName: data[0].supplierName,
|
||||||
|
rows: [data[0]]
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(controller.$state.go).toHaveBeenCalledWith('route.agencyTerm.createInvoiceIn', {q: params});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,4 +2,5 @@ picture: Foto
|
||||||
Buy requests: Peticiones de compra
|
Buy requests: Peticiones de compra
|
||||||
Agency route: Agencia ruta
|
Agency route: Agencia ruta
|
||||||
Agency Agreement: Agencia acuerdo
|
Agency Agreement: Agencia acuerdo
|
||||||
Autonomous: Autónomo
|
Autonomous: Autónomos
|
||||||
|
Two autonomous cannot be counted at the same time: Dos autonónomos no pueden ser contabilizados al mismo tiempo
|
|
@ -53,7 +53,7 @@
|
||||||
"url": "/createInvoiceIn?q",
|
"url": "/createInvoiceIn?q",
|
||||||
"state": "route.agencyTerm.createInvoiceIn",
|
"state": "route.agencyTerm.createInvoiceIn",
|
||||||
"component": "vn-agency-term-create-invoice-in",
|
"component": "vn-agency-term-create-invoice-in",
|
||||||
"description": "Create invoiceIn",
|
"description": "File management",
|
||||||
"params": {
|
"params": {
|
||||||
"route": "$ctrl.route"
|
"route": "$ctrl.route"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue