diff --git a/client/ticket/src/package/index.html b/client/ticket/src/package/index.html
index 785eeb3b2..462dec31d 100644
--- a/client/ticket/src/package/index.html
+++ b/client/ticket/src/package/index.html
@@ -21,6 +21,7 @@
label="Package"
show-field="name"
value-field="packagingFk"
+ where="{or: [{id: {like: '%search%'}}, {name: {like: '%search%'}}]}"
field="package.packagingFk">
{{id}} : {{name}}
diff --git a/client/ticket/src/summary/index.js b/client/ticket/src/summary/index.js
index 645ce1185..2d9bd797f 100644
--- a/client/ticket/src/summary/index.js
+++ b/client/ticket/src/summary/index.js
@@ -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)
diff --git a/client/ticket/src/summary/index.spec.js b/client/ticket/src/summary/index.spec.js
new file mode 100644
index 000000000..eafcd7e01
--- /dev/null
+++ b/client/ticket/src/summary/index.spec.js
@@ -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)');
+ });
+ });
+ });
+});
diff --git a/services/loopback/common/methods/sale/specs/updateQuantity.spec.js b/services/loopback/common/methods/sale/specs/updateQuantity.spec.js
new file mode 100644
index 000000000..9dd56a3c7
--- /dev/null
+++ b/services/loopback/common/methods/sale/specs/updateQuantity.spec.js
@@ -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);
+ });
+});
diff --git a/services/loopback/common/methods/ticket/specs/componentUpdate.spec.js b/services/loopback/common/methods/ticket/specs/componentUpdate.spec.js
index 7f5a1bd77..4b00264b6 100644
--- a/services/loopback/common/methods/ticket/specs/componentUpdate.spec.js
+++ b/services/loopback/common/methods/ticket/specs/componentUpdate.spec.js
@@ -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');
});
});
diff --git a/services/ticket/common/methods/packaging/listPackaging.js b/services/ticket/common/methods/packaging/listPackaging.js
index 9aa1ad678..8e83a60a5 100644
--- a/services/ticket/common/methods/packaging/listPackaging.js
+++ b/services/ticket/common/methods/packaging/listPackaging.js
@@ -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);
};
};
diff --git a/services/ticket/common/methods/packaging/specs/listPackaging.spec.js b/services/ticket/common/methods/packaging/specs/listPackaging.spec.js
new file mode 100644
index 000000000..3b503d833
--- /dev/null
+++ b/services/ticket/common/methods/packaging/specs/listPackaging.spec.js
@@ -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');
+ });
+});
+