Skip to content

Commit 6e81874

Browse files
authored
Feature/445 Unit Tests for central-settlement (#24)
* Initialize test/ * Dummy .test.js files * Restored test/data/ and added rc&sinon modules * istanbul: 1.1.0-alpha.1 & .istanbul.yml * Resolved most issues requested by PR review
1 parent 8af0011 commit 6e81874

9 files changed

Lines changed: 653 additions & 6 deletions

File tree

‎.istanbul.yml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
instrumentation:
2+
include-all-sources: true
3+
excludes: ['**/test/**']
4+
check:
5+
global:
6+
statements: 90
7+
lines: 90
8+
branches: 90
9+
functions: 90
10+
each:
11+
statements: 90
12+
lines: 90
13+
branches: 90
14+
functions: 90

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@
3232
},
3333
"devDependencies": {
3434
"eslint": "^2",
35-
"istanbul": "~0.4.3",
35+
"istanbul": "1.1.0-alpha.1",
36+
"sinon": "^6.1.5",
3637
"swagmock": "~0.0.2",
3738
"tap-xunit": "1.4.0",
3839
"tape": "4.6.2",

‎src/handlers/settlements/{id}.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
const Boom = require('boom')
3737

3838
const settlement = require('../../domain/settlement/index')
39-
// const dataAccess = require('../../../tests/data/settlements/{id}')
4039
const Logger = require('@mojaloop/central-services-shared').Logger
4140
const Path = require('path')
4241

‎src/handlers/settlements/{settlementId}/participants/{participantId}.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
'use strict'
3434

3535
const Boom = require('boom')
36-
const dataAccess = require('../../../../../tests/data/settlements/{settlementId}/participants/{participantId}')
36+
const dataAccess = require('../../../../../test/data/settlements/{settlementId}/participants/{participantId}')
3737
const Logger = require('@mojaloop/central-services-shared').Logger
3838
const Path = require('path')
3939

‎src/handlers/settlements/{settlementId}/participants/{participantId}/accounts/{accountId}.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
'use strict'
2525

2626
const Boom = require('boom')
27-
const dataAccess = require('../../../../../../../tests/data/settlements/{settlementId}/participants/{participantId}/accounts/{accountId}')
27+
const dataAccess = require('../../../../../../../test/data/settlements/{settlementId}/participants/{participantId}/accounts/{accountId}')
2828
const Settlements = require('../../../../../../domain/settlement')
2929

3030
/**

‎test/data/mockgen.js‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*****
2+
License
3+
--------------
4+
Copyright © 2017 Bill & Melinda Gates Foundation
5+
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
10+
11+
Contributors
12+
--------------
13+
This is the official list of the Mojaloop project contributors for this file.
14+
Names of the original copyright holders (individuals or organizations)
15+
should be listed with a '*' in the first column. People who have
16+
contributed from an organization can be listed under the organization
17+
that actually holds the copyright for their contributions (see the
18+
Gates Foundation organization for an example). Those individuals should have
19+
their names indented and be marked with a '-'. Email address can be added
20+
optionally within square brackets <email>.
21+
22+
* Gates Foundation
23+
- Name Surname <name.surname@gatesfoundation.com>
24+
25+
* Valentin Genev <valentin.genev@modusbox.com>
26+
* Deon Botha <deon.botha@modusbox.com>
27+
* Rajiv Mothilal <rajiv.mothilal@modusbox.com>
28+
* Miguel de Barros <miguel.debarros@modusbox.com>
29+
30+
--------------
31+
******/
32+
33+
'use strict'
34+
var Swagmock = require('swagmock')
35+
var Path = require('path')
36+
var apiPath = Path.resolve(__dirname, '../interface/swagger.json')
37+
var mockgen
38+
39+
module.exports = function () {
40+
/**
41+
* Cached mock generator
42+
*/
43+
mockgen = mockgen || Swagmock(apiPath)
44+
return mockgen
45+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
/*****
2+
License
3+
--------------
4+
Copyright © 2017 Bill & Melinda Gates Foundation
5+
The Mojaloop files are made available by the Bill & Melinda Gates Foundation under the Apache License, Version 2.0 (the "License") and you may not use these files except in compliance with the License. You may obtain a copy of the License at
6+
7+
http://www.apache.org/licenses/LICENSE-2.0
8+
9+
Unless required by applicable law or agreed to in writing, the Mojaloop files are distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
10+
11+
Contributors
12+
--------------
13+
This is the official list of the Mojaloop project contributors for this file.
14+
Names of the original copyright holders (individuals or organizations)
15+
should be listed with a '*' in the first column. People who have
16+
contributed from an organization can be listed under the organization
17+
that actually holds the copyright for their contributions (see the
18+
Gates Foundation organization for an example). Those individuals should have
19+
their names indented and be marked with a '-'. Email address can be added
20+
optionally within square brackets <email>.
21+
22+
* Gates Foundation
23+
- Name Surname <name.surname@gatesfoundation.com>
24+
25+
* Valentin Genev <valentin.genev@modusbox.com>
26+
* Deon Botha <deon.botha@modusbox.com>
27+
* Rajiv Mothilal <rajiv.mothilal@modusbox.com>
28+
* Miguel de Barros <miguel.debarros@modusbox.com>
29+
30+
--------------
31+
******/
32+
33+
'use strict'
34+
var Mockgen = require('../../../mockgen.js')
35+
/**
36+
* Operations on /settlements/{settlementId}/participants/{participantId}
37+
*/
38+
module.exports = {
39+
/**
40+
* summary: Acknowledegement of settlement by updating with Settlements Id and Participant Id.
41+
* description:
42+
* parameters: settlementId, participantId, settlementParticipantUpdatePayload
43+
* produces: application/json
44+
* responses: 200, 400, 401, 404, 415, default
45+
* operationId: updateSettlementBySettlementIdParticipantId
46+
*/
47+
put: {
48+
200: function (req, res, callback) {
49+
/**
50+
* Using mock data generator module.
51+
* Replace this by actual data for the api.
52+
*/
53+
Mockgen().responses({
54+
path: '/settlements/{settlementId}/participants/{participantId}',
55+
operation: 'put',
56+
response: '200'
57+
}, callback)
58+
},
59+
400: function (req, res, callback) {
60+
/**
61+
* Using mock data generator module.
62+
* Replace this by actual data for the api.
63+
*/
64+
Mockgen().responses({
65+
path: '/settlements/{settlementId}/participants/{participantId}',
66+
operation: 'put',
67+
response: '400'
68+
}, callback)
69+
},
70+
401: function (req, res, callback) {
71+
/**
72+
* Using mock data generator module.
73+
* Replace this by actual data for the api.
74+
*/
75+
Mockgen().responses({
76+
path: '/settlements/{settlementId}/participants/{participantId}',
77+
operation: 'put',
78+
response: '401'
79+
}, callback)
80+
},
81+
404: function (req, res, callback) {
82+
/**
83+
* Using mock data generator module.
84+
* Replace this by actual data for the api.
85+
*/
86+
Mockgen().responses({
87+
path: '/settlements/{settlementId}/participants/{participantId}',
88+
operation: 'put',
89+
response: '404'
90+
}, callback)
91+
},
92+
415: function (req, res, callback) {
93+
/**
94+
* Using mock data generator module.
95+
* Replace this by actual data for the api.
96+
*/
97+
Mockgen().responses({
98+
path: '/settlements/{settlementId}/participants/{participantId}',
99+
operation: 'put',
100+
response: '415'
101+
}, callback)
102+
},
103+
default: function (req, res, callback) {
104+
/**
105+
* Using mock data generator module.
106+
* Replace this by actual data for the api.
107+
*/
108+
Mockgen().responses({
109+
path: '/settlements/{settlementId}/participants/{participantId}',
110+
operation: 'put',
111+
response: 'default'
112+
}, callback)
113+
}
114+
}
115+
}

0 commit comments

Comments
 (0)