-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(processors): add tests for POST /processors (#217)
* test(processors): add tests for POST /processors
- Loading branch information
Showing
6 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
tests/integration-tests/processors/helpers/requestCreator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
const request = require('supertest'), | ||
expressApp = require('../../../../src/app'); | ||
let app; | ||
module.exports = { | ||
init, | ||
createProcessor | ||
}; | ||
async function init() { | ||
try { | ||
app = await expressApp(); | ||
} catch (err){ | ||
console.log(err); | ||
process.exit(1); | ||
} | ||
} | ||
|
||
function createProcessor(body, headers) { | ||
return request(app).post('/v1/processors') | ||
.send(body) | ||
.set(headers) | ||
.expect(function(res){ | ||
return res; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
const should = require('should'), | ||
nock = require('nock'); | ||
|
||
let validHeaders = { 'Content-Type': 'application/json' }; | ||
const requestSender = require('./helpers/requestCreator'); | ||
describe('Processors api', function() { | ||
this.timeout(5000000); | ||
before(async function () { | ||
await requestSender.init(); | ||
}); | ||
|
||
describe('Good requests', function() { | ||
it('Create processor with type file_download', async () => { | ||
nock('https://authentication.predator.dev').get('/?dl=1').reply(200, | ||
`{ | ||
const uuid = require('uuid/v4'); | ||
module.exports = { | ||
createAuthToken | ||
}; | ||
function createAuthToken(userContext, events, done) { | ||
userContext.vars.token = uuid(); | ||
return done(); | ||
} | ||
}` | ||
); | ||
|
||
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(201); | ||
}); | ||
|
||
it('Create processor with type raw_javascript', async () => { | ||
const requestBody = { | ||
name: 'authentication', | ||
description: 'Creates authorization token and saves it in the context', | ||
type: 'raw_javascript', | ||
javascript: | ||
`{ | ||
const uuid = require('uuid/v4'); | ||
module.exports = { | ||
createAuthToken | ||
}; | ||
function createAuthToken(userContext, events, done) { | ||
userContext.vars.token = uuid(); | ||
return done(); | ||
} | ||
}` | ||
}; | ||
let createProcessorResponse = await requestSender.createProcessor(requestBody, validHeaders); | ||
createProcessorResponse.statusCode.should.eql(201); | ||
}); | ||
}); | ||
|
||
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('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); | ||
}); | ||
}); | ||
}); |