Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
5d503e9c19
|
@ -21,6 +21,7 @@
|
|||
label="Package"
|
||||
show-field="name"
|
||||
value-field="packagingFk"
|
||||
where="{or: [{id: {like: '%search%'}}, {name: {like: '%search%'}}]}"
|
||||
field="package.packagingFk">
|
||||
<tpl-item>{{id}} : {{name}}</tpl-item>
|
||||
</vn-autocomplete>
|
||||
|
|
|
@ -8,8 +8,7 @@ class Controller {
|
|||
}
|
||||
|
||||
$onChanges() {
|
||||
if (!this.ticket)
|
||||
return;
|
||||
if (!this.ticket) return;
|
||||
|
||||
this.$http.get(`/ticket/api/Tickets/${this.ticket.id}/summary`).then(res => {
|
||||
if (res && res.data)
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
import './index';
|
||||
|
||||
describe('Ticket', () => {
|
||||
describe('Component vnTicketSummary', () => {
|
||||
let $componentController;
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('ticket');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
|
||||
$componentController = _$componentController_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
controller = $componentController('vnTicketSummary');
|
||||
controller.ticket = {id: 1};
|
||||
}));
|
||||
|
||||
describe('$onChanges()', () => {
|
||||
it('should perform a GET query and define summary property', () => {
|
||||
let res = {id: 1, nickname: 'Batman'};
|
||||
$httpBackend.when('GET', `/ticket/api/Tickets/1/summary`).respond(200, res);
|
||||
$httpBackend.expect('GET', `/ticket/api/Tickets/1/summary`);
|
||||
controller.$onChanges();
|
||||
$httpBackend.flush();
|
||||
|
||||
expect(controller.summary).toBeDefined();
|
||||
expect(controller.summary.nickname).toEqual('Batman');
|
||||
});
|
||||
});
|
||||
|
||||
describe('formattedAddress()', () => {
|
||||
it('should return a full fromatted address with city and province', () => {
|
||||
controller.summary = {
|
||||
address: {
|
||||
province: {
|
||||
name: 'Gotham'
|
||||
},
|
||||
street: '1007 Mountain Drive',
|
||||
city: 'Gotham'
|
||||
}
|
||||
};
|
||||
|
||||
expect(controller.formattedAddress).toEqual('1007 Mountain Drive - Gotham (Gotham)');
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -0,0 +1,45 @@
|
|||
const app = require(`${servicesDir}/ticket/server/server`);
|
||||
|
||||
describe('sale updateQuantity()', () => {
|
||||
it('should throw an error if the quantity is not a number', async() => {
|
||||
let error;
|
||||
|
||||
await app.models.Sale.updateQuantity(1, 'wrong quantity!')
|
||||
.catch(response => {
|
||||
expect(response).toEqual(new Error('The value should be a number'));
|
||||
error = response;
|
||||
});
|
||||
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should throw an error if the quantity is greater than it should be', async() => {
|
||||
let error;
|
||||
|
||||
await app.models.Sale.updateQuantity(1, 99)
|
||||
.catch(response => {
|
||||
expect(response).toEqual(new Error('The new quantity should be smaller than the old one'));
|
||||
error = response;
|
||||
});
|
||||
|
||||
expect(error).toBeDefined();
|
||||
});
|
||||
|
||||
it('should update the quantity of a given sale current line', async() => {
|
||||
let originalLineData = await app.models.Sale.findOne({where: {id: 1}, fields: ['quantity']});
|
||||
|
||||
expect(originalLineData.quantity).toEqual(5);
|
||||
|
||||
await app.models.Sale.updateQuantity(1, 4);
|
||||
|
||||
let modifiedLineData = await app.models.Sale.findOne({where: {id: 1}, fields: ['quantity']});
|
||||
|
||||
expect(modifiedLineData.quantity).toEqual(4);
|
||||
|
||||
await app.models.Sale.update({id: 1}, {quantity: 5});
|
||||
|
||||
let resetLineDataValues = await app.models.Sale.findOne({where: {id: 1}, fields: ['quantity']});
|
||||
|
||||
expect(resetLineDataValues.quantity).toEqual(5);
|
||||
});
|
||||
});
|
|
@ -1,20 +1,21 @@
|
|||
const app = require(`${servicesDir}/ticket/server/server`);
|
||||
|
||||
describe('ticket componentUpdate()', () => {
|
||||
xdescribe('ticket componentUpdate()', () => {
|
||||
it('should call the componentUpdate method and receive an error', async() => {
|
||||
let data = {
|
||||
clientFk: 101,
|
||||
agencyModeFk: 1,
|
||||
addressFk: 121,
|
||||
warehouseFk: 1,
|
||||
shipped: Date.now(),
|
||||
landed: Date.now(),
|
||||
hasToBeUnrouted: true,
|
||||
shipped: new Date(),
|
||||
landed: new Date(),
|
||||
isDeleted: false,
|
||||
hasToBeUnrouted: false,
|
||||
option: 1
|
||||
};
|
||||
let ctx = {req: {accessToken: {userId: 101}}};
|
||||
await app.models.Ticket.componentUpdate(1, data, ctx)
|
||||
.catch(response => {
|
||||
expect(response).toEqual(new Error('ER_SIGNAL_EXCEPTION: NO_AGENCY_AVAILABLE'));
|
||||
});
|
||||
let result = await app.models.Ticket.componentUpdate(1, data, ctx);
|
||||
|
||||
expect(result.constructor.name).toEqual('OkPacket');
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
|
||||
const ParameterizedSQL = require('vn-loopback/node_modules/loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('listPackaging', {
|
||||
description: 'Returns all packages including item',
|
||||
|
@ -20,30 +23,12 @@ module.exports = Self => {
|
|||
});
|
||||
|
||||
Self.listPackaging = async filter => {
|
||||
let where = '';
|
||||
let limit = '';
|
||||
let order = '';
|
||||
let params;
|
||||
let stmt = new ParameterizedSQL(
|
||||
`SELECT i.name, i.id, p.id packagingFk
|
||||
FROM item i JOIN packaging p ON i.id = p.itemFk`
|
||||
);
|
||||
|
||||
if (filter) {
|
||||
let connector = Self.dataSource.connector;
|
||||
if (filter.where) {
|
||||
if (filter.where.packagingFk) {
|
||||
where = 'WHERE p.id = ?';
|
||||
params = [filter.where.packagingFk];
|
||||
} else {
|
||||
let search = filter.where.name.regexp;
|
||||
where = 'WHERE i.id REGEXP ? OR i.name REGEXP ?';
|
||||
params = [search, search];
|
||||
}
|
||||
}
|
||||
|
||||
limit = connector._buildLimit(null, filter.limit, filter.offset);
|
||||
order = connector.buildOrderBy('Item', filter.order);
|
||||
}
|
||||
|
||||
let query = `SELECT i.name, i.id, p.id packagingFk FROM
|
||||
item i JOIN packaging p ON i.id = p.itemFk ${where} ${order} ${limit}`;
|
||||
return await Self.rawSql(query, params);
|
||||
stmt.merge(Self.buildSuffix(filter, 'i'));
|
||||
return Self.rawStmt(stmt);
|
||||
};
|
||||
};
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
const app = require(`${servicesDir}/ticket/server/server`);
|
||||
|
||||
describe('ticket listPackaging()', () => {
|
||||
it('should call the listPackaging method and return the response', async () => {
|
||||
let filter = {where: {packagingFk: 1}};
|
||||
let response = await app.models.Packaging.listPackaging(filter);
|
||||
|
||||
expect(response[0].name).toBeDefined();
|
||||
expect(response[0].name).toEqual('Gem of Time');
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue