diff --git a/modules/worker/back/methods/department/filter.js b/modules/worker/back/methods/department/filter.js deleted file mode 100644 index 56e6f2490..000000000 --- a/modules/worker/back/methods/department/filter.js +++ /dev/null @@ -1,74 +0,0 @@ -const buildFilter = require('vn-loopback/util/filter').buildFilter; -const mergeFilters = require('vn-loopback/util/filter').mergeFilters; - -module.exports = Self => { - Self.remoteMethodCtx('filter', { - description: 'Find all instances of the model matched by filter from the data source.', - accessType: 'READ', - accepts: [ - { - arg: 'filter', - type: 'Object', - description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string', - http: {source: 'query'} - }, - { - arg: 'search', - type: 'String', - description: `If it's and integer searchs by id, otherwise it searchs by name`, - http: {source: 'query'} - }, - { - arg: 'id', - type: 'Integer', - description: 'The department id', - http: {source: 'query'} - }, - { - arg: 'code', - type: 'String', - description: 'The department code', - http: {source: 'query'} - }, - { - arg: 'name', - type: 'String', - description: 'The department name', - http: {source: 'query'} - } - ], - returns: { - type: ['Object'], - root: true - }, - http: { - path: `/filter`, - verb: 'GET' - } - }); - - Self.filter = async(ctx, filter) => { - let conn = Self.dataSource.connector; - let where = buildFilter(ctx.args, (param, value) => { - switch (param) { - case 'search': - return /^\d+$/.test(value) - ? {'id': value} - : {or: [ - {'code': {like: `%${value}%`}}, - {'name': {like: `%${value}%`}} - ]}; - case 'id': - return {'id': value}; - case 'code': - return {'code': value}; - case 'name': - return {'name': {like: `%${value}%`}}; - } - }); - - filter = mergeFilters(ctx.args.filter, {where}); - const departments = await Self.app.models.Department.find(filter); - return departments; - }; -}; diff --git a/modules/worker/back/methods/department/getLeaves.js b/modules/worker/back/methods/department/getLeaves.js index ae6aa0f0c..566bbffad 100644 --- a/modules/worker/back/methods/department/getLeaves.js +++ b/modules/worker/back/methods/department/getLeaves.js @@ -25,6 +25,7 @@ module.exports = Self => { `CALL department_getLeaves(?, ?)`, [parentId, search] ); + let map = new Map(); for (let node of res) { if (!map.has(node.parentFk)) diff --git a/modules/worker/back/methods/department/specs/getLeaves.spec.js b/modules/worker/back/methods/department/specs/getLeaves.spec.js new file mode 100644 index 000000000..4ebadbb02 --- /dev/null +++ b/modules/worker/back/methods/department/specs/getLeaves.spec.js @@ -0,0 +1,18 @@ +const models = require('vn-loopback/server/server').models; + +describe('department getLeaves()', () => { + it('should return the department and the childs containing the search value', async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + let result = await models.Zone.getLeaves(null, '31'); + + expect(result.length).toEqual(1); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/worker/front/department/descriptor/index.spec.js b/modules/worker/front/department/descriptor/index.spec.js new file mode 100644 index 000000000..305ebcc18 --- /dev/null +++ b/modules/worker/front/department/descriptor/index.spec.js @@ -0,0 +1,26 @@ +import './index.js'; + +describe('vnWorkerDepartmentDescriptor', () => { + let controller; + let $httpBackend; + + beforeEach(ngModule('worker')); + + beforeEach(inject(($componentController, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + controller = $componentController('vnWorkerDepartmentDescriptor', {$element: null}); + })); + + describe('loadData()', () => { + it(`should perform a get query to store the department data into the controller`, () => { + const id = '31'; + const response = 'foo'; + + $httpBackend.expectRoute('GET', `Departments/${id}`).respond(response); + controller.id = id; + $httpBackend.flush(); + + expect(controller.department).toEqual(response); + }); + }); +});