From 9bd69baaf166aa575bf396c3f15b6569fa4acb78 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Tue, 7 Aug 2018 11:06:40 +0200 Subject: [PATCH 1/6] #569 ticket tracking back unit tests plus tiny refactor --- .../models/specs/ticket-tracking.spec.js | 24 +++++++++++++++++++ .../ticket/common/models/ticket-tracking.js | 6 ++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 services/ticket/common/models/specs/ticket-tracking.spec.js diff --git a/services/ticket/common/models/specs/ticket-tracking.spec.js b/services/ticket/common/models/specs/ticket-tracking.spec.js new file mode 100644 index 000000000..961d1732c --- /dev/null +++ b/services/ticket/common/models/specs/ticket-tracking.spec.js @@ -0,0 +1,24 @@ +const app = require(`${servicesDir}/ticket/server/server`); + +describe('ticket model TicketTracking', () => { + let ticketTrackingId; + + afterAll(async() => { + await app.models.TicketTracking.destroyById(ticketTrackingId); + }); + + it('should store the worker id into the instance', async() => { + let originalTrackings = await app.models.TicketTracking.find({where: {ticketFk: 1}}); + + expect(originalTrackings.length).toEqual(1); + + await app.models.TicketTracking.create({ticketFk: 1, stateFk: 20}); + let result = await app.models.TicketTracking.find({where: {ticketFk: 1}}); + + let workerFk = result[1].workerFk; + ticketTrackingId = result[1].id; + + expect(result.length).toEqual(2); + expect(workerFk).toEqual(1); + }); +}); diff --git a/services/ticket/common/models/ticket-tracking.js b/services/ticket/common/models/ticket-tracking.js index 5875a7816..45acf7f90 100644 --- a/services/ticket/common/models/ticket-tracking.js +++ b/services/ticket/common/models/ticket-tracking.js @@ -6,9 +6,9 @@ module.exports = function(Self) { Self.observe('before save', async function(ctx) { let models = Self.app.models; let token = ctx.options.accessToken; - let userId = token && token.userId; + let currentUserId = token && token.userId; - let user = await models.Worker.findOne({where: {userFk: userId}}); - ctx.instance.workerFk = user.id; + let worker = await models.Worker.findOne({where: {userFk: currentUserId}}); + ctx.instance.workerFk = worker.id; }); }; From 72766d0759c5cf1630801664213cd46cdbb940d8 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 7 Aug 2018 11:57:11 +0200 Subject: [PATCH 2/6] Added module claim #442 --- client/claim/index.js | 1 + client/claim/routes.json | 36 ++++++++++++++ client/claim/src/index.js | 7 +++ client/claim/src/index/index.html | 80 +++++++++++++++++++++++++++++++ client/claim/src/index/index.js | 65 +++++++++++++++++++++++++ client/claim/src/locale/es.yml | 7 +++ client/claim/src/module.js | 5 ++ client/modules.yml | 1 + client/salix/src/locale/es.yml | 7 +-- client/spliting.js | 4 +- services_tests.js | 25 +++++++--- 11 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 client/claim/index.js create mode 100644 client/claim/routes.json create mode 100644 client/claim/src/index.js create mode 100644 client/claim/src/index/index.html create mode 100644 client/claim/src/index/index.js create mode 100644 client/claim/src/locale/es.yml create mode 100644 client/claim/src/module.js diff --git a/client/claim/index.js b/client/claim/index.js new file mode 100644 index 000000000..8420b1093 --- /dev/null +++ b/client/claim/index.js @@ -0,0 +1 @@ +export * from './src'; diff --git a/client/claim/routes.json b/client/claim/routes.json new file mode 100644 index 000000000..c81f71b89 --- /dev/null +++ b/client/claim/routes.json @@ -0,0 +1,36 @@ +{ + "module": "claim", + "name": "Claims", + "icon": "icon-claims", + "validations": true, + "routes": [ + { + "url": "/claim", + "state": "claim", + "abstract": true, + "component": "ui-view", + "description": "Claims" + }, + { + "url": "/index?q", + "state": "claim.index", + "component": "vn-claim-index", + "description": "Listado" + }, + { + "url": "/:id", + "state": "claim.card", + "abstract": true, + "component": "vn-claim-card" + }, + { + "url": "/summary", + "state": "claim.card.summary", + "component": "vn-claim-summary", + "description": "Summary", + "params": { + "claim": "$ctrl.claim" + } + } + ] +} \ No newline at end of file diff --git a/client/claim/src/index.js b/client/claim/src/index.js new file mode 100644 index 000000000..c7608c145 --- /dev/null +++ b/client/claim/src/index.js @@ -0,0 +1,7 @@ +export * from './module'; + +import './index/'; +/* +import './card'; +import './descriptor'; +import './summary'; */ diff --git a/client/claim/src/index/index.html b/client/claim/src/index/index.html new file mode 100644 index 000000000..b7175f05d --- /dev/null +++ b/client/claim/src/index/index.html @@ -0,0 +1,80 @@ + + +
+
+ + + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
IdSalespersonDateHourAliasProvinceStateAgencyWarehouseInvoiceRoute
{{::ticket.id}}{{::ticket.client.salesPerson.name | dashIfEmpty}}{{::ticket.shipped | date:'dd/MM/yyyy'}}{{::ticket.shipped | date:'HH:mm'}} + + {{::ticket.nickname}} + + {{::ticket.address.province.name}}{{::ticket.tracking.state.name}}{{::ticket.agencyMode.name}}{{::ticket.warehouse.name}}{{::ticket.refFk | dashIfEmpty}}{{::ticket.routeFk | dashIfEmpty}} + + +
+ +
+ + +
+ + + + + \ No newline at end of file diff --git a/client/claim/src/index/index.js b/client/claim/src/index/index.js new file mode 100644 index 000000000..4027f5043 --- /dev/null +++ b/client/claim/src/index/index.js @@ -0,0 +1,65 @@ +import ngModule from '../module'; + +export default class Controller { + constructor($scope) { + this.$ = $scope; + this.ticketSelected = null; + + this.filter = { + include: [ + { + relation: 'address', + scope: { + fields: ['provinceFk'], + include: { + relation: 'province', + scope: { + fields: ['name'] + } + } + } + }, { + relation: 'warehouse', + scope: { + fields: ['name'] + } + }, { + relation: 'agencyMode', + scope: { + fields: ['name'] + } + }, { + relation: 'tracking', + scope: { + fields: ['stateFk'], + include: { + relation: 'state', + scope: { + fields: ['name'] + } + } + } + }, { + relation: 'client', + scope: { + fields: ['salesPersonFk'], + include: { + relation: 'salesPerson', + scope: { + fields: ['name'] + } + } + } + } + ], + order: 'shipped DESC' + }; + } +} + +Controller.$inject = ['$scope']; + +ngModule.component('vnClaimIndex', { + template: require('./index.html'), + controller: Controller +}); diff --git a/client/claim/src/locale/es.yml b/client/claim/src/locale/es.yml new file mode 100644 index 000000000..9799c2a8d --- /dev/null +++ b/client/claim/src/locale/es.yml @@ -0,0 +1,7 @@ +#Ordenar alfabeticamente + + +#sections +Claims: Reclamaciones +List: Listado +Summary: Vista previa \ No newline at end of file diff --git a/client/claim/src/module.js b/client/claim/src/module.js new file mode 100644 index 000000000..14e9efcad --- /dev/null +++ b/client/claim/src/module.js @@ -0,0 +1,5 @@ +import {ng} from 'vendor'; +import 'core'; + +const ngModule = ng.module('claim', ['vnCore']); +export default ngModule; diff --git a/client/modules.yml b/client/modules.yml index 0227e5f7d..ceef9935b 100644 --- a/client/modules.yml +++ b/client/modules.yml @@ -8,3 +8,4 @@ salix: [] #route: [] ticket: [item, client] order: [item, ticket] +claim: [] diff --git a/client/salix/src/locale/es.yml b/client/salix/src/locale/es.yml index 70baa3f2c..27df1e4db 100644 --- a/client/salix/src/locale/es.yml +++ b/client/salix/src/locale/es.yml @@ -5,9 +5,10 @@ Client Frozen: Cliente congelado Client has debt: Cliente con riesgo Client inactive: Cliente inactivo Client not checked: Cliente no comprobado -Clients: Clientes credit: Crédito creditInsurance: Crédito Asegurado +Clients: Clientes +Claims: Reclamaciones Data saved!: ¡Datos guardados! Home: Inicio Items: Artículos @@ -16,13 +17,13 @@ Logout: Cerrar sesión Modules access : Acceso a módulos Notifications: Notificaciones name: Nombre -Orders: Pedidos phone: Teléfono Preview: Vista previa -Production : Producción Profile: Perfil +Production : Producción Push on applications menu: Para abrir un módulo pulsa en el menú de aplicaciones Return to module index: Volver a la página principal del módulo Routes: Rutas What is new: Novedades de la versión Web Account inactive: Sin acceso Web +Orders: Pedidos \ No newline at end of file diff --git a/client/spliting.js b/client/spliting.js index 1699b202f..00f80ce64 100644 --- a/client/spliting.js +++ b/client/spliting.js @@ -12,5 +12,7 @@ export default { ticket: cb => require.ensure([], () => cb(require('ticket'))), order: - cb => require.ensure([], () => cb(require('order'))) + cb => require.ensure([], () => cb(require('order'))), + claim: + cb => require.ensure([], () => cb(require('claim'))) }; diff --git a/services_tests.js b/services_tests.js index c891bab91..05c780f25 100644 --- a/services_tests.js +++ b/services_tests.js @@ -1,3 +1,4 @@ +const fs = require('fs-extra'); process.on('warning', warning => { console.log(warning.name); console.log(warning.message); @@ -18,15 +19,25 @@ let environment = require('gulp-env'); environment(".env.json"); +let serviceList = fs.readdirSync(servicesDir); +let serviceSpecs = [ + 'auth/server/**/*[sS]pec.js' +]; +const exclude = ['auth', 'salix']; + +for (let service of serviceList) { + try { + let serviceDir = fs.readdirSync(`${servicesDir}/${service}`); + for (let file of serviceDir) { + if (file === 'server' && exclude.indexOf(service) == -1) + serviceSpecs.push(`${service}/common/**/*[sS]pec.js`); + } + } catch (e) {} +} + jasmine.loadConfig({ spec_dir: 'services', - spec_files: [ - 'auth/server/**/*[sS]pec.js', - 'client/common/**/*[sS]pec.js', - 'item/common/**/*[sS]pec.js', - 'ticket/common/**/*[sS]pec.js', - 'loopback/common/**/*[sS]pec.js' - ], + spec_files: serviceSpecs, helpers: [ '/services/utils/jasmineHelpers.js' ] From a44719c1ec65770dd33c856a2f0376db6c46cee5 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Tue, 7 Aug 2018 12:17:34 +0200 Subject: [PATCH 3/6] #552 account.js backend unit tests --- .../loopback/common/models/specs/account.spec.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 services/loopback/common/models/specs/account.spec.js diff --git a/services/loopback/common/models/specs/account.spec.js b/services/loopback/common/models/specs/account.spec.js new file mode 100644 index 000000000..97abedd6e --- /dev/null +++ b/services/loopback/common/models/specs/account.spec.js @@ -0,0 +1,15 @@ +const app = require(`${servicesDir}/client/server/server`); + +describe('loopback model Account', () => { + it('should return true if the user has the given role', async() => { + let result = await app.models.Account.hasRole(1, 'employee'); + + expect(result).toBeTruthy(); + }); + + it('should return false if the user doesnt have the given role', async() => { + let result = await app.models.Account.hasRole(1, 'administrator'); + + expect(result).toBeFalsy(); + }); +}); From a06f7fb01f77246265551df954d4daa232bbe5c4 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 7 Aug 2018 12:48:55 +0200 Subject: [PATCH 4/6] added claim list #443 --- client/claim/src/index/index.html | 85 ++++++++++++------------------- client/claim/src/index/index.js | 60 ++++++++-------------- client/claim/src/locale/es.yml | 4 +- client/modules.yml | 2 +- 4 files changed, 56 insertions(+), 95 deletions(-) diff --git a/client/claim/src/index/index.html b/client/claim/src/index/index.html index b7175f05d..3fdc3169c 100644 --- a/client/claim/src/index/index.html +++ b/client/claim/src/index/index.html @@ -1,9 +1,9 @@
@@ -17,64 +17,43 @@
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
IdSalespersonDateHourAliasProvinceStateAgencyWarehouseInvoiceRoute
{{::ticket.id}}{{::ticket.client.salesPerson.name | dashIfEmpty}}{{::ticket.shipped | date:'dd/MM/yyyy'}}{{::ticket.shipped | date:'HH:mm'}} - - {{::ticket.nickname}} - - {{::ticket.address.province.name}}{{::ticket.tracking.state.name}}{{::ticket.agencyMode.name}}{{::ticket.warehouse.name}}{{::ticket.refFk | dashIfEmpty}}{{::ticket.routeFk | dashIfEmpty}} + + + + Id + Client Id + Client + Created + Worker + Observation + Responsible + State + + + + + + {{::claim.id}} + {{::claim.client.id}} + {{::claim.client.name}} + {{::claim.created | date:'dd/MM/yyyy'}} + {{::claim.worker.firstName}} {{::claim.worker.name}} + {{::claim.observation}} + {{::claim.claimResponsible.description}} + {{::claim.claimState.description}} + -
- + + + +
- - - - - - \ No newline at end of file + \ No newline at end of file diff --git a/client/claim/src/index/index.js b/client/claim/src/index/index.js index 4027f5043..3721fb0fa 100644 --- a/client/claim/src/index/index.js +++ b/client/claim/src/index/index.js @@ -8,51 +8,31 @@ export default class Controller { this.filter = { include: [ { - relation: 'address', - scope: { - fields: ['provinceFk'], - include: { - relation: 'province', - scope: { - fields: ['name'] - } - } - } - }, { - relation: 'warehouse', - scope: { - fields: ['name'] - } - }, { - relation: 'agencyMode', - scope: { - fields: ['name'] - } - }, { - relation: 'tracking', - scope: { - fields: ['stateFk'], - include: { - relation: 'state', - scope: { - fields: ['name'] - } - } - } - }, { relation: 'client', scope: { - fields: ['salesPersonFk'], - include: { - relation: 'salesPerson', - scope: { - fields: ['name'] - } - } + fields: ['name'] + } + }, + { + relation: 'worker', + scope: { + fields: ['firstName', 'name'] + } + }, + { + relation: 'claimResponsible', + scope: { + fields: ['description'] + } + }, + { + relation: 'claimState', + scope: { + fields: ['description'] } } ], - order: 'shipped DESC' + order: 'claimStateFk ASC, created DESC' }; } } diff --git a/client/claim/src/locale/es.yml b/client/claim/src/locale/es.yml index 9799c2a8d..fc6b2c490 100644 --- a/client/claim/src/locale/es.yml +++ b/client/claim/src/locale/es.yml @@ -1,5 +1,7 @@ #Ordenar alfabeticamente - +Client Id: Id cliente +Observation: Observación +Responsible: Responsable #sections Claims: Reclamaciones diff --git a/client/modules.yml b/client/modules.yml index ceef9935b..617a08969 100644 --- a/client/modules.yml +++ b/client/modules.yml @@ -8,4 +8,4 @@ salix: [] #route: [] ticket: [item, client] order: [item, ticket] -claim: [] +claim: [item, client] From 6b47787de85f1e6567b97b8f17de3518e2d03853 Mon Sep 17 00:00:00 2001 From: Joan Date: Tue, 7 Aug 2018 13:41:57 +0200 Subject: [PATCH 5/6] dev modules only for developer role --- client/claim/routes.json | 3 ++- client/order/routes.json | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/client/claim/routes.json b/client/claim/routes.json index c81f71b89..153d192bc 100644 --- a/client/claim/routes.json +++ b/client/claim/routes.json @@ -15,7 +15,8 @@ "url": "/index?q", "state": "claim.index", "component": "vn-claim-index", - "description": "Listado" + "description": "Listado", + "acl": ["developer"] }, { "url": "/:id", diff --git a/client/order/routes.json b/client/order/routes.json index 0ec6c93e3..090907c33 100644 --- a/client/order/routes.json +++ b/client/order/routes.json @@ -9,14 +9,14 @@ "state": "order", "abstract": true, "component": "ui-view", - "description": "Orders", - "acl": ["developer"] + "description": "Orders" }, { "url": "/index?q", "state": "order.index", "component": "vn-order-index", - "description": "List" + "description": "List", + "acl": ["developer"] }, { "url": "/:id", From e094fe44562748b66311dd8668cdfe410e00ebd1 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Tue, 7 Aug 2018 15:04:06 +0200 Subject: [PATCH 6/6] #568 ticket-packaging.js Backend unit tests --- .../models/specs/ticket-packaging.spec.js | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 services/ticket/common/models/specs/ticket-packaging.spec.js diff --git a/services/ticket/common/models/specs/ticket-packaging.spec.js b/services/ticket/common/models/specs/ticket-packaging.spec.js new file mode 100644 index 000000000..c1f0f5897 --- /dev/null +++ b/services/ticket/common/models/specs/ticket-packaging.spec.js @@ -0,0 +1,38 @@ +const app = require(`${servicesDir}/ticket/server/server`); + +describe('ticket model TicketTracking', () => { + let ticketTrackingId; + + afterAll(async() => { + await app.models.TicketPackaging.destroyById(ticketTrackingId); + }); + + it('should save a ticketTraing as the quantity is greater than 0', async() => { + let result = await app.models.TicketPackaging.create({ticketFk: 1, quantity: 1, packagingFk: 1}); + + expect(result).toBeTruthy(); + ticketTrackingId = result.id; + }); + + it('should return an error as the quantity is 0', async() => { + let error; + try { + await app.models.TicketPackaging.create({ticketFk: 1, quantity: 0, packagingFk: 1}); + } catch (e) { + error = e; + } + + expect(error.message).toContain('Enter an integer different to zero'); + }); + + it('should return an error as the quantity isnt a number', async() => { + let error; + try { + await app.models.TicketPackaging.create({ticketFk: 1, quantity: 'random string', packagingFk: 1}); + } catch (e) { + error = e; + } + + expect(error.message).toContain('Enter an integer different to zero'); + }); +});