Skip to content

Commit 788253a

Browse files
author
ehennum
committed
client test for error mapping in the Data Service endpoint
1 parent f5c5a45 commit 788253a

File tree

3 files changed

+68
-13
lines changed

3 files changed

+68
-13
lines changed

test-basic-proxy/lib/negative/badExecutionTest.js

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,48 @@ const BadExecution = require("./badExecution.js");
2323
describe('bad execution', function() {
2424
const service = BadExecution.on(testutil.makeClient());
2525

26-
it('error mapping', function (done) {
27-
service.errorMapping()
26+
const test = [
27+
[406, 'Unacceptable1', "Unacceptable in every way"],
28+
[406, 'Unacceptable2', "Unacceptable, that's how you'll stay", "Unacceptable, that's how you'll stay"],
29+
[406, 'Unacceptable2', "Unacceptable, that's how you'll stay", null],
30+
[406, 'Unacceptable2', "Unacceptable, that's how you'll stay", "Unacceptable no matter how near or far"],
31+
[410, 'Absent1', "You may search this wide world over"],
32+
[500, 'Unknown1', null, "Are the stars out tonight?"]
33+
];
34+
35+
function runTest(i, done) {
36+
if (i === test.length) {
37+
done();
38+
}
39+
const testCase = test[i];
40+
41+
const statusCode = testCase[0];
42+
const sentCode = testCase[1];
43+
const mappedMsg = (testCase[2] === null) ? 'Internal Server Error' : testCase[2];
44+
const sentMsg = (testCase.length < 4) ? null : testCase[3];
45+
const mappedCode = (testCase[2] === null) ? 'INTERNAL ERROR' : sentCode;
46+
47+
service.errorMapping(sentCode, sentMsg)
2848
.then(output => {
2949
expect.fail('should not succeed');
3050
done();
3151
})
3252
.catch(err => {
3353
const errorResponse = err.body.errorResponse;
34-
expect(errorResponse.statusCode).to.eql(418);
35-
expect(errorResponse.status).to.eql("Status Message For 418");
36-
expect(errorResponse.messageCode).to.eql('ERROR_MAPPING');
37-
expect(errorResponse.message).to.contain('Test of error mapping');
38-
done();
54+
// console.log(errorResponse);
55+
expect(errorResponse.statusCode).to.eql(statusCode);
56+
expect(errorResponse.status).to.eql(mappedMsg);
57+
expect(errorResponse.messageCode).to.eql(mappedCode);
58+
if (sentMsg !== null) {
59+
const inlineMsg = ': fn.error(null, errCode, errMsg); -- ';
60+
const msgOffset = errorResponse.message.indexOf(inlineMsg) + inlineMsg.length;
61+
expect(errorResponse.message.substring(msgOffset, msgOffset + sentMsg.length)).to.eql(sentMsg);
62+
}
63+
runTest(i + 1, done);
3964
});
65+
}
66+
67+
it('error conditions', function (done) {
68+
runTest(0, done);
4069
});
4170
});
Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,29 @@
11
{
22
"functionName" : "errorMapping",
3-
"errorConditions":[
4-
{
5-
"errorCode": "ERROR_MAPPING",
6-
"httpStatusCode": 418,
7-
"errorMessage":"Status Message For 418"
3+
"params": [ {
4+
"name": "errCode",
5+
"datatype": "string"
6+
}, {
7+
"name": "errMsg",
8+
"datatype": "string",
9+
"nullable": true
10+
} ],
11+
"return": {
12+
"datatype": "jsonDocument",
13+
"nullable": true
14+
},
15+
"errorConditions":[ {
16+
"httpStatusCode": 406,
17+
"errorCode": "Unacceptable1",
18+
"errorMessage": "Unacceptable in every way"
19+
}, {
20+
"httpStatusCode": 406,
21+
"errorCode": "Unacceptable2",
22+
"errorMessage": "Unacceptable, that's how you'll stay"
23+
}, {
24+
"httpStatusCode": 410,
25+
"errorCode": "Absent1",
26+
"errorMessage": "You may search this wide world over"
827
}
928
]
1029
}

test-basic-proxy/ml-modules/negative/badExecution/errorMapping.sjs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,15 @@
1515
*/
1616
'use strict';
1717
// declareUpdate(); // Note: uncomment if changing the database state
18+
var errCode; // string
19+
var errMsg; // string?
1820

19-
fn.error(null, "ERROR_MAPPING", "Test of error mapping");
21+
if (errCode == void 0) {
22+
errCode = 418;
23+
errMsg = 'Status Message For 418';
24+
}
25+
26+
fn.error(null, errCode, errMsg);
2027

2128
const returnValue = "Error should be thrown before execution reaches this line";
2229
returnValue;

0 commit comments

Comments
 (0)