Skip to content

Commit

Permalink
test(custom-js): add tests for GET /processors/{processor_id}
Browse files Browse the repository at this point in the history
  • Loading branch information
NivLipetz committed Nov 9, 2019
1 parent 6ef1abb commit 75562e5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 55 deletions.
12 changes: 10 additions & 2 deletions src/processors/models/processorsManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
}
};
112 changes: 59 additions & 53 deletions tests/integration-tests/processors/processors-test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const should = require('should'),
uuid = require('uuid/v4'),
nock = require('nock');

let validHeaders = { 'Content-Type': 'application/json' };
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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
Expand All @@ -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);
});
});
});
});
Expand Down

0 comments on commit 75562e5

Please sign in to comment.