From 09ae91af935ff5b4163b0a88c2ce083b8f42d5b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Se=CC=81rgio=20Ramos?= Date: Fri, 14 Jul 2017 12:17:28 +0100 Subject: [PATCH] feat(portal-api): add branches resolver --- packages/portal-api/lib/data/index.js | 5 ++++ packages/portal-api/test/_mocks/data.js | 26 ++++++++++++------- packages/portal-api/test/_mocks/triton.js | 2 ++ .../portal-api/test/watch/container-pilot.js | 2 +- 4 files changed, 24 insertions(+), 11 deletions(-) diff --git a/packages/portal-api/lib/data/index.js b/packages/portal-api/lib/data/index.js index ec26f654..27fb2e9d 100644 --- a/packages/portal-api/lib/data/index.js +++ b/packages/portal-api/lib/data/index.js @@ -1359,6 +1359,11 @@ class Data extends EventEmitter { return cb(null, Transform.fromService({ service, + branches: service.branches.map((service) => { + return Object.assign({}, service, { + instances: this._instancesFilter(service.instances) + }); + }), instances: this._instancesFilter(service.instance_ids) })); }); diff --git a/packages/portal-api/test/_mocks/data.js b/packages/portal-api/test/_mocks/data.js index 9b5b9d55..1b92efdb 100644 --- a/packages/portal-api/test/_mocks/data.js +++ b/packages/portal-api/test/_mocks/data.js @@ -1,30 +1,36 @@ +'use strict'; + const FindIndex = require('lodash.findindex'); module.exports = ({ deploymentGroups = [], services = [], instances = [] }) => { - const getInstances = serviceId => (opts, cb) => { - cb(null, instances - .filter(instance => { + const getInstances = (serviceId) => { + return (opts, cb) => { + cb(null, instances + .filter((instance) => { return instance.serviceId === serviceId; }) ); + }; }; - const getServices = deploymentGroupId => (opts, cb) => { - cb(null, services - .filter(service => { + const getServices = (deploymentGroupId) => { + return (opts, cb) => { + cb(null, services + .filter((service) => { return service.deploymentGroupId === deploymentGroupId; }) - .map(service => { + .map((service) => { return Object.assign({}, service, { instances: getInstances(service.id) }); }) ); + }; }; const getDeploymentGroups = (opts, cb) => { cb(null, deploymentGroups - .map(dg => { + .map((dg) => { return Object.assign({}, dg, { services: getServices(dg.id) }); @@ -54,8 +60,8 @@ module.exports = ({ deploymentGroups = [], services = [], instances = [] }) => { const serviceIndex = FindIndex(service, ['id', service.id]); const updatedService = Object.assign({}, services[serviceIndex], service); - services[serviceIndex] = updateService; - return updateService; + services[serviceIndex] = updatedService; + return updatedService; }; return { diff --git a/packages/portal-api/test/_mocks/triton.js b/packages/portal-api/test/_mocks/triton.js index f32b8817..cab9d723 100644 --- a/packages/portal-api/test/_mocks/triton.js +++ b/packages/portal-api/test/_mocks/triton.js @@ -1,3 +1,5 @@ +'use strict'; + const Find = require('lodash.find'); module.exports = ({ machines = [], networks = [] }) => { diff --git a/packages/portal-api/test/watch/container-pilot.js b/packages/portal-api/test/watch/container-pilot.js index 1f8b69c1..93358a87 100644 --- a/packages/portal-api/test/watch/container-pilot.js +++ b/packages/portal-api/test/watch/container-pilot.js @@ -10,7 +10,7 @@ const TritonMock = require('../_mocks/triton'); const lab = exports.lab = Lab.script(); const it = lab.it; -const expect = Lab.expect; +// const expect = Lab.expect; it('sets instance health statuses appropriately', (done) => {