ticket volume plus e2e, and back-front unit test fixed

This commit is contained in:
Carlos Jimenez 2018-04-03 16:10:39 +02:00
parent fd324df1c9
commit ce3600a01e
21 changed files with 141 additions and 243 deletions

View File

@ -19,7 +19,7 @@ describe('Client', () => {
describe('_getClassifications()', () => {
it('should perform a GET query to define the classifications property in the controller', () => {
let res = ['some classifications'];
let query = '/client/api/CreditClassifications?filter=%7B%22include%22%3A%5B%7B%22relation%22%3A%22creditInsurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D';
let query = '/client/api/CreditClassifications?filter=%7B%22order%22%3A%22finished%20ASC%2C%20started%20DESC%22%2C%22include%22%3A%5B%7B%22relation%22%3A%22creditInsurances%22%2C%22scope%22%3A%7B%22fields%22%3A%5B%22id%22%2C%22credit%22%2C%22created%22%2C%22grade%22%5D%2C%22order%22%3A%22created%20DESC%22%2C%22limit%22%3A2%7D%7D%5D%2C%22where%22%3A%7B%7D%7D';
$httpBackend.whenGET(query).respond(res);
$httpBackend.expectGET(query);
@ -61,20 +61,15 @@ describe('Client', () => {
});
describe('closeContract()', () => {
it('should perform a GET query to set a due date to a contract', () => {
let res = ['pepinillos'];
controller.client = {id: 101};
let classification = {id: 1};
let query = '/client/api/CreditClassifications/1';
spyOn(controller, '_getClassifications');
it('should define the classificationId property of the controller and then call the show method()', () => {
controller.$scope.closeContract = {show: () => {}};
spyOn(controller.$scope.closeContract, 'show');
expect(controller.classificationId).toBeFalsy();
controller.closeContract({id: 1});
$httpBackend.whenPATCH(query).respond(res);
$httpBackend.expectPATCH(query);
controller.closeContract(classification);
$httpBackend.flush();
expect(controller._getClassifications).toHaveBeenCalledWith(101);
});
expect(controller.classificationId).toEqual(1);
expect(controller.$scope.closeContract.show).toHaveBeenCalledWith();
});
});
});
});

View File

@ -1,7 +1,7 @@
<vn-vertical style="text-align:center">
<vn-one>{{::$ctrl.sale.concept}}</vn-one>
<vn-one>
<vn-one ng-repeat="fetchedTag in $ctrl.sale.itemTag track by $index">
<vn-one ng-repeat="fetchedTag in $ctrl.sale.item.itemTag track by $index">
<vn-label>{{::fetchedTag.tag.name}} </vn-label>{{::fetchedTag.value}}
</vn-one>
</vn-one>

View File

@ -17,7 +17,8 @@ describe('Ticket', () => {
$scope = {
index: {
accept: function() {}
}
},
form: {}
};
controller = $componentController('vnTicketPackageIndex', {$scope: $scope});
}));
@ -33,24 +34,22 @@ describe('Ticket', () => {
describe('submit()', () => {
it('should perform a post', () => {
spyOn(angular, 'equals').and.returnValue(true);
let query = '/ticket/api/TicketPackagings/crudTicketPackaging';
controller.removedPackages = [];
controller.oldPackages = [
{id: 1, packagingFk: 1, quantity: 5, ticketFk: 1}
];
controller.packages = [
{quantity: 5, packagingFk: 2, ticketFk: 1},
{id: 1, packagingFk: 1, quantity: 25, ticketFk: 1}
];
spyOn(controller.$.index, 'accept');
let packagesObj = {
delete: controller.removedPackages,
create: [],
update: []
};
let query = '/ticket/api/TicketPackagings/crudTicketPackaging';
controller.removedPackages = [];
controller.oldPackages = [];
controller.oldPackages[1] = {id: 1, packagingFk: 1, quantity: 5, ticketFk: 1};
controller.packages = [
{quantity: 5, packagingFk: 2, ticketFk: 1},
{id: 1, packagingFk: 1, quantity: 25, ticketFk: 1}
];
$httpBackend.whenPOST(query, packagesObj).respond('omg YEAH');
$httpBackend.expectPOST(query, packagesObj);
$httpBackend.expectPOST(query, {delete: [], create: [{quantity: 5, packagingFk: 2, ticketFk: 1}], update: [{id: 1, packagingFk: 1, quantity: 25, ticketFk: 1}]}).respond('ok');
controller.submit();
$httpBackend.flush();
});

View File

@ -17,16 +17,7 @@
<td style="text-align:center!important"><vn-check style="text-align:center!important" vn-one field="sale.isChecked.isChecked" disabled="true"></vn-check></td>
<td number>{{::sale.itemFk}}</td>
<td>
<vn-vertical style="text-align:center">
<vn-one>{{::sale.concept}}</vn-one>
<vn-one>
<vn-one ng-repeat="fetchedTag in sale.itemTag track by $index">
<vn-label>{{::fetchedTag.tag.name}} </vn-label>{{::fetchedTag.value}}
</vn-one>
</vn-one>
</vn-vertical>
</td>
<td><vn-fetched-tags sale="sale"/></td>
<td number>{{::sale.quantity}}</td>
</tr>
</tbody>

View File

@ -1,10 +1,30 @@
<form name="form" ng-submit="$ctrl.submit()">
<mg-ajax path="/ticket/api/sales/filter" options="vnIndexNonAuto" actions="$ctrl.setVolumes()"></mg-ajax>
<vn-vertical>
<vn-card pad-large>
<vn-one margin-medium-top>
<vn-vertical>
<vn-title>Volumes</vn-title>
</vn-one>
<table class="vn-grid">
<thead>
<tr>
<th number translate>Item</th>
<th translate style="text-align:center">Description</th>
<th number translate>Quantity</th>
<th number translate>m³ per unit</th>
<th number translate>m³ per quantity</th>
<th number translate>total m³</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="sale in index.model.instances track by sale.id">
<td number>{{::sale.itemFk}}</td>
<td><vn-fetched-tags sale="sale"/></td>
<td number>{{::sale.quantity}}</td>
<td number>{{::sale.volume.m3_uni}}</td>
<td number>{{::sale.volume.volumeTimesQuantity}}</td>
<td number>{{::sale.volume.m3_total}}</td>
</tr>
</tbody>
</table>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>
</vn-vertical>

View File

@ -1,27 +1,35 @@
import ngModule from '../module';
import FilterTicketList from '../filter-ticket-list';
class Controller {
constructor($stateParams, $scope, $http, $translate, vnApp) {
this.params = $stateParams;
class Controller extends FilterTicketList {
constructor($scope, $http, $translate, $timeout, $state) {
super($scope, $timeout, $state);
this.$scope = $scope;
this.$http = $http;
this.$translate = $translate;
this.vnApp = vnApp;
this.onOrder('itemFk', 'ASC');
this.ticketVolumes = [];
this.oldVolumes = {};
this.removedVolumes = [];
}
_getTicketVolumes(ticketFk) {
this.$http.get(`/tcket/api/Volumes/${ticketFk}/getVolumes`)
setVolumes() {
if (!this.$scope.index) return;
this.$http.get(`/api/tickets/${this.ticket.id}/getVolume`)
.then(response => {
this.ticketVolumes = response.data;
if (response.data) {
this.$scope.index.model.instances.forEach(sale => {
response.data.volumes.forEach(volume => {
if (sale.id === volume.saleFk)
sale.volume = volume;
});
});
}
});
}
}
Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
Controller.$inject = ['$scope', '$http', '$translate', '$timeout', '$state'];
ngModule.component('vnTicketVolume', {
template: require('./ticket-volume.html'),

View File

@ -1,143 +0,0 @@
// import './ticket-observations.js';
// describe('ticket', () => {
// describe('Component vnTicketObservations', () => {
// let $componentController;
// let $state;
// let controller;
// let $httpBackend;
// beforeEach(() => {
// angular.mock.module('ticket');
// });
// beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
// $componentController = _$componentController_;
// $state = _$state_;
// $httpBackend = _$httpBackend_;
// controller = $componentController('vnTicketObservations', {$state: $state});
// }));
// describe('add / remove observation', () => {
// it('should add one empty observation into controller observations collection and call _setIconAdd()', () => {
// controller.ticketObservations = [];
// spyOn(controller, '_setIconAdd').and.callThrough();
// controller.addObservation();
// expect(controller._setIconAdd).toHaveBeenCalledWith();
// expect(controller.ticketObservations.length).toEqual(1);
// expect(controller.ticketObservations[0].id).toBe(undefined);
// expect(controller.ticketObservations[0].showAddIcon).toBeTruthy();
// });
// it('should remove an observation that occupies the position in the index given and call _setIconAdd()', () => {
// let index = 2;
// controller.ticketObservations = [
// {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false},
// {id: 2, observationTypeFk: 2, description: 'two', showAddIcon: false},
// {id: 3, observationTypeFk: 3, description: 'three', showAddIcon: true}
// ];
// spyOn(controller, '_setIconAdd').and.callThrough();
// controller.removeObservation(index);
// expect(controller._setIconAdd).toHaveBeenCalledWith();
// expect(controller.ticketObservations.length).toEqual(2);
// expect(controller.ticketObservations[0].showAddIcon).toBeFalsy();
// expect(controller.ticketObservations[1].showAddIcon).toBeTruthy();
// expect(controller.ticketObservations[index]).toBe(undefined);
// });
// });
// describe('_equalObservations()', () => {
// it('should return true if two observations are equals independent of control attributes', () => {
// let observationOne = {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: true};
// let observationTwo = {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false};
// let equals = controller._equalObservations(observationOne, observationTwo);
// expect(equals).toBeTruthy();
// });
// it('should return false if two observations aint equals independent of control attributes', () => {
// let observationOne = {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: true};
// let observationTwo = {id: 1, observationTypeFk: 1, description: 'two', showAddIcon: true};
// let equals = controller._equalObservations(observationOne, observationTwo);
// expect(equals).toBeFalsy();
// });
// });
// describe('get Observations()', () => {
// it('should perform a GET query to receive the ticket observations', () => {
// let res = [{id: 1, observationTypeFk: 1, description: 'one'}];
// $httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond(res);
// $httpBackend.expectGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`);
// controller.getObservations();
// $httpBackend.flush();
// });
// });
// describe('submit()', () => {
// it("should return an error message 'The observation type must be unique'", () => {
// controller.$scope.form = {};
// spyOn(controller.vnApp, 'showMessage').and.callThrough();
// controller.ticketObservations = [
// {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1},
// {observationTypeFk: 1, description: 'one', itemFk: 1}
// ];
// controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}};
// controller.submit();
// expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The observation type must be unique');
// });
// it("should perfom a query to delete observations", () => {
// controller.$scope.form = {$setPristine: () => {}};
// controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one'}};
// controller.ticketObservations = [];
// controller.removedObservations = [1];
// $httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
// $httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!');
// controller.submit();
// $httpBackend.flush();
// });
// it("should perfom a query to update observations", () => {
// controller.$scope.form = {$setPristine: () => {}};
// controller.ticketObservations = [{id: 1, observationTypeFk: 1, description: 'number one!'}];
// controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one'}};
// $httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
// $httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!');
// controller.submit();
// $httpBackend.flush();
// });
// it("should perfom a query to create new observation", () => {
// controller.$scope.form = {$setPristine: () => {}};
// controller.ticketObservations = [{observationTypeFk: 2, description: 'two'}];
// $httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
// $httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!');
// controller.submit();
// $httpBackend.flush();
// });
// it("should return a message 'No changes to save' when there are no changes to apply", () => {
// controller.$scope.form = {$setPristine: () => {}};
// spyOn(controller.vnApp, 'showMessage').and.callThrough();
// controller.oldObservations = [
// {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false},
// {id: 2, observationTypeFk: 2, description: 'two', showAddIcon: true}
// ];
// controller.ticketObservations = [];
// controller.submit();
// expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save');
// });
// });
// });
// });

View File

@ -50,6 +50,7 @@ describe('create item tags path', () => {
.waitToClick(selectors.itemTags.fifthTagSelect)
.waitToClick(selectors.itemTags.fifthTagSelectOptionFive)
.type(selectors.itemTags.fifthValueInput, 'Thanos')
.clearInput(selectors.itemTags.fifthRelevancyInput)
.type(selectors.itemTags.fifthRelevancyInput, '1')
.click(selectors.itemTags.submitItemTagsButton)
.waitForSnackbar()

View File

@ -1,19 +1,14 @@
const totalGreuge = require('../sumAmount');
const catchErrors = require('../../../../../../services/utils/jasmineHelpers').catchErrors;
describe('Greuge totalGreuge()', () => {
it('should call the sumAmount method', done => {
it('should call the sumAmount method', async() => {
let clientFk = 1;
let self = jasmine.createSpyObj('self', ['remoteMethod', 'rawSql']);
self.rawSql.and.returnValue(Promise.resolve([{sumAmount: 6000}]));
totalGreuge(self);
let callback = (error, result) => {
if (error) return catchErrors(done)(error);
let result = await self.sumAmount(clientFk);
expect(result).toBe(6000);
done();
};
self.sumAmount(clientFk, callback);
expect(result).toBe(6000);
});
});

View File

@ -0,0 +1,28 @@
USE `vn`;
DROP procedure IF EXISTS `ticketVolume`;
DELIMITER $$
USE `vn`$$
CREATE DEFINER=`root`@`%` PROCEDURE `ticketVolume`(IN vTicketId INT)
BEGIN
DECLARE vWarehouseId INTEGER;
DECLARE vShippedDate DATE;
DROP TEMPORARY TABLE IF EXISTS ticketVolume;
SELECT warehouseFk, shipped INTO vWarehouseId,vShippedDate FROM vn.ticket WHERE id = vTicketId;
CREATE TEMPORARY TABLE IF NOT EXISTS ticketVolume ENGINE MEMORY
SELECT itemFk, saleFk, quantity, concept, VolUd as m3_uni, volume as m3, volume * quantity as volumeTimesQuantity, @m3:= @m3 + ifnull(volume,0) as m3_total
FROM
(
SELECT round(r.cm3 / 1000000,3) as VolUd ,s.quantity, round(r.cm3 * s.quantity / 1000000,3) as volume,
s.itemFk, s.id AS saleFk, s.concept, @m3:= 0, @vol:=0, t.agencyModeFk
FROM sale s
JOIN vn.ticket t on t.id = s.ticketFk
JOIN bi.rotacion r ON r.Id_Article = s.itemFk AND r.warehouse_id = t.warehouseFk
WHERE s.ticketFk = vTicketId
) sub;
END$$
DELIMITER ;

View File

@ -8,12 +8,6 @@
"TaxType": {
"dataSource": "vn"
},
"ItemTag": {
"dataSource": "vn"
},
"Tag": {
"dataSource": "vn"
},
"ItemNiche": {
"dataSource": "vn"
},

View File

@ -1,5 +1,5 @@
module.exports = Self => {
Self.remoteMethod('getVolumes', {
Self.remoteMethod('getVolume', {
description: 'Returns the volumes of a ticket',
accessType: 'READ',
accepts: [{
@ -10,17 +10,20 @@ module.exports = Self => {
http: {source: 'path'}
}],
returns: {
type: 'object'
arg: 'volumes'
},
http: {
path: `/:id/getVolumes`,
path: `/:id/getVolume`,
verb: 'GET'
}
});
Self.getVolumes = async ticketFk => {
let query = `SELECT vn.ticketVolume(?) AS ticketVolumes`;
Self.getVolume = async ticketFk => {
let callMethod = `CALL vn.ticketVolume(?);`;
await Self.rawSql(callMethod, [ticketFk]);
let query = `SELECT * from vn.ticketVolume;`;
let response = await Self.rawSql(query, [ticketFk]);
return response[0];
return response;
};
};

View File

@ -1,16 +1,16 @@
// const getDebt = require('../getDebt');
const getVolume = require('../get-volume');
// describe('client getDebt()', () => {
// it('should call the getDebt method', done => {
// let clientFk = 109;
// let self = jasmine.createSpyObj('self', ['remoteMethod', 'rawSql']);
// self.rawSql.and.returnValue(Promise.resolve([{debt: 100}]));
// getDebt(self);
// self.getDebt(clientFk)
// .then(result => {
// expect(result.debt).toEqual(100);
// done();
// });
// });
// });
describe('client getVolume()', () => {
it('should call the getVolume method', done => {
let ticketFk = 1;
let self = jasmine.createSpyObj('self', ['remoteMethod', 'rawSql']);
self.rawSql.and.returnValue(Promise.resolve([{volumeData: 100}]));
getVolume(self);
self.getVolume(ticketFk)
.then(result => {
expect(result).toEqual([{volumeData: 100}]);
done();
});
});
});

View File

@ -1,4 +1,3 @@
module.exports = function(Self) {
require('../methods/ticket/change-time.js')(Self);
require('../methods/ticket/change-worker.js')(Self);

View File

@ -72,6 +72,12 @@
"Item": {
"dataSource": "vn"
},
"ItemTag": {
"dataSource": "vn"
},
"Tag": {
"dataSource": "vn"
},
"Origin": {
"dataSource": "vn"
},

View File

@ -10,15 +10,22 @@ module.exports = Self => {
limit: params.size,
order: params.order || 'concept ASC',
include: [{
relation: "itemTag",
relation: "item",
scope: {
fields: ["id", "value", "priority", "tagFk"],
include: {
relation: "tag",
relation: "itemTag",
scope: {
fields: ["name"]
fields: ["tagFk", "value"],
include: {
relation: "tag",
scope: {
fields: ["name"]
}
},
limit: 6
}
}
},
fields: ["itemFk", "name"]
}
},
{

View File

@ -41,11 +41,6 @@
"foreignKey": "itemFk",
"required": true
},
"itemTag": {
"type": "hasMany",
"model": "ItemTag",
"foreignKey": "itemFk"
},
"ticket": {
"type": "belongsTo",
"model": "Ticket",