-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
DIV-3491 - create DN case for integration testing (#1)
* WIP: over to Hosain * DIV-3491 - included missing require and removes `this` reference Also ignored idea files * Organising dependencies * Reusing test method between DN and AOS cases * DIV-3491 - rethrow error if there is an issue creating a case * DIV-3491 - create case should get caseData instead of file path * Addressed comments from code review and added Travis CI files. Also added test case and adjusted tests after changes were made to source code. * Using resolves for returning a promise from Sinon
- Loading branch information
Showing
8 changed files
with
883 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,3 +59,5 @@ typings/ | |
|
||
# next.js build output | ||
.next | ||
|
||
.idea/ |
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 @@ | ||
8.12.0 |
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 @@ | ||
language: node_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,93 @@ | ||
const util = require('util'); | ||
const url = require('url'); | ||
const request = require('request-promise-native'); | ||
const logger = require('@hmcts/nodejs-logging').Logger.getLogger(__filename); | ||
|
||
const createAosCase = (params, proxy) => { | ||
params.eventId = 'testAosAwaiting'; | ||
return _createCase(params, proxy); | ||
}; | ||
|
||
const createDnCase = (params, proxy) => { | ||
params.eventId = 'testAwaitingDecreeNisi'; | ||
return _createCase(params, proxy); | ||
}; | ||
|
||
function _createCase(params, proxy) { | ||
return _createCaseForUser(params, proxy) | ||
.then(createCaseResponse => { | ||
logger.info(`Created case ${createCaseResponse.id}`); | ||
return _updateCase(params, createCaseResponse.id, params.eventId, proxy); | ||
}) | ||
.catch(error => { | ||
logger.info(`Error creating case: ${util.inspect(error)}`); | ||
throw error; | ||
}); | ||
} | ||
|
||
function _createCaseForUser(params, proxy) { | ||
const uri = `${params.baseUrl}/casemaintenance/version/1/submit`; | ||
const headers = { | ||
Authorization: `Bearer ${params.authToken}`, | ||
'Content-Type': 'application/json' | ||
}; | ||
|
||
const options = { | ||
uri, | ||
headers, | ||
body: params.caseData, | ||
json: true | ||
}; | ||
|
||
if (proxy) { | ||
Object.assign(options, _setupProxy(proxy)); | ||
} | ||
return request.post(options); | ||
}; | ||
|
||
const _updateCase = (params, caseId, eventId, proxy) => { | ||
logger.info(`Issuing event ${eventId} against case ${caseId}.`); | ||
const baseUrl = params.baseUrl; | ||
const uri = `${baseUrl}/casemaintenance/version/1/updateCase/${caseId}/${eventId}`; | ||
const headers = { | ||
Authorization: `Bearer ${params.authToken}`, | ||
'Content-Type': 'application/json' | ||
}; | ||
|
||
const options = { | ||
uri, | ||
headers, | ||
body: {}, | ||
json: true | ||
}; | ||
|
||
if (proxy) { | ||
Object.assign(options, _setupProxy(proxy)); | ||
} | ||
return request.post(options); | ||
}; | ||
|
||
const _setupProxy = proxy => { | ||
const proxyUrl = url.parse(proxy); | ||
|
||
let proxyOptions = {}; | ||
|
||
if (proxyUrl.protocol.indexOf('socks') >= 0) { | ||
proxyOptions = { | ||
strictSSL: false, | ||
agentClass: socksAgent, | ||
socksHost: proxyUrl.hostname || 'localhost', | ||
socksPort: proxyUrl.port || 9000 | ||
}; | ||
} else { | ||
proxyOptions = { proxy: proxyUrl.href }; | ||
} | ||
|
||
return proxyOptions; | ||
}; | ||
|
||
|
||
module.exports = { | ||
createAosCase, | ||
createDnCase | ||
}; |
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,29 @@ | ||
{ | ||
"name": "@hmcts/div-test-harness", | ||
"version": "1.0.0", | ||
"description": "Module used for functional tests to create a case and progress it to a certain state so that other tests can build upon it", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "mocha" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/hmcts/div-test-harness.git" | ||
}, | ||
"author": "", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/hmcts/div-test-harness/issues" | ||
}, | ||
"homepage": "https://github.com/hmcts/div-test-harness#readme", | ||
"devDependencies": { | ||
"mocha": "^5.2.0", | ||
"chai": "^4.2.0", | ||
"sinon": "^7.1.1" | ||
}, | ||
"dependencies": { | ||
"@hmcts/nodejs-logging": "^3.0.0", | ||
"request": "^2.88.0", | ||
"request-promise-native": "^1.0.5" | ||
} | ||
} |
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,41 @@ | ||
const sinon = require('sinon'); | ||
const fs = require('fs'); | ||
const expect = require('chai').expect; | ||
const request = require('request-promise-native'); | ||
const divTestHarness = require('../index.js'); | ||
|
||
describe('index.js', function () { | ||
beforeEach(function () { | ||
sinon.stub(request, 'post').resolves({ id: '123' }); | ||
}); | ||
|
||
afterEach(function () { | ||
request.post.restore(); | ||
}); | ||
|
||
it('should create a DN case', function () { | ||
const proxy = ''; | ||
const params = { | ||
baseUrl: '', | ||
authToken: '', | ||
caseData: fs.readFileSync('test/test.json') | ||
}; | ||
return divTestHarness.createDnCase(params, proxy) | ||
.then(() => { | ||
expect(request.post.callCount).to.equal(2); | ||
}); | ||
}); | ||
|
||
it('should create a AOS case', function () { | ||
const proxy = ''; | ||
const params = { | ||
baseUrl: '', | ||
authToken: '', | ||
caseData: fs.readFileSync('test/test.json') | ||
}; | ||
return divTestHarness.createAosCase(params, proxy) | ||
.then(() => { | ||
expect(request.post.callCount).to.equal(2); | ||
}); | ||
}); | ||
}); |
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 @@ | ||
{} |
Oops, something went wrong.