account-lookup-service 15.6.0-iso.2 → 15.6.0-iso.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.circleci/config.yml +1 -1
- package/.ncurc.yaml +1 -2
- package/audit-ci.jsonc +3 -1
- package/jest.config.js +2 -0
- package/package.json +14 -16
- package/src/constants.js +2 -1
- package/src/domain/participants/participants.js +173 -130
- package/src/domain/parties/getPartiesByTypeAndID.js +15 -14
- package/src/domain/parties/parties.js +13 -12
- package/src/domain/parties/utils.js +13 -6
- package/src/domain/timeout/dto.js +4 -10
- package/src/handlers/index.js +4 -4
- package/src/handlers/monitoring/index.js +1 -1
- package/src/interface/api-swagger-iso20022-parties.yaml +7 -6
- package/src/interface/api-swagger.yaml +7 -6
- package/src/interface/fspiop-rest-v2.0-ISO20022_parties.yaml +2043 -1583
- package/src/lib/config.js +1 -1
- package/src/lib/index.js +1 -2
- package/src/models/participantEndpoint/facade.js +21 -19
- package/src/plugins.js +20 -9
- package/src/server.js +3 -19
- package/test/fixtures/index.js +30 -6
- package/test/fixtures/iso.js +1 -1
- package/test/unit/api/health.test.js +3 -0
- package/test/unit/api/participants/participants.test.js +5 -7
- package/test/unit/api/participants/{Type}/{ID}/{SubId}.test.js +0 -3
- package/test/unit/api/participants/{Type}/{ID}.test.js +0 -3
- package/test/unit/api/participants.test.js +36 -3
- package/test/unit/domain/participants/participants.test.js +76 -48
- package/test/unit/domain/parties/parties.test.js +3 -3
- package/test/unit/domain/parties/utils.test.js +60 -0
- package/test/unit/domain/timeout/dto.test.js +1 -2
- package/test/unit/lib/TransformFacades.test.js +2 -1
- package/test/unit/lib/config.test.js +7 -0
- package/test/unit/models/participantEndpoint/facade.test.js +25 -8
- package/test/unit/plugins.test.js +4 -2
- package/test/util/apiClients/BasicApiClient.js +2 -2
- package/src/handlers/monitoring/plugins/metrics.js +0 -48
- package/src/lib/requestLogger.js +0 -54
- package/src/metrics/handler.js +0 -33
- package/src/metrics/plugin.js +0 -52
- package/src/metrics/routes.js +0 -43
- package/test/unit/lib/requestLogger.test.js +0 -115
package/src/lib/config.js
CHANGED
@@ -167,7 +167,7 @@ const config = {
|
|
167
167
|
INSTRUMENTATION_METRICS_LABELS: RC.INSTRUMENTATION.METRICS.labels,
|
168
168
|
INSTRUMENTATION_METRICS_CONFIG: RC.INSTRUMENTATION.METRICS.config,
|
169
169
|
JWS_SIGN: RC.ENDPOINT_SECURITY.JWS.JWS_SIGN,
|
170
|
-
FSPIOP_SOURCE_TO_SIGN: RC.
|
170
|
+
FSPIOP_SOURCE_TO_SIGN: RC.HUB_PARTICIPANT.NAME,
|
171
171
|
JWS_SIGNING_KEY_PATH: RC.ENDPOINT_SECURITY.JWS.JWS_SIGNING_KEY_PATH,
|
172
172
|
API_DOC_ENDPOINTS_ENABLED: RC.API_DOC_ENDPOINTS_ENABLED || false,
|
173
173
|
FEATURE_ENABLE_EXTENDED_PARTY_ID_TYPE: RC.FEATURE_ENABLE_EXTENDED_PARTY_ID_TYPE || false,
|
package/src/lib/index.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
const { loggerFactory
|
1
|
+
const { loggerFactory } = require('@mojaloop/central-services-logger/src/contextLogger')
|
2
2
|
const { TransformFacades } = require('@mojaloop/ml-schema-transformer-lib')
|
3
3
|
|
4
4
|
const logger = loggerFactory('ALS') // global logger without context
|
@@ -6,6 +6,5 @@ const logger = loggerFactory('ALS') // global logger without context
|
|
6
6
|
module.exports = {
|
7
7
|
logger,
|
8
8
|
loggerFactory,
|
9
|
-
asyncStorage,
|
10
9
|
TransformFacades
|
11
10
|
}
|
@@ -33,7 +33,9 @@ const ErrorHandler = require('@mojaloop/central-services-error-handling')
|
|
33
33
|
const JwsSigner = require('@mojaloop/sdk-standard-components').Jws.signer
|
34
34
|
const Metrics = require('@mojaloop/central-services-metrics')
|
35
35
|
const Config = require('../../lib/config')
|
36
|
+
const { logger } = require('../../lib')
|
36
37
|
const { hubNameRegex } = require('../../lib/util').hubNameConfig
|
38
|
+
|
37
39
|
const uriRegex = /(?:^.*)(\/(participants|parties|quotes|transfers)(\/.*)*)$/
|
38
40
|
|
39
41
|
/**
|
@@ -47,7 +49,7 @@ const defineJwsSigner = (config, headers, requestedEndpoint) => {
|
|
47
49
|
// We need below 2 headers for JWS
|
48
50
|
headers[Enums.Http.Headers.FSPIOP.HTTP_METHOD] = headers[Enums.Http.Headers.FSPIOP.HTTP_METHOD] || Enums.Http.RestMethods.PUT
|
49
51
|
headers[Enums.Http.Headers.FSPIOP.URI] = headers[Enums.Http.Headers.FSPIOP.URI] || uriRegex.exec(requestedEndpoint)[1]
|
50
|
-
|
52
|
+
logger.debug('JWS is enabled, getting JwsSigner')
|
51
53
|
jwsSigner = new JwsSigner({
|
52
54
|
logger: Logger,
|
53
55
|
signingKey: config.JWS_SIGNING_KEY
|
@@ -83,10 +85,10 @@ exports.sendRequest = async (headers, requestedParticipant, endpointType, method
|
|
83
85
|
try {
|
84
86
|
requestedEndpoint = await Util.Endpoints.getEndpoint(Config.SWITCH_ENDPOINT, requestedParticipant, endpointType, options || undefined)
|
85
87
|
histTimerEndGetParticipantEndpoint({ success: true, endpointType, participantName: requestedParticipant })
|
86
|
-
|
88
|
+
logger.debug('participant requestedEndpoint and endpointType: ', { requestedEndpoint, endpointType })
|
87
89
|
} catch (err) {
|
88
90
|
histTimerEndGetParticipantEndpoint({ success: false, endpointType, participantName: requestedParticipant })
|
89
|
-
|
91
|
+
logger.warn('error in getEndpoint: ', err)
|
90
92
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
91
93
|
}
|
92
94
|
|
@@ -102,9 +104,7 @@ exports.sendRequest = async (headers, requestedParticipant, endpointType, method
|
|
102
104
|
content: Config.PROTOCOL_VERSIONS.CONTENT.DEFAULT.toString(),
|
103
105
|
accept: Config.PROTOCOL_VERSIONS.ACCEPT.DEFAULT.toString()
|
104
106
|
}
|
105
|
-
const
|
106
|
-
|
107
|
-
const resp = await Util.Request.sendRequest({
|
107
|
+
const params = {
|
108
108
|
url: requestedEndpoint,
|
109
109
|
headers,
|
110
110
|
source: headers[Enums.Http.Headers.FSPIOP.SOURCE],
|
@@ -113,17 +113,19 @@ exports.sendRequest = async (headers, requestedParticipant, endpointType, method
|
|
113
113
|
payload,
|
114
114
|
responseType: Enums.Http.ResponseTypes.JSON,
|
115
115
|
span,
|
116
|
-
jwsSigner,
|
117
116
|
protocolVersions,
|
118
117
|
hubNameRegex,
|
119
118
|
apiType: Config.API_TYPE
|
120
|
-
}
|
119
|
+
}
|
120
|
+
logger.debug('participant - sendRequest params:', { params })
|
121
|
+
params.jwsSigner = defineJwsSigner(Config, headers, requestedEndpoint)
|
122
|
+
|
123
|
+
const resp = await Util.Request.sendRequest(params)
|
121
124
|
histTimerEndSendRequestToParticipant({ success: true, endpointType, participantName: requestedParticipant })
|
122
125
|
return resp
|
123
126
|
} catch (err) {
|
124
127
|
histTimerEndSendRequestToParticipant({ success: false, endpointType, participantName: requestedParticipant })
|
125
|
-
|
126
|
-
|
128
|
+
logger.warn('error in sendRequest: ', err)
|
127
129
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
128
130
|
}
|
129
131
|
}
|
@@ -148,7 +150,7 @@ exports.validateParticipant = async (fsp) => {
|
|
148
150
|
return resp
|
149
151
|
} catch (err) {
|
150
152
|
histTimerEnd({ success: false })
|
151
|
-
|
153
|
+
logger.warn('error in validateParticipant: ', err)
|
152
154
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
153
155
|
}
|
154
156
|
}
|
@@ -188,7 +190,7 @@ exports.sendErrorToParticipant = async (participantName, endpointType, errorInfo
|
|
188
190
|
histTimerEndGetParticipantEndpoint({ success: true, endpointType, participantName })
|
189
191
|
} catch (err) {
|
190
192
|
histTimerEndGetParticipantEndpoint({ success: false, endpointType, participantName })
|
191
|
-
|
193
|
+
logger.warn('error in getEndpoint: ', err)
|
192
194
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
193
195
|
}
|
194
196
|
|
@@ -212,10 +214,7 @@ exports.sendErrorToParticipant = async (participantName, endpointType, errorInfo
|
|
212
214
|
clonedHeaders[Enums.Http.Headers.FSPIOP.SOURCE] = Config.HUB_NAME
|
213
215
|
}
|
214
216
|
|
215
|
-
|
216
|
-
const jwsSigner = defineJwsSigner(Config, clonedHeaders, requesterErrorEndpoint)
|
217
|
-
|
218
|
-
await Util.Request.sendRequest({
|
217
|
+
const params = {
|
219
218
|
url: requesterErrorEndpoint,
|
220
219
|
headers: clonedHeaders,
|
221
220
|
source: clonedHeaders[Enums.Http.Headers.FSPIOP.SOURCE],
|
@@ -225,14 +224,17 @@ exports.sendErrorToParticipant = async (participantName, endpointType, errorInfo
|
|
225
224
|
responseType: Enums.Http.ResponseTypes.JSON,
|
226
225
|
hubNameRegex,
|
227
226
|
span,
|
228
|
-
jwsSigner,
|
229
227
|
protocolVersions,
|
230
228
|
apiType: Config.API_TYPE
|
231
|
-
}
|
229
|
+
}
|
230
|
+
logger.debug('participant - sendErrorToParticipant params: ', { params })
|
231
|
+
params.jwsSigner = defineJwsSigner(Config, clonedHeaders, requesterErrorEndpoint)
|
232
|
+
|
233
|
+
await Util.Request.sendRequest(params)
|
232
234
|
histTimerEndSendRequestToParticipant({ success: true, endpointType, participantName })
|
233
235
|
} catch (err) {
|
234
236
|
histTimerEndSendRequestToParticipant({ success: false, endpointType, participantName })
|
235
|
-
|
237
|
+
logger.warn('error in sendErrorToParticipant: ', err)
|
236
238
|
throw ErrorHandler.Factory.reformatFSPIOPError(err)
|
237
239
|
}
|
238
240
|
}
|
package/src/plugins.js
CHANGED
@@ -24,16 +24,22 @@
|
|
24
24
|
******/
|
25
25
|
'use strict'
|
26
26
|
|
27
|
-
const Config = require('./lib/config')
|
28
27
|
const Inert = require('@hapi/inert')
|
29
28
|
const Vision = require('@hapi/vision')
|
30
29
|
const Blipp = require('blipp')
|
31
30
|
const ErrorHandling = require('@mojaloop/central-services-error-handling')
|
32
|
-
const
|
33
|
-
const
|
34
|
-
|
35
|
-
|
36
|
-
|
31
|
+
const MetricsPlugin = require('@mojaloop/central-services-metrics').plugin
|
32
|
+
const {
|
33
|
+
APIDocumentation,
|
34
|
+
FSPIOPHeaderValidation,
|
35
|
+
HapiEventPlugin,
|
36
|
+
HapiRawPayload,
|
37
|
+
OpenapiBackendValidator,
|
38
|
+
loggingPlugin
|
39
|
+
} = require('@mojaloop/central-services-shared').Util.Hapi
|
40
|
+
|
41
|
+
const { logger } = require('./lib')
|
42
|
+
const Config = require('./lib/config')
|
37
43
|
|
38
44
|
const registerPlugins = async (server, openAPIBackend) => {
|
39
45
|
await server.register(OpenapiBackendValidator)
|
@@ -121,10 +127,10 @@ const registerPlugins = async (server, openAPIBackend) => {
|
|
121
127
|
Inert,
|
122
128
|
Vision,
|
123
129
|
ErrorHandling,
|
124
|
-
|
125
|
-
|
130
|
+
HapiRawPayload,
|
131
|
+
HapiEventPlugin,
|
126
132
|
{
|
127
|
-
plugin:
|
133
|
+
plugin: FSPIOPHeaderValidation.plugin,
|
128
134
|
options: getOptionsForFSPIOPHeaderValidation()
|
129
135
|
}
|
130
136
|
])
|
@@ -132,6 +138,11 @@ const registerPlugins = async (server, openAPIBackend) => {
|
|
132
138
|
if (Config.DISPLAY_ROUTES === true) {
|
133
139
|
await server.register([Blipp])
|
134
140
|
}
|
141
|
+
|
142
|
+
await server.register({
|
143
|
+
plugin: loggingPlugin,
|
144
|
+
options: { log: logger }
|
145
|
+
})
|
135
146
|
}
|
136
147
|
|
137
148
|
module.exports = {
|
package/src/server.js
CHANGED
@@ -23,7 +23,6 @@
|
|
23
23
|
******/
|
24
24
|
'use strict'
|
25
25
|
|
26
|
-
const { randomUUID } = require('node:crypto')
|
27
26
|
const Hapi = require('@hapi/hapi')
|
28
27
|
const Boom = require('@hapi/boom')
|
29
28
|
|
@@ -37,7 +36,6 @@ const { name, version } = require('../package.json')
|
|
37
36
|
const Db = require('./lib/db')
|
38
37
|
const Util = require('./lib/util')
|
39
38
|
const Plugins = require('./plugins')
|
40
|
-
const RequestLogger = require('./lib/requestLogger')
|
41
39
|
const Migrator = require('./lib/migrator')
|
42
40
|
const APIHandlers = require('./api')
|
43
41
|
const Routes = require('./api/routes')
|
@@ -104,23 +102,6 @@ const createServer = async (port, api, routes, isAdmin, proxyCacheConfig, proxyM
|
|
104
102
|
}
|
105
103
|
}
|
106
104
|
|
107
|
-
await server.ext([
|
108
|
-
{
|
109
|
-
type: 'onPreHandler',
|
110
|
-
method: (request, h) => {
|
111
|
-
request.headers.traceid = request.headers.traceid || randomUUID()
|
112
|
-
RequestLogger.logRequest(request)
|
113
|
-
return h.continue
|
114
|
-
}
|
115
|
-
},
|
116
|
-
{
|
117
|
-
type: 'onPreResponse',
|
118
|
-
method: (request, h) => {
|
119
|
-
RequestLogger.logResponse(request)
|
120
|
-
return h.continue
|
121
|
-
}
|
122
|
-
}
|
123
|
-
])
|
124
105
|
await Plugins.registerPlugins(server, api, isAdmin)
|
125
106
|
|
126
107
|
server.route(routes)
|
@@ -148,6 +129,9 @@ const initializeApi = async (appConfig) => {
|
|
148
129
|
} = appConfig
|
149
130
|
|
150
131
|
if (!INSTRUMENTATION_METRICS_DISABLED) {
|
132
|
+
if (INSTRUMENTATION_METRICS_CONFIG.defaultLabels) {
|
133
|
+
INSTRUMENTATION_METRICS_CONFIG.defaultLabels.serviceVersion = version
|
134
|
+
}
|
151
135
|
initializeInstrumentation(INSTRUMENTATION_METRICS_CONFIG)
|
152
136
|
}
|
153
137
|
await connectDatabase(DATABASE)
|
package/test/fixtures/index.js
CHANGED
@@ -9,14 +9,15 @@ const headersDto = ({
|
|
9
9
|
destination = 'toDfsp',
|
10
10
|
proxy = '',
|
11
11
|
date = '2024-05-24 08:52:19',
|
12
|
-
accept
|
12
|
+
accept,
|
13
|
+
contentType
|
13
14
|
} = {}) => Object.freeze({
|
14
15
|
[Headers.FSPIOP.SOURCE]: source,
|
15
16
|
...(destination && { [Headers.FSPIOP.DESTINATION]: destination }),
|
16
17
|
...(proxy && { [Headers.FSPIOP.PROXY]: proxy }),
|
17
18
|
date,
|
18
19
|
accept,
|
19
|
-
'content-type': accept
|
20
|
+
'content-type': contentType || accept
|
20
21
|
})
|
21
22
|
|
22
23
|
const protocolVersionsDto = () => ({
|
@@ -40,22 +41,29 @@ const partiesCallHeadersDto = ({
|
|
40
41
|
destination,
|
41
42
|
proxy,
|
42
43
|
date,
|
43
|
-
accept: '
|
44
|
+
accept: interopHeader('parties', '1'),
|
45
|
+
contentType: interopHeader('parties', '1.1')
|
44
46
|
})
|
45
47
|
|
46
48
|
const participantsCallHeadersDto = ({
|
47
49
|
source,
|
48
50
|
destination,
|
49
51
|
proxy,
|
50
|
-
date
|
52
|
+
date,
|
53
|
+
acceptVersion = '1',
|
54
|
+
contentTypeVersion = '1.1'
|
51
55
|
} = {}) => headersDto({
|
52
56
|
source,
|
53
57
|
destination,
|
54
58
|
proxy,
|
55
59
|
date,
|
56
|
-
accept: '
|
60
|
+
accept: interopHeader('participants', acceptVersion),
|
61
|
+
contentType: interopHeader('participants', contentTypeVersion)
|
57
62
|
})
|
58
63
|
|
64
|
+
// todo: add ISO mode support
|
65
|
+
const interopHeader = (resource, version = '1') => `application/vnd.interoperability.${resource}+json;version=${version}`
|
66
|
+
|
59
67
|
const oracleRequestResponseDto = ({
|
60
68
|
partyList = [{ fspId: 'dfspFromOracle' }]
|
61
69
|
} = {}) => ({
|
@@ -83,6 +91,20 @@ const putPartiesSuccessResponseDto = ({
|
|
83
91
|
}
|
84
92
|
})
|
85
93
|
|
94
|
+
const postParticipantsPayloadDto = ({
|
95
|
+
requestId = randomUUID(), // '01JE8SG3F4WNHY8B9876THQ344',
|
96
|
+
partyList = [{
|
97
|
+
partyIdType: 'MSISDN',
|
98
|
+
partyIdentifier: '123456',
|
99
|
+
fspId: 'fspId123'
|
100
|
+
}],
|
101
|
+
currency = 'XXX'
|
102
|
+
} = {}) => Object.freeze({
|
103
|
+
requestId,
|
104
|
+
partyList,
|
105
|
+
...(currency && { currency })
|
106
|
+
})
|
107
|
+
|
86
108
|
const errorCallbackResponseDto = ({
|
87
109
|
errorCode = '1234',
|
88
110
|
errorDescription = 'Error description',
|
@@ -124,8 +146,10 @@ module.exports = {
|
|
124
146
|
participantsCallHeadersDto,
|
125
147
|
oracleRequestResponseDto,
|
126
148
|
putPartiesSuccessResponseDto,
|
149
|
+
postParticipantsPayloadDto,
|
127
150
|
errorCallbackResponseDto,
|
128
151
|
mockAlsRequestDto,
|
129
152
|
protocolVersionsDto,
|
130
|
-
mockHapiRequestDto
|
153
|
+
mockHapiRequestDto,
|
154
|
+
interopHeader
|
131
155
|
}
|
package/test/fixtures/iso.js
CHANGED
@@ -38,6 +38,7 @@ const Sinon = require('sinon')
|
|
38
38
|
const MigrationLockModel = require('../../../src/models/misc/migrationLock')
|
39
39
|
const Logger = require('@mojaloop/central-services-logger')
|
40
40
|
const Config = require('../../../src/lib/config')
|
41
|
+
const Metrics = require('@mojaloop/central-services-metrics')
|
41
42
|
|
42
43
|
Logger.isDebugEnabled = jest.fn(() => true)
|
43
44
|
Logger.isErrorEnabled = jest.fn(() => true)
|
@@ -51,6 +52,7 @@ describe('/health', () => {
|
|
51
52
|
sandbox = Sinon.createSandbox()
|
52
53
|
sandbox.stub(Db, 'connect').returns(Promise.resolve({}))
|
53
54
|
Config.API_PORT = await getPort()
|
55
|
+
Metrics.getDefaultRegister().clear()
|
54
56
|
server = await initServer(Config)
|
55
57
|
})
|
56
58
|
|
@@ -117,6 +119,7 @@ describe('/health', () => {
|
|
117
119
|
Config.proxyMap = { proxied: 'proxy' }
|
118
120
|
let serverWithProxy
|
119
121
|
try {
|
122
|
+
Metrics.getDefaultRegister().clear()
|
120
123
|
serverWithProxy = await initServer(Config)
|
121
124
|
sandbox.stub(MigrationLockModel, 'getIsMigrationLocked').resolves(false)
|
122
125
|
const mock = await Helper.generateMockRequest('/health', 'get')
|
@@ -35,16 +35,12 @@ const Helper = require('../../../util/helper')
|
|
35
35
|
const participants = require('../../../../src/domain/participants')
|
36
36
|
const initServer = require('../../../../src/server').initializeApi
|
37
37
|
const getPort = require('get-port')
|
38
|
-
const Logger = require('@mojaloop/central-services-logger')
|
39
38
|
const Config = require('../../../../src/lib/config')
|
40
39
|
|
41
|
-
Logger.isDebugEnabled = jest.fn(() => true)
|
42
|
-
Logger.isErrorEnabled = jest.fn(() => true)
|
43
|
-
Logger.isInfoEnabled = jest.fn(() => true)
|
44
|
-
let server
|
45
|
-
let sandbox
|
46
|
-
|
47
40
|
describe('/participants', () => {
|
41
|
+
let server
|
42
|
+
let sandbox
|
43
|
+
|
48
44
|
beforeAll(async () => {
|
49
45
|
sandbox = Sinon.createSandbox()
|
50
46
|
sandbox.stub(Db, 'connect').returns(Promise.resolve({}))
|
@@ -56,6 +52,7 @@ describe('/participants', () => {
|
|
56
52
|
await server.stop()
|
57
53
|
sandbox.restore()
|
58
54
|
})
|
55
|
+
|
59
56
|
const mock = {
|
60
57
|
requestId: '3ede3c17-36aa-42f4-b6db-b0df2e42f31e',
|
61
58
|
partyList: [{
|
@@ -79,6 +76,7 @@ describe('/participants', () => {
|
|
79
76
|
],
|
80
77
|
currency: 'EUR'
|
81
78
|
}
|
79
|
+
|
82
80
|
it('postParticipantsBatch success', async () => {
|
83
81
|
// Arrange
|
84
82
|
const options = {
|
@@ -35,7 +35,6 @@ const Db = require('../../../../../../src/lib/db')
|
|
35
35
|
const oracleEndpointCached = require('../../../../../../src/models/oracle/oracleEndpointCached')
|
36
36
|
const participant = require('../../../../../../src/models/participantEndpoint/facade')
|
37
37
|
const participants = require('../../../../../../src/domain/participants')
|
38
|
-
const requestLogger = require('../../../../../../src/lib/requestLogger')
|
39
38
|
const Helper = require('../../../../../util/helper')
|
40
39
|
const initServer = require('../../../../../../src/server').initializeApi
|
41
40
|
const Logger = require('@mojaloop/central-services-logger')
|
@@ -51,8 +50,6 @@ describe('/participants/{Type}/{ID}/{SubId}', () => {
|
|
51
50
|
beforeAll(async () => {
|
52
51
|
sandbox = Sinon.createSandbox()
|
53
52
|
sandbox.stub(Db, 'connect').returns(Promise.resolve({}))
|
54
|
-
sandbox.stub(requestLogger, 'logRequest').returns({})
|
55
|
-
sandbox.stub(requestLogger, 'logResponse').returns({})
|
56
53
|
Config.API_PORT = await getPort()
|
57
54
|
server = await initServer(Config)
|
58
55
|
})
|
@@ -40,7 +40,6 @@ const Db = require('../../../../../src/lib/db')
|
|
40
40
|
const oracleEndpointCached = require('../../../../../src/models/oracle/oracleEndpointCached')
|
41
41
|
const participant = require('../../../../../src/models/participantEndpoint/facade')
|
42
42
|
const participants = require('../../../../../src/domain/participants')
|
43
|
-
const requestLogger = require('../../../../../src/lib/requestLogger')
|
44
43
|
const Helper = require('../../../../util/helper')
|
45
44
|
const initServer = require('../../../../../src/server').initializeApi
|
46
45
|
const Config = require('../../../../../src/lib/config')
|
@@ -55,8 +54,6 @@ describe('/participants/{Type}/{ID}', () => {
|
|
55
54
|
beforeAll(async () => {
|
56
55
|
sandbox = Sinon.createSandbox()
|
57
56
|
sandbox.stub(Db, 'connect').returns(Promise.resolve({}))
|
58
|
-
sandbox.stub(requestLogger, 'logRequest').returns({})
|
59
|
-
sandbox.stub(requestLogger, 'logResponse').returns({})
|
60
57
|
Config.API_PORT = await getPort()
|
61
58
|
server = await initServer(Config)
|
62
59
|
sandbox.stub(Logger)
|
@@ -36,6 +36,7 @@ const initServer = require('../../../src/server').initializeApi
|
|
36
36
|
const Helper = require('../../util/helper')
|
37
37
|
const Db = require('../../../src/lib/db')
|
38
38
|
const Config = require('../../../src/lib/config')
|
39
|
+
const fixtures = require('../../fixtures')
|
39
40
|
|
40
41
|
Logger.isDebugEnabled = jest.fn(() => true)
|
41
42
|
Logger.isErrorEnabled = jest.fn(() => true)
|
@@ -44,14 +45,14 @@ let sandbox
|
|
44
45
|
let server
|
45
46
|
|
46
47
|
describe('/participants', () => {
|
47
|
-
|
48
|
+
beforeAll(async () => {
|
48
49
|
sandbox = Sinon.createSandbox()
|
49
50
|
sandbox.stub(Db, 'connect').returns(Promise.resolve({}))
|
50
51
|
Config.API_PORT = await getPort()
|
51
52
|
server = await initServer(Config)
|
52
53
|
})
|
53
54
|
|
54
|
-
|
55
|
+
afterAll(async () => {
|
55
56
|
await server.stop()
|
56
57
|
sandbox.restore()
|
57
58
|
})
|
@@ -103,6 +104,38 @@ describe('/participants', () => {
|
|
103
104
|
|
104
105
|
// Assert
|
105
106
|
expect(response.statusCode).toBe(400)
|
106
|
-
|
107
|
+
})
|
108
|
+
|
109
|
+
it('should validate requestId in UUID format', async () => {
|
110
|
+
const reqOptions = {
|
111
|
+
method: 'post',
|
112
|
+
url: '/participants',
|
113
|
+
headers: fixtures.participantsCallHeadersDto(),
|
114
|
+
payload: fixtures.postParticipantsPayloadDto()
|
115
|
+
}
|
116
|
+
const response = await server.inject(reqOptions)
|
117
|
+
expect(response.statusCode).toBe(200)
|
118
|
+
})
|
119
|
+
|
120
|
+
it('should validate requestId in ULID format', async () => {
|
121
|
+
const reqOptions = {
|
122
|
+
method: 'post',
|
123
|
+
url: '/participants',
|
124
|
+
headers: fixtures.participantsCallHeadersDto(),
|
125
|
+
payload: fixtures.postParticipantsPayloadDto({ requestId: '01JE8SG3F4WNHY8B9876THQ344' })
|
126
|
+
}
|
127
|
+
const response = await server.inject(reqOptions)
|
128
|
+
expect(response.statusCode).toBe(200)
|
129
|
+
})
|
130
|
+
|
131
|
+
it('should fail requestId validation', async () => {
|
132
|
+
const reqOptions = {
|
133
|
+
method: 'post',
|
134
|
+
url: '/participants',
|
135
|
+
headers: fixtures.participantsCallHeadersDto(),
|
136
|
+
payload: fixtures.postParticipantsPayloadDto({ requestId: 'wrong format' })
|
137
|
+
}
|
138
|
+
const response = await server.inject(reqOptions)
|
139
|
+
expect(response.statusCode).toBe(400)
|
107
140
|
})
|
108
141
|
})
|