diff --git a/src/processors/models/processorsManager.js b/src/processors/models/processorsManager.js index f00fd6b25..bf357cac5 100644 --- a/src/processors/models/processorsManager.js +++ b/src/processors/models/processorsManager.js @@ -5,7 +5,8 @@ const uuid = require('uuid'); const logger = require('../../common/logger'), databaseConnector = require('./database/databaseConnector'), common = require('../../common/consts.js'), - fileManager = require('../../tests/models/fileManager.js'); + fileManager = require('../../tests/models/fileManager.js'), + { ERROR_MESSAGES } = require('../../common/consts'); module.exports.createProcessor = async function (processor) { let processorId = uuid.v4(); @@ -29,5 +30,12 @@ module.exports.getAllProcessors = async function(from, limit) { }; module.exports.getProcessor = async function(processorId) { - return databaseConnector.getProcessor(processorId); + const processor = await databaseConnector.getProcessor(processorId); + if (processor) { + return processor; + } else { + const error = new Error(ERROR_MESSAGES.NOT_FOUND); + error.statusCode = 404; + throw error; + } }; diff --git a/tests/integration-tests/processors/processors-test.js b/tests/integration-tests/processors/processors-test.js index 8e642b660..d17a9d7ac 100644 --- a/tests/integration-tests/processors/processors-test.js +++ b/tests/integration-tests/processors/processors-test.js @@ -1,4 +1,5 @@ const should = require('should'), + uuid = require('uuid/v4'), nock = require('nock'); let validHeaders = { 'Content-Type': 'application/json' }; @@ -79,6 +80,10 @@ describe('Processors api', function() { getProcessorResponse.statusCode.should.eql(200); should(getProcessorResponse.body).containDeep(processorData); }); + it('Get non-existent processor by id', async () => { + let getProcessorResponse = await requestSender.getProcessor(uuid(), validHeaders); + getProcessorResponse.statusCode.should.eql(404); + }); }); describe('POST /v1/processors', function () { it('Create processor with type file_download', async () => { @@ -130,55 +135,55 @@ describe('Processors api', function() { }); describe('Bad requests', function () { - it('Create processor with unknown type', async () => { - const requestBody = { - name: 'bad-processor', - description: 'Processor with unknown type', - type: 'unknown' - }; - let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); - createProcessorResponse.statusCode.should.eql(400); - }); - - it('Create processor with type file_download and no url', async () => { - const requestBody = { - name: 'download-me', - description: 'Processor with no file url', - type: 'file_download' - }; - let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); - createProcessorResponse.statusCode.should.eql(400); - }); - - it('Create processor with type raw_javascript and no js', async () => { - const requestBody = { - name: 'javascript-me', - description: 'Processor with no js', - type: 'raw_javascript', - file_url: 'bad' - }; - let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); - createProcessorResponse.statusCode.should.eql(400); + describe('POST /v1/processors', function () { + it('Create processor with unknown type', async () => { + const requestBody = { + name: 'bad-processor', + description: 'Processor with unknown type', + type: 'unknown' + }; + let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); + createProcessorResponse.statusCode.should.eql(400); + }); + it('Create processor with type file_download and no url', async () => { + const requestBody = { + name: 'download-me', + description: 'Processor with no file url', + type: 'file_download' + }; + let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); + createProcessorResponse.statusCode.should.eql(400); + }); + it('Create processor with type raw_javascript and no js', async () => { + const requestBody = { + name: 'javascript-me', + description: 'Processor with no js', + type: 'raw_javascript', + file_url: 'bad' + }; + let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); + createProcessorResponse.statusCode.should.eql(400); + }); }); }); describe('Sad requests', function () { - it('Create processor with type file_download and invalid file_url', async () => { - nock('https://authentication.predator.dev').get('/?dl=1').replyWithError('error downloading file'); - - const requestBody = { - name: 'authentication', - description: 'Creates authorization token and saves it in the context', - type: 'file_download', - file_url: 'https://authentication.predator.dev/?dl=1' - }; - let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); - createProcessorResponse.statusCode.should.eql(422); - }); + describe('POST /v1/processors', function () { + it('Create processor with type file_download and invalid file_url', async () => { + nock('https://authentication.predator.dev').get('/?dl=1').replyWithError('error downloading file'); - it('Create processor with type file_download and invalid js syntax', async () => { - nock('https://authentication.predator.dev').get('/?dl=1').reply(200, - `{ + const requestBody = { + name: 'authentication', + description: 'Creates authorization token and saves it in the context', + type: 'file_download', + file_url: 'https://authentication.predator.dev/?dl=1' + }; + let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); + createProcessorResponse.statusCode.should.eql(422); + }); + it('Create processor with type file_download and invalid js syntax', async () => { + nock('https://authentication.predator.dev').get('/?dl=1').reply(200, + `{ const uuid = require('uuid/v4'); module.exports = { createAuthToken @@ -191,15 +196,16 @@ describe('Processors api', function() { this is not valid javascript }` - ); - const requestBody = { - name: 'authentication', - description: 'Creates authorization token and saves it in the context', - type: 'file_download', - file_url: 'https://authentication.predator.dev/?dl=1' - }; - let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); - createProcessorResponse.statusCode.should.eql(422); + ); + const requestBody = { + name: 'authentication', + description: 'Creates authorization token and saves it in the context', + type: 'file_download', + file_url: 'https://authentication.predator.dev/?dl=1' + }; + let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); + createProcessorResponse.statusCode.should.eql(422); + }); }); }); });