diff --git a/src/cli/diagnostics.js b/src/cli/diagnostics.js index fd1fd6025..9506b8e1a 100644 --- a/src/cli/diagnostics.js +++ b/src/cli/diagnostics.js @@ -38,7 +38,7 @@ class Diagnostics extends BaseCLIHandler { group: [constants.CMD_STRACE_UPDATE] }, { - name: 'microservice-id', alias: 'i', type: String, description: 'Microservice ID', + name: 'microservice-uuid', alias: 'i', type: String, description: 'Microservice UUID', group: [constants.CMD_STRACE_UPDATE, constants.CMD_STRACE_INFO, constants.CMD_STRACE_FTP_POST, constants.CMD_IMAGE_SNAPSHOT_CREATE, constants.CMD_IMAGE_SNAPSHOT_GET] }, @@ -128,16 +128,16 @@ const _executeCase = async function (diagnosticCommand, commandName, f, isUserRe const _changeMicroserviceStraceState = async function (obj) { logger.info(JSON.stringify(obj)); - const enable = AppHelper.validateBooleanCliOptions(obj.enable, obj.disable); - await DiagnosticService.changeMicroserviceStraceState(obj.microserviceId, {enable: enable}, {}, true); - const msg = enable ? 'Microservice strace has been enabled' : 'Microservice strace has been disabled'; + const isEnable = AppHelper.validateBooleanCliOptions(obj.enable, obj.disable); + await DiagnosticService.changeMicroserviceStraceState(obj.microserviceUuid, {enable: isEnable}, {}, true); + const msg = isEnable ? 'Microservice strace has been enabled' : 'Microservice strace has been disabled'; logger.info(msg); }; const _getMicroserviceStraceData = async function (obj) { logger.info(JSON.stringify(obj)); - const result = await DiagnosticService.getMicroserviceStraceData(obj.microserviceId, {format: obj.format}, {}, true); + const result = await DiagnosticService.getMicroserviceStraceData(obj.microserviceUuid, {format: obj.format}, {}, true); logger.info(JSON.stringify(result, null, 2)); logger.info('Microservice strace data has been retrieved successfully.'); }; @@ -145,21 +145,21 @@ const _getMicroserviceStraceData = async function (obj) { const _postMicroserviceStraceDataToFtp = async function (obj) { logger.info(JSON.stringify(obj)); - await DiagnosticService.postMicroserviceStraceDatatoFtp(obj.microserviceId, obj, {}, true); + await DiagnosticService.postMicroserviceStraceDatatoFtp(obj.microserviceUuid, obj, {}, true); logger.info('Strace data has been posted to ftp successfully.'); }; const _postMicroserviceImageSnapshotCreate = async function (obj) { logger.info(JSON.stringify(obj)); - await DiagnosticService.postMicroserviceImageSnapshotCreate(obj.microserviceId, {}, true); + await DiagnosticService.postMicroserviceImageSnapshotCreate(obj.microserviceUuid, {}, true); logger.info('Microservice image snapshot has been created successfully.'); }; const _getMicroserviceImageSnapshot = async function (obj) { logger.info(JSON.stringify(obj)); - const filePath = await DiagnosticService.getMicroserviceImageSnapshot(obj.microserviceId, {}, true); + const filePath = await DiagnosticService.getMicroserviceImageSnapshot(obj.microserviceUuid, {}, true); logger.info('Microservice images path = ' + filePath); }; diff --git a/src/controllers/diagnostic-controller.js b/src/controllers/diagnostic-controller.js index 699a6c382..7512f175e 100644 --- a/src/controllers/diagnostic-controller.js +++ b/src/controllers/diagnostic-controller.js @@ -17,32 +17,30 @@ const AuthDecorator = require('./../decorators/authorization-decorator'); const changeMicroserviceStraceStateEndPoint = async function (req, user) { logger.info("Parameters: " + JSON.stringify(req.body)); - logger.info("Microservice id: " + req.params.id); - return await DiagnosticService.changeMicroserviceStraceState(req.params.id, req.body, user, false); + logger.info("Microservice UUID: " + req.params.uuid); + return await DiagnosticService.changeMicroserviceStraceState(req.params.uuid, req.body, user, false); }; const getMicroserviceStraceDataEndPoint = async function (req, user) { logger.info("Parameters:" + JSON.stringify(req.query)); - logger.info("Microservice id: " + req.params.id); - return await DiagnosticService.getMicroserviceStraceData(req.params.id, req.query, user, false); + logger.info("Microservice UUID: " + req.params.uuid); + return await DiagnosticService.getMicroserviceStraceData(req.params.uuid, req.query, user, false); }; const postMicroserviceStraceDataToFtpEndPoint = async function (req, user) { logger.info("Parameters:" + JSON.stringify(req.body)); - logger.info("Microservice id: " + req.params.id); - return await DiagnosticService.postMicroserviceStraceDatatoFtp(req.params.id, req.body, user, false); + logger.info("Microservice UUID: " + req.params.uuid); + return await DiagnosticService.postMicroserviceStraceDatatoFtp(req.params.uuid, req.body, user, false); }; const createMicroserviceImageSnapshotEndPoint = async function (req, user) { - logger.info("Parameters:" + JSON.stringify(req.body)); - logger.info("Microservice id: " + req.params.id); - return await DiagnosticService.postMicroserviceImageSnapshotCreate(req.params.id, user, false); + logger.info("Microservice UUID: " + req.params.uuid); + return await DiagnosticService.postMicroserviceImageSnapshotCreate(req.params.uuid, user, false); }; const getMicroserviceImageSnapshotEndPoint = async function (req, user) { - logger.info("Parameters:" + JSON.stringify(req.body)); - logger.info("Microservice id: " + req.params.id); - return await DiagnosticService.getMicroserviceImageSnapshot(req.params.id, user, false); + logger.info("Microservice UUID: " + req.params.uuid); + return await DiagnosticService.getMicroserviceImageSnapshot(req.params.uuid, user, false); }; module.exports = { @@ -50,5 +48,5 @@ module.exports = { getMicroserviceStraceDataEndPoint: AuthDecorator.checkAuthToken(getMicroserviceStraceDataEndPoint), postMicroserviceStraceDataToFtpEndPoint: AuthDecorator.checkAuthToken(postMicroserviceStraceDataToFtpEndPoint), createMicroserviceImageSnapshotEndPoint: AuthDecorator.checkAuthToken(createMicroserviceImageSnapshotEndPoint), - getMicroserviceImageSnapshotEndPoint: AuthDecorator.checkAuthToken(getMicroserviceImageSnapshotEndPoint), + getMicroserviceImageSnapshotEndPoint: AuthDecorator.checkAuthToken(getMicroserviceImageSnapshotEndPoint) }; diff --git a/src/controllers/flow-controller.js b/src/controllers/flow-controller.js index ecd9a432b..f66a0cd5e 100644 --- a/src/controllers/flow-controller.js +++ b/src/controllers/flow-controller.js @@ -15,7 +15,7 @@ const logger = require('../logger'); const AuthDecorator = require('./../decorators/authorization-decorator'); const FlowService = require('../services/flow-service'); -const _createFlowEndPoint = async function (req, user) { +const createFlowEndPoint = async function (req, user) { const flow = req.body; logger.info("Parameters:" + JSON.stringify(flow)); @@ -23,40 +23,40 @@ const _createFlowEndPoint = async function (req, user) { return await FlowService.createFlow(flow, user, false) }; -const _getFlowsByUserEndPoint = async function (req, user) { +const getFlowsByUserEndPoint = async function (req, user) { return await FlowService.getUserFlows(user, false) }; -const _getFlowEndPoint = async function (req, user) { +const getFlowEndPoint = async function (req, user) { const flowId = req.params.id; - logger.info("Flow id:" + JSON.stringify(flowId)) + logger.info("Flow id:" + JSON.stringify(flowId)); return await FlowService.getFlowWithTransaction(flowId, user, false) }; -const _updateFlowEndPoint = async function (req, user) { +const updateFlowEndPoint = async function (req, user) { const flow = req.body; const flowId = req.params.id; - logger.info("Parameters:" + JSON.stringify(flow)) - logger.info("Flow id:" + JSON.stringify(flowId)) + logger.info("Parameters:" + JSON.stringify(flow)); + logger.info("Flow id:" + JSON.stringify(flowId)); return await FlowService.updateFlow(flow, flowId, user, false) }; -const _deleteFlowEndPoint = async function (req, user) { +const deleteFlowEndPoint = async function (req, user) { const flowId = req.params.id; - logger.info("Flow id:" + JSON.stringify(flowId)) + logger.info("Flow id:" + JSON.stringify(flowId)); return await FlowService.deleteFlow(flowId, user, false) }; module.exports = { - createFlowEndPoint: AuthDecorator.checkAuthToken(_createFlowEndPoint), - getFlowsByUserEndPoint: AuthDecorator.checkAuthToken(_getFlowsByUserEndPoint), - getFlowEndPoint: AuthDecorator.checkAuthToken(_getFlowEndPoint), - updateFlowEndPoint: AuthDecorator.checkAuthToken(_updateFlowEndPoint), - deleteFlowEndPoint: AuthDecorator.checkAuthToken(_deleteFlowEndPoint) + createFlowEndPoint: AuthDecorator.checkAuthToken(createFlowEndPoint), + getFlowsByUserEndPoint: AuthDecorator.checkAuthToken(getFlowsByUserEndPoint), + getFlowEndPoint: AuthDecorator.checkAuthToken(getFlowEndPoint), + updateFlowEndPoint: AuthDecorator.checkAuthToken(updateFlowEndPoint), + deleteFlowEndPoint: AuthDecorator.checkAuthToken(deleteFlowEndPoint) }; \ No newline at end of file diff --git a/src/routes/diagnostics.js b/src/routes/diagnostics.js index 372828670..d9f512771 100644 --- a/src/routes/diagnostics.js +++ b/src/routes/diagnostics.js @@ -14,13 +14,12 @@ const constants = require('../helpers/constants'); const DiagnosticController = require('../controllers/diagnostic-controller'); const ResponseDecorator = require('../decorators/response-decorator'); const Errors = require('../helpers/errors'); -const ErrorMessages = require('../helpers/error-messages'); const fs = require('fs'); module.exports = [ { method: 'post', - path: '/api/v3/microservices/:id/image-snapshot', + path: '/api/v3/microservices/:uuid/image-snapshot', middleware: async (req, res) => { const successCode = constants.HTTP_CODE_CREATED; @@ -49,7 +48,7 @@ module.exports = [ }, { method: 'get', - path: '/api/v3/microservices/:id/image-snapshot', + path: '/api/v3/microservices/:uuid/image-snapshot', middleware: async (req, res) => { const successCode = constants.HTTP_CODE_SUCCESS; const errorCodes = [ @@ -85,7 +84,7 @@ module.exports = [ }, { method: 'patch', - path: '/api/v3/microservices/:id/strace', + path: '/api/v3/microservices/:uuid/strace', middleware: async (req, res) => { const successCode = constants.HTTP_CODE_NO_CONTENT; @@ -118,7 +117,7 @@ module.exports = [ }, { method: 'get', - path: '/api/v3/microservices/:id/strace', + path: '/api/v3/microservices/:uuid/strace', middleware: async (req, res) => { const successCode = constants.HTTP_CODE_SUCCESS; @@ -147,7 +146,7 @@ module.exports = [ }, { method: 'put', - path: '/api/v3/microservices/:id/strace', + path: '/api/v3/microservices/:uuid/strace', middleware: async (req, res) => { const successCode = constants.HTTP_CODE_NO_CONTENT; const errorCodes = [ diff --git a/test/Controller Testing.postman_collection.json b/test/Controller Testing.postman_collection.json index f18490ce9..0c1d186b1 100644 --- a/test/Controller Testing.postman_collection.json +++ b/test/Controller Testing.postman_collection.json @@ -1,6 +1,6 @@ { "info": { - "_postman_id": "507ec948-6bd6-48ad-9272-ab609e6ce965", + "_postman_id": "f26c12d6-fdb5-4606-841b-de7979fe33f5", "name": "Controller Testing", "description": "iofog-controller collection", "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json" @@ -8,7 +8,6 @@ "item": [ { "name": "User", - "description": "User collection", "item": [ { "name": "Create user", @@ -508,6 +507,7 @@ "response": [] } ], + "description": "User collection", "event": [ { "listen": "prerequest", @@ -533,7 +533,6 @@ }, { "name": "General", - "description": "General collection", "item": [ { "name": "Status", @@ -653,6 +652,7 @@ "response": [] } ], + "description": "General collection", "event": [ { "listen": "prerequest", @@ -678,7 +678,6 @@ }, { "name": "Agent", - "description": "Agent collection", "item": [ { "name": "Create user", @@ -1635,7 +1634,7 @@ "", "var data = JSON.parse(responseBody);", "", - "tests[\"Response error message is valid\"] = data.name === \"ValidationError\" && data.message === \"Uploaded image snapshot file not found\"" + "tests[\"Response error message is valid\"] = data.name === \"ValidationError\" && data.message === \"Invalid content type\"" ], "type": "text/javascript" } @@ -1766,6 +1765,7 @@ "response": [] } ], + "description": "Agent collection", "event": [ { "listen": "prerequest", @@ -1791,7 +1791,6 @@ }, { "name": "Flow", - "description": "Flow collection", "item": [ { "name": "Create user", @@ -2175,6 +2174,7 @@ "response": [] } ], + "description": "Flow collection", "event": [ { "listen": "prerequest", @@ -2200,7 +2200,6 @@ }, { "name": "Catalog", - "description": "Catalog collection", "item": [ { "name": "Create user", @@ -2593,6 +2592,7 @@ "response": [] } ], + "description": "Catalog collection", "event": [ { "listen": "prerequest", @@ -2618,7 +2618,6 @@ }, { "name": "Tunnel", - "description": "Tunnel collection", "item": [ { "name": "Create user", @@ -2959,6 +2958,7 @@ "response": [] } ], + "description": "Tunnel collection", "event": [ { "listen": "prerequest", @@ -2984,7 +2984,6 @@ }, { "name": "Microservices", - "description": "Microservices collection", "item": [ { "name": "Create user", @@ -3759,7 +3758,10 @@ "value": "{{user-token}}" } ], - "body": {}, + "body": { + "mode": "raw", + "raw": "" + }, "url": { "raw": "{{host}}/api/v3/microservices/{{ms-id}}/volume-mapping", "host": [ @@ -4056,6 +4058,7 @@ "response": [] } ], + "description": "Microservices collection", "event": [ { "listen": "prerequest", @@ -4081,7 +4084,6 @@ }, { "name": "Diagnostics", - "description": "Diagnostics collection", "item": [ { "name": "Create user", @@ -4877,6 +4879,7 @@ "response": [] } ], + "description": "Diagnostics collection", "event": [ { "listen": "prerequest", @@ -4902,7 +4905,6 @@ }, { "name": "ioFog", - "description": "ioFog collection", "item": [ { "name": "Create user", @@ -5606,6 +5608,7 @@ "response": [] } ], + "description": "ioFog collection", "event": [ { "listen": "prerequest", @@ -5631,7 +5634,6 @@ }, { "name": "Registries", - "description": "Registries collection", "item": [ { "name": "Create user", @@ -5966,6 +5968,7 @@ "response": [] } ], + "description": "Registries collection", "event": [ { "listen": "prerequest", diff --git a/test/src/controllers/diagnostics-controller.test.js b/test/src/controllers/diagnostics-controller.test.js new file mode 100644 index 000000000..1403afd63 --- /dev/null +++ b/test/src/controllers/diagnostics-controller.test.js @@ -0,0 +1,238 @@ +const {expect} = require('chai'); +const sinon = require('sinon'); + +const DiagnosticController = require('../../../src/controllers/diagnostic-controller'); +const DiagnosticService = require('../../../src/services/diagnostic-service'); + +describe('Diagnostic Controller', () => { + def('subject', () => DiagnosticController); + def('sandbox', () => sinon.createSandbox()); + + afterEach(() => $sandbox.restore()); + + describe('.changeMicroserviceStraceStateEndPoint()', () => { + def('user', () => 'user!'); + def('uuid', () => 'testUuid'); + + def('enable', () => true); + + def('req', () => ({ + params: { + uuid: $uuid + }, + body: { + enable: $enable + } + })); + + def('response', () => Promise.resolve()); + def('subject', () => $subject.changeMicroserviceStraceStateEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(DiagnosticService, 'changeMicroserviceStraceState').returns($response); + }); + + it('calls DiagnosticService.changeMicroserviceStraceState with correct args', async () => { + await $subject; + expect(DiagnosticService.changeMicroserviceStraceState).to.have.been.calledWith($uuid, { + enable: $enable + }, $user, false); + }); + + context('when DiagnosticService#changeMicroserviceStraceState fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when DiagnosticService#changeMicroserviceStraceState succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + }); + + describe('.getMicroserviceStraceDataEndPoint()', () => { + def('user', () => 'user!'); + def('uuid', () => 'testUuid'); + def('format', () => 'string'); + + def('req', () => ({ + params: { + uuid: $uuid + }, + query: { + format: $format + } + })); + def('response', () => Promise.resolve()); + def('subject', () => $subject.getMicroserviceStraceDataEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(DiagnosticService, 'getMicroserviceStraceData').returns($response); + }); + + it('calls DiagnosticService.getMicroserviceStraceData with correct args', async () => { + await $subject; + expect(DiagnosticService.getMicroserviceStraceData).to.have.been.calledWith($uuid, { + format: $format + }, $user, false) + }); + + context('when DiagnosticService#getMicroserviceStraceData fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when DiagnosticService#getMicroserviceStraceData succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + + }); + + describe('.postMicroserviceStraceDataToFtpEndPoint()', () => { + def('user', () => 'user!'); + def('uuid', () => 'testUuid'); + + def('ftpHost', () => 'testHost'); + def('ftpPort', () => 15); + def('ftpPass', () => 'ftpPass'); + def('ftpDestDir', () => 'ftpDestDirectory'); + + def('req', () => ({ + params: { + uuid: $uuid + }, + body: { + ftpHost: $ftpHost, + ftpPort: $ftpPort, + ftpPass: $ftpPass, + ftpDestDir: $ftpDestDir + } + })); + + def('response', () => Promise.resolve()); + def('subject', () => $subject.postMicroserviceStraceDataToFtpEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(DiagnosticService, 'postMicroserviceStraceDatatoFtp').returns($response); + }); + + it('calls DiagnosticService.postMicroserviceStraceDatatoFtp with correct args', async () => { + await $subject; + expect(DiagnosticService.postMicroserviceStraceDatatoFtp).to.have.been.calledWith($uuid, { + ftpHost: $ftpHost, + ftpPort: $ftpPort, + ftpPass: $ftpPass, + ftpDestDir: $ftpDestDir + }, $user, false); + }); + + context('when DiagnosticService#postMicroserviceStraceDatatoFtp fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when DiagnosticService#postMicroserviceStraceDatatoFtp succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + }); + + describe('.createMicroserviceImageSnapshotEndPoint()', () => { + def('user', () => 'user!'); + def('uuid', () => 'testUuid'); + + def('req', () => ({ + params: { + uuid: $uuid + } + })); + + def('response', () => Promise.resolve()); + def('subject', () => $subject.createMicroserviceImageSnapshotEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(DiagnosticService, 'postMicroserviceImageSnapshotCreate').returns($response); + }); + + it('calls DiagnosticService.postMicroserviceImageSnapshotCreate with correct args', async () => { + await $subject; + expect(DiagnosticService.postMicroserviceImageSnapshotCreate).to.have.been.calledWith($uuid, $user, false); + }); + + context('when DiagnosticService#postMicroserviceImageSnapshotCreate fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when DiagnosticService#postMicroserviceImageSnapshotCreate succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + }); + + describe('.getMicroserviceImageSnapshotEndPoint()', () => { + def('user', () => 'user!'); + def('uuid', () => 'testUuid'); + + def('req', () => ({ + params: { + uuid: $uuid + } + })); + + def('response', () => Promise.resolve()); + def('subject', () => $subject.getMicroserviceImageSnapshotEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(DiagnosticService, 'getMicroserviceImageSnapshot').returns($response); + }); + + it('calls DiagnosticService.getMicroserviceImageSnapshot with correct args', async () => { + await $subject; + expect(DiagnosticService.getMicroserviceImageSnapshot).to.have.been.calledWith($uuid, $user, false); + }); + + context('when DiagnosticService.getMicroserviceImageSnapshot fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when DiagnosticService.getMicroserviceImageSnapshot succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + + }); + +}); \ No newline at end of file diff --git a/test/src/controllers/flow-controller.test.js b/test/src/controllers/flow-controller.test.js new file mode 100644 index 000000000..ecb45b2a4 --- /dev/null +++ b/test/src/controllers/flow-controller.test.js @@ -0,0 +1,228 @@ +const {expect} = require('chai'); +const sinon = require('sinon'); + +const FlowController = require('../../../src/controllers/flow-controller'); +const FlowService = require('../../../src/services/flow-service'); + +describe('Flow Controller', () => { + def('subject', () => FlowController); + def('sandbox', () => sinon.createSandbox()); + + afterEach(() => $sandbox.restore()); + + describe('.createFlowEndPoint()', () => { + def('user', () => 'user!'); + + def('name', () => 'testName'); + def('description', () => 'testDescription'); + def('isActivated', () => true); + + def('req', () => ({ + body: { + name: $name, + description: $description, + isActivated: $isActivated + } + })); + + def('response', () => Promise.resolve()); + def('subject', () => $subject.createFlowEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(FlowService, 'createFlow').returns($response); + }); + + it('calls FlowService.createFlow with correct args', async () => { + await $subject; + expect(FlowService.createFlow).to.have.been.calledWith({ + name: $name, + description: $description, + isActivated: $isActivated + }, $user, false); + }); + + context('when FlowService#createFlow fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when FlowService#createFlow succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + }); + + describe('.getFlowsByUserEndPoint()', () => { + def('user', () => 'user!'); + + def('req', () => ({ + body: {} + })); + def('response', () => Promise.resolve()); + def('subject', () => $subject.getFlowsByUserEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(FlowService, 'getUserFlows').returns($response); + }); + + it('calls FlowService.getUserFlows with correct args', async () => { + await $subject; + expect(FlowService.getUserFlows).to.have.been.calledWith($user, false) + }); + + context('when FlowService#getUserFlows fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when FlowService#getUserFlows succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + + }); + + describe('.getFlowEndPoint()', () => { + def('user', () => 'user!'); + def('id', () => 15); + + def('req', () => ({ + params: { + id: $id + } + })); + + def('response', () => Promise.resolve()); + def('subject', () => $subject.getFlowEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(FlowService, 'getFlowWithTransaction').returns($response); + }); + + it('calls FlowService.getFlowWithTransaction with correct args', async () => { + await $subject; + expect(FlowService.getFlowWithTransaction).to.have.been.calledWith($id, $user, false); + }); + + context('when FlowService#getFlowWithTransaction fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when FlowService#getFlowWithTransaction succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + }); + + describe('.updateFlowEndPoint()', () => { + def('user', () => 'user!'); + def('id', () => 15); + + def('name', () => 'updatedTestName'); + def('description', () => 'updatedTestDescription'); + def('isActivated', () => false); + + def('req', () => ({ + params: { + id: $id + }, + body: { + name: $name, + description: $description, + isActivated: $isActivated + } + })); + + def('response', () => Promise.resolve()); + def('subject', () => $subject.updateFlowEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(FlowService, 'updateFlow').returns($response); + }); + + it('calls FlowService.updateFlow with correct args', async () => { + await $subject; + expect(FlowService.updateFlow).to.have.been.calledWith({ + name: $name, + description: $description, + isActivated: $isActivated + }, $id, $user, false); + }); + + context('when FlowService#updateFlow fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when FlowService#updateFlow succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + }); + + describe('.deleteFlowEndPoint()', () => { + def('user', () => 'user!'); + def('id', () => 15); + + def('req', () => ({ + params: { + id: $id + } + })); + + def('response', () => Promise.resolve()); + def('subject', () => $subject.deleteFlowEndPoint($req, $user)); + + beforeEach(() => { + $sandbox.stub(FlowService, 'deleteFlow').returns($response); + }); + + it('calls FlowService.deleteFlow with correct args', async () => { + await $subject; + expect(FlowService.deleteFlow).to.have.been.calledWith($id, $user, false); + }); + + context('when FlowService.deleteFlow fails', () => { + const error = 'Error!'; + + def('response', () => Promise.reject(error)); + + it(`fails with "${error}"`, () => { + return expect($subject).to.be.rejectedWith(error) + }) + }); + + context('when FlowService.deleteFlow succeeds', () => { + it(`succeeds`, () => { + return expect($subject).to.eventually.equal(undefined) + }) + }) + + }); + +}); \ No newline at end of file