@mojaloop/central-services-shared 17.0.2 → 17.2.1
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 +6 -0
- package/CHANGELOG.md +21 -0
- package/CODEOWNERS +38 -0
- package/audit-ci.jsonc +21 -0
- package/package.json +12 -8
- package/src/enums/events.js +1 -0
- package/src/enums/kafka.js +4 -0
- package/src/index.d.ts +2 -0
- package/src/util/comparators/duplicateCheckComparator.js +17 -8
- package/src/util/hapi/plugins/headerValidation.js +1 -0
- package/test/unit/util/comparators/duplicateCheckComparator.test.js +181 -9
- package/.ncurc.js +0 -7
- package/audit-resolve.json +0 -61
package/.circleci/config.yml
CHANGED
|
@@ -187,7 +187,7 @@ jobs:
|
|
|
187
187
|
command: mkdir -p ./audit/results
|
|
188
188
|
- run:
|
|
189
189
|
name: Check for new npm vulnerabilities
|
|
190
|
-
command: npm run audit:check --
|
|
190
|
+
command: npm run audit:check -- -o json > ./audit/results/auditResults.json
|
|
191
191
|
- store_artifacts:
|
|
192
192
|
path: ./audit/results
|
|
193
193
|
prefix: audit
|
package/.ncurc.yaml
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Add a TODO comment indicating the reason for each rejected dependency upgrade added to this list, and what should be done to resolve it (i.e. handle it through a story, etc).
|
|
2
|
+
reject: [
|
|
3
|
+
# TODO: Added "@hapi/catbox", "@hapi/catbox-memory" to ncurc for dep:check to ignore updates due to breaking changes which should be handled by another story
|
|
4
|
+
"@hapi/catbox",
|
|
5
|
+
"@hapi/catbox-memory"
|
|
6
|
+
]
|
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,27 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [17.2.1](https://github.com/mojaloop/central-services-shared/compare/v17.2.0...v17.2.1) (2022-08-15)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* **mojaloop/#2814:** added bulk quotes to header validation ([#334](https://github.com/mojaloop/central-services-shared/issues/334)) ([ab6c3f6](https://github.com/mojaloop/central-services-shared/commit/ab6c3f6f9ed5968c1f154f3c78fab080e03a1534)), closes [mojaloop/#2814](https://github.com/mojaloop/project/issues/2814)
|
|
11
|
+
|
|
12
|
+
## [17.2.0](https://github.com/mojaloop/central-services-shared/compare/v17.1.0...v17.2.0) (2022-08-11)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* **mojaloop/#2796:** duplicate transaction not getting callback for post /bulkTransfers ([#332](https://github.com/mojaloop/central-services-shared/issues/332)) ([5427a53](https://github.com/mojaloop/central-services-shared/commit/5427a5307fe8f3be319888ec83ecf3eab1d85cdd)), closes [mojaloop/#2796](https://github.com/mojaloop/project/issues/2796)
|
|
18
|
+
|
|
19
|
+
## [17.1.0](https://github.com/mojaloop/central-services-shared/compare/v17.0.2...v17.1.0) (2022-08-05)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
### Features
|
|
23
|
+
|
|
24
|
+
* **mojaloop/#2796:** duplicate transaction not getting callback for post /bulkTransfers ([#331](https://github.com/mojaloop/central-services-shared/issues/331)) ([b7f6ba6](https://github.com/mojaloop/central-services-shared/commit/b7f6ba6cb90565b1f50a6574408f33f41388be68)), closes [mojaloop/#2796](https://github.com/mojaloop/project/issues/2796)
|
|
25
|
+
|
|
5
26
|
### [17.0.2](https://github.com/mojaloop/central-services-shared/compare/v17.0.1...v17.0.2) (2022-05-19)
|
|
6
27
|
|
|
7
28
|
|
package/CODEOWNERS
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# This is a comment.
|
|
2
|
+
# Each line is a file pattern followed by one or more owners.
|
|
3
|
+
|
|
4
|
+
## These owners will be the default owners for everything in
|
|
5
|
+
## the repo. Unless a later match takes precedence,
|
|
6
|
+
## @global-owner1 and @global-owner2 will be requested for
|
|
7
|
+
## review when someone opens a pull request.
|
|
8
|
+
#* @global-owner1 @global-owner2
|
|
9
|
+
* @mdebarros @elnyry-sam-k @vijayg10 @kleyow
|
|
10
|
+
|
|
11
|
+
## Order is important; the last matching pattern takes the most
|
|
12
|
+
## precedence. When someone opens a pull request that only
|
|
13
|
+
## modifies JS files, only @js-owner and not the global
|
|
14
|
+
## owner(s) will be requested for a review.
|
|
15
|
+
# *.js @js-owner
|
|
16
|
+
|
|
17
|
+
## You can also use email addresses if you prefer. They'll be
|
|
18
|
+
## used to look up users just like we do for commit author
|
|
19
|
+
## emails.
|
|
20
|
+
#*.go docs@example.com
|
|
21
|
+
|
|
22
|
+
# In this example, @doctocat owns any files in the build/logs
|
|
23
|
+
# directory at the root of the repository and any of its
|
|
24
|
+
# subdirectories.
|
|
25
|
+
# /build/logs/ @doctocat
|
|
26
|
+
|
|
27
|
+
## The `docs/*` pattern will match files like
|
|
28
|
+
## `docs/getting-started.md` but not further nested files like
|
|
29
|
+
## `docs/build-app/troubleshooting.md`.
|
|
30
|
+
# docs/* docs@example.com
|
|
31
|
+
|
|
32
|
+
## In this example, @octocat owns any file in an apps directory
|
|
33
|
+
## anywhere in your repository.
|
|
34
|
+
#apps/ @octocat
|
|
35
|
+
|
|
36
|
+
## In this example, @doctocat owns any file in the `/docs`
|
|
37
|
+
## directory in the root of your repository.
|
|
38
|
+
#/docs/ @doctocat
|
package/audit-ci.jsonc
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://github.com/IBM/audit-ci/raw/main/docs/schema.json",
|
|
3
|
+
// audit-ci supports reading JSON, JSONC, and JSON5 config files.
|
|
4
|
+
// Only use one of ["low": true, "moderate": true, "high": true, "critical": true]
|
|
5
|
+
"moderate": true,
|
|
6
|
+
"allowlist": [ // NOTE: Please add as much information as possible to any items added to the allowList
|
|
7
|
+
// Currently no fixes available for the following
|
|
8
|
+
"GHSA-v88g-cgmw-v5xw",
|
|
9
|
+
"GHSA-phwq-j96m-2c2q",
|
|
10
|
+
"GHSA-282f-qqgm-c34q",
|
|
11
|
+
"GHSA-6vfc-qv3f-vr6c",
|
|
12
|
+
"GHSA-6vfc-qv3f-vr6c",
|
|
13
|
+
"GHSA-wc69-rhjr-hc9g",
|
|
14
|
+
"GHSA-g954-5hwp-pp24",
|
|
15
|
+
"GHSA-g954-5hwp-pp24",
|
|
16
|
+
"GHSA-mjxr-4v3x-q3m4",
|
|
17
|
+
"GHSA-rjqq-98f6-6j3r",
|
|
18
|
+
"GHSA-w5p7-h5w8-2hfq",
|
|
19
|
+
"GHSA-p9pc-299p-vxgp"
|
|
20
|
+
]
|
|
21
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mojaloop/central-services-shared",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.2.1",
|
|
4
4
|
"description": "Shared code for mojaloop central services",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"author": "ModusBox",
|
|
@@ -27,6 +27,10 @@
|
|
|
27
27
|
"engines": {
|
|
28
28
|
"node": "=16.x"
|
|
29
29
|
},
|
|
30
|
+
"imports": {
|
|
31
|
+
"#src/*": "./src/*.js",
|
|
32
|
+
"#test/*": "./test/*.js"
|
|
33
|
+
},
|
|
30
34
|
"pre-commit": [
|
|
31
35
|
"lint",
|
|
32
36
|
"dep:check",
|
|
@@ -43,8 +47,8 @@
|
|
|
43
47
|
"test:xunit": "npx tape 'test/unit/**/**.test.js' | tap-xunit > ./test/results/xunit.xml",
|
|
44
48
|
"test:coverage": "npx nyc --reporter=lcov --reporter=text-summary tapes -- 'test/unit/**/**.test.js'",
|
|
45
49
|
"test:coverage-check": "npm run test:coverage && nyc check-coverage",
|
|
46
|
-
"audit:
|
|
47
|
-
"audit:check": "npx
|
|
50
|
+
"audit:fix": "npm audit fix",
|
|
51
|
+
"audit:check": "npx audit-ci --config ./audit-ci.jsonc",
|
|
48
52
|
"dep:check": "npx ncu -e 2",
|
|
49
53
|
"dep:update": "npx ncu -u",
|
|
50
54
|
"release": "npx standard-version --no-verify --releaseCommitMessageFormat 'chore(release): {{currentTag}} [skip ci]'",
|
|
@@ -58,24 +62,24 @@
|
|
|
58
62
|
"dotenv": "16.0.1",
|
|
59
63
|
"env-var": "7.1.1",
|
|
60
64
|
"event-stream": "4.0.1",
|
|
61
|
-
"immutable": "4.
|
|
65
|
+
"immutable": "4.1.0",
|
|
62
66
|
"lodash": "4.17.21",
|
|
63
67
|
"mustache": "4.2.0",
|
|
64
68
|
"openapi-backend": "5.3.0",
|
|
65
69
|
"raw-body": "2.5.1",
|
|
66
70
|
"rc": "1.2.8",
|
|
67
71
|
"shins": "2.6.0",
|
|
68
|
-
"uuid4": "2.0.
|
|
72
|
+
"uuid4": "2.0.3",
|
|
69
73
|
"widdershins": "^4.0.1",
|
|
70
|
-
"yaml": "2.1.
|
|
74
|
+
"yaml": "2.1.1"
|
|
71
75
|
},
|
|
72
76
|
"devDependencies": {
|
|
73
77
|
"@hapi/hapi": "20.2.2",
|
|
74
78
|
"@hapi/joi": "17.1.1",
|
|
79
|
+
"audit-ci": "^6.3.0",
|
|
75
80
|
"base64url": "3.0.1",
|
|
76
81
|
"chance": "1.1.8",
|
|
77
|
-
"npm-
|
|
78
|
-
"npm-check-updates": "13.0.1",
|
|
82
|
+
"npm-check-updates": "16.0.5",
|
|
79
83
|
"nyc": "15.1.0",
|
|
80
84
|
"pre-commit": "1.2.2",
|
|
81
85
|
"proxyquire": "2.1.3",
|
package/src/enums/events.js
CHANGED
|
@@ -65,6 +65,7 @@ const Event = {
|
|
|
65
65
|
BULK_ABORT: 'bulk-abort',
|
|
66
66
|
BULK_COMMIT: 'bulk-commit',
|
|
67
67
|
BULK_PREPARE: 'bulk-prepare',
|
|
68
|
+
BULK_PREPARE_DUPLICATE: 'bulk-prepare-duplicate',
|
|
68
69
|
BULK_PROCESSING: 'bulk-processing',
|
|
69
70
|
BULK_TIMEOUT_RECEIVED: 'bulk-timeout-received',
|
|
70
71
|
BULK_TIMEOUT_RESERVED: 'bulk-timeout-reserved',
|
package/src/enums/kafka.js
CHANGED
|
@@ -106,6 +106,10 @@ const TopicMap = {
|
|
|
106
106
|
functionality: transferEventType.NOTIFICATION,
|
|
107
107
|
action: transferEventAction.EVENT
|
|
108
108
|
},
|
|
109
|
+
'bulk-prepare-duplicate': {
|
|
110
|
+
functionality: transferEventType.NOTIFICATION,
|
|
111
|
+
action: transferEventAction.EVENT
|
|
112
|
+
},
|
|
109
113
|
'bulk-processing': {
|
|
110
114
|
functionality: transferEventType.NOTIFICATION,
|
|
111
115
|
action: transferEventAction.EVENT
|
package/src/index.d.ts
CHANGED
|
@@ -268,6 +268,7 @@ declare namespace CentralServicesShared {
|
|
|
268
268
|
BULK_PROCESSING = 'bulk-processing',
|
|
269
269
|
BULK_TIMEOUT_RECEIVED = 'bulk-timeout-received',
|
|
270
270
|
BULK_TIMEOUT_RESERVED = 'bulk-timeout-reserved',
|
|
271
|
+
BULK_PREPARE_DUPLICATE = 'bulk-prepare-duplicate',
|
|
271
272
|
BULK_GET = 'bulk-get',
|
|
272
273
|
CLOSE = 'close',
|
|
273
274
|
COMMIT = 'commit',
|
|
@@ -324,6 +325,7 @@ declare namespace CentralServicesShared {
|
|
|
324
325
|
BULK_ABORT: EventActionEnum.BULK_ABORT;
|
|
325
326
|
BULK_COMMIT: EventActionEnum.BULK_COMMIT;
|
|
326
327
|
BULK_PREPARE: EventActionEnum.BULK_PREPARE;
|
|
328
|
+
BULK_PREPARE_DUPLICATE: EventActionEnum.BULK_PREPARE_DUPLICATE;
|
|
327
329
|
BULK_PROCESSING: EventActionEnum.BULK_PROCESSING;
|
|
328
330
|
BULK_TIMEOUT_RECEIVED: EventActionEnum.BULK_TIMEOUT_RECEIVED;
|
|
329
331
|
BULK_TIMEOUT_RESERVED: EventActionEnum.BULK_TIMEOUT_RESERVED;
|
|
@@ -30,32 +30,41 @@
|
|
|
30
30
|
|
|
31
31
|
const Hash = require('../hash')
|
|
32
32
|
|
|
33
|
-
const duplicateCheckComparator = async (id,
|
|
33
|
+
const duplicateCheckComparator = async (id, objectOrHashOverride, getDuplicateDataFuncOverride, saveHashFuncOverride, options = {
|
|
34
|
+
hashOverride: false
|
|
35
|
+
}) => {
|
|
36
|
+
// lets check if we can actually do the comparison
|
|
37
|
+
if (objectOrHashOverride == null) throw Error('objectOrHashOverride arg is null')
|
|
38
|
+
|
|
34
39
|
let hasDuplicateId = false
|
|
35
40
|
let hasDuplicateHash = false
|
|
36
|
-
|
|
37
|
-
let
|
|
41
|
+
let duplicateHashRecordResult = null
|
|
42
|
+
let saveHashFuncOverrideResult = false
|
|
43
|
+
|
|
44
|
+
const generatedHash = options?.hashOverride ? objectOrHashOverride : Hash.generateSha256(objectOrHashOverride) // options.hashOverride is useful for cases where the hash is already provided, such as Bulk Transfers Prepare/Fulfil Use-Case - the hash is calculated in the Bulk-API-Adapter.
|
|
38
45
|
|
|
39
46
|
const compareById = async () => {
|
|
40
|
-
|
|
41
|
-
hasDuplicateId =
|
|
47
|
+
duplicateHashRecordResult = await getDuplicateDataFuncOverride(id)
|
|
48
|
+
hasDuplicateId = duplicateHashRecordResult !== null
|
|
42
49
|
return hasDuplicateId
|
|
43
50
|
}
|
|
44
51
|
|
|
45
52
|
const compareByHash = () => {
|
|
46
|
-
hasDuplicateHash =
|
|
53
|
+
hasDuplicateHash = duplicateHashRecordResult.hash === generatedHash
|
|
47
54
|
return hasDuplicateHash
|
|
48
55
|
}
|
|
49
56
|
|
|
50
57
|
if (await compareById()) {
|
|
51
58
|
compareByHash()
|
|
52
59
|
} else {
|
|
53
|
-
await saveHashFuncOverride(id, generatedHash)
|
|
60
|
+
saveHashFuncOverrideResult = await saveHashFuncOverride(id, generatedHash)
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
return {
|
|
57
64
|
hasDuplicateId,
|
|
58
|
-
hasDuplicateHash
|
|
65
|
+
hasDuplicateHash,
|
|
66
|
+
duplicateHashRecordResult,
|
|
67
|
+
saveHashFuncOverrideResult
|
|
59
68
|
}
|
|
60
69
|
}
|
|
61
70
|
|
|
@@ -45,58 +45,230 @@ Test('Duplicate check comparator', dccTest => {
|
|
|
45
45
|
dccTest.test('duplicateCheckComparator should', duplicateCheckComparatorTest => {
|
|
46
46
|
duplicateCheckComparatorTest.test('compare hashes when id exists', async test => {
|
|
47
47
|
try {
|
|
48
|
+
// Arrange
|
|
48
49
|
const hash = 'helper.hash'
|
|
49
|
-
const duplicateCheckComparator = Proxyquire('
|
|
50
|
+
const duplicateCheckComparator = Proxyquire('#src/util/comparators/duplicateCheckComparator', {
|
|
50
51
|
'../hash': {
|
|
51
52
|
generateSha256: sandbox.stub().returns(hash)
|
|
52
53
|
}
|
|
53
54
|
})
|
|
54
55
|
const id = 1
|
|
55
56
|
const object = { key: 'value' }
|
|
56
|
-
const
|
|
57
|
-
const
|
|
57
|
+
const getDuplicateDataFuncOverrideResult = { id, hash }
|
|
58
|
+
const getDuplicateDataFuncOverride = sandbox.stub().resolves(getDuplicateDataFuncOverrideResult)
|
|
59
|
+
const saveHashFuncOverride = sandbox.stub().resolves(true)
|
|
58
60
|
|
|
59
61
|
const expected = {
|
|
60
62
|
hasDuplicateId: true,
|
|
61
|
-
hasDuplicateHash: true
|
|
63
|
+
hasDuplicateHash: true,
|
|
64
|
+
saveHashFuncOverrideResult: false,
|
|
65
|
+
duplicateHashRecordResult: getDuplicateDataFuncOverrideResult
|
|
62
66
|
}
|
|
67
|
+
|
|
68
|
+
// Act
|
|
63
69
|
const result = await duplicateCheckComparator(id, object, getDuplicateDataFuncOverride, saveHashFuncOverride)
|
|
70
|
+
|
|
71
|
+
// Assert
|
|
64
72
|
test.deepEqual(result, expected, 'hash matched')
|
|
73
|
+
test.ok(saveHashFuncOverride.called === false)
|
|
65
74
|
test.end()
|
|
66
75
|
} catch (err) {
|
|
76
|
+
// Assert
|
|
67
77
|
Logger.error(`duplicateCheckComparator failed with error - ${err}`)
|
|
68
78
|
test.fail()
|
|
69
79
|
test.end()
|
|
70
80
|
}
|
|
71
81
|
})
|
|
72
82
|
|
|
73
|
-
duplicateCheckComparatorTest.test('save
|
|
83
|
+
duplicateCheckComparatorTest.test('save hash when id not found', async test => {
|
|
74
84
|
try {
|
|
85
|
+
// Arrange
|
|
75
86
|
const hash = 'helper.hash'
|
|
76
|
-
const duplicateCheckComparator = Proxyquire('
|
|
87
|
+
const duplicateCheckComparator = Proxyquire('#src/util/comparators/duplicateCheckComparator', {
|
|
77
88
|
'../hash': {
|
|
78
89
|
generateSha256: sandbox.stub().returns(hash)
|
|
79
90
|
}
|
|
80
91
|
})
|
|
81
92
|
const id = 1
|
|
82
93
|
const object = { key: 'value' }
|
|
83
|
-
const getDuplicateDataFuncOverride =
|
|
84
|
-
const saveHashFuncOverride =
|
|
94
|
+
const getDuplicateDataFuncOverride = sandbox.stub().resolves(null)
|
|
95
|
+
const saveHashFuncOverride = sandbox.stub().resolves(true)
|
|
85
96
|
|
|
86
97
|
const expected = {
|
|
87
98
|
hasDuplicateId: false,
|
|
88
|
-
hasDuplicateHash: false
|
|
99
|
+
hasDuplicateHash: false,
|
|
100
|
+
saveHashFuncOverrideResult: true,
|
|
101
|
+
duplicateHashRecordResult: null
|
|
89
102
|
}
|
|
103
|
+
|
|
104
|
+
// Act
|
|
90
105
|
const result = await duplicateCheckComparator(id, object, getDuplicateDataFuncOverride, saveHashFuncOverride)
|
|
106
|
+
|
|
107
|
+
// Assert
|
|
91
108
|
test.deepEqual(result, expected, 'hash saved')
|
|
109
|
+
test.ok(saveHashFuncOverride.calledOnceWith(id, hash))
|
|
110
|
+
test.end()
|
|
111
|
+
} catch (err) {
|
|
112
|
+
// Assert
|
|
113
|
+
Logger.error(`duplicateCheckComparator failed with error - ${err}`)
|
|
114
|
+
test.fail()
|
|
115
|
+
test.end()
|
|
116
|
+
}
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
duplicateCheckComparatorTest.test('compare hashes when id exists and generatedHashOverride is injected', async test => {
|
|
120
|
+
try {
|
|
121
|
+
// Arrange
|
|
122
|
+
const hash = 'helper.hash'
|
|
123
|
+
const generatedHashOverride = 'helper.hash.override'
|
|
124
|
+
const duplicateCheckComparator = Proxyquire('#src/util/comparators/duplicateCheckComparator', {
|
|
125
|
+
'../hash': {
|
|
126
|
+
generateSha256: sandbox.stub().returns(hash)
|
|
127
|
+
}
|
|
128
|
+
})
|
|
129
|
+
const id = 1
|
|
130
|
+
const getDuplicateDataFuncOverrideResult = { id, hash: generatedHashOverride }
|
|
131
|
+
const getDuplicateDataFuncOverride = sandbox.stub().resolves(getDuplicateDataFuncOverrideResult)
|
|
132
|
+
const saveHashFuncOverride = sandbox.stub().resolves(true)
|
|
133
|
+
|
|
134
|
+
const expected = {
|
|
135
|
+
hasDuplicateId: true,
|
|
136
|
+
hasDuplicateHash: true,
|
|
137
|
+
duplicateHashRecordResult: getDuplicateDataFuncOverrideResult,
|
|
138
|
+
saveHashFuncOverrideResult: false
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// Act
|
|
142
|
+
const result = await duplicateCheckComparator(id, generatedHashOverride, getDuplicateDataFuncOverride, saveHashFuncOverride, {
|
|
143
|
+
hashOverride: true
|
|
144
|
+
})
|
|
145
|
+
|
|
146
|
+
// Assert
|
|
147
|
+
test.deepEqual(result, expected, 'hash matched')
|
|
148
|
+
test.ok(saveHashFuncOverride.called === false)
|
|
92
149
|
test.end()
|
|
93
150
|
} catch (err) {
|
|
151
|
+
// Assert
|
|
94
152
|
Logger.error(`duplicateCheckComparator failed with error - ${err}`)
|
|
95
153
|
test.fail()
|
|
96
154
|
test.end()
|
|
97
155
|
}
|
|
98
156
|
})
|
|
99
157
|
|
|
158
|
+
duplicateCheckComparatorTest.test('save hash when id not found and generatedHashOverride is injected', async test => {
|
|
159
|
+
try {
|
|
160
|
+
// Arrange
|
|
161
|
+
const hash = 'helper.hash'
|
|
162
|
+
const generatedHashOverride = 'helper.hash.override'
|
|
163
|
+
const duplicateCheckComparator = Proxyquire('#src/util/comparators/duplicateCheckComparator', {
|
|
164
|
+
'../hash': {
|
|
165
|
+
generateSha256: sandbox.stub().returns(hash)
|
|
166
|
+
}
|
|
167
|
+
})
|
|
168
|
+
const id = 1
|
|
169
|
+
const getDuplicateDataFuncOverride = sandbox.stub().resolves(null)
|
|
170
|
+
const saveHashFuncOverride = sandbox.stub().resolves(true)
|
|
171
|
+
|
|
172
|
+
const expected = {
|
|
173
|
+
hasDuplicateId: false,
|
|
174
|
+
hasDuplicateHash: false,
|
|
175
|
+
saveHashFuncOverrideResult: true,
|
|
176
|
+
duplicateHashRecordResult: null
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// Act
|
|
180
|
+
const result = await duplicateCheckComparator(id, generatedHashOverride, getDuplicateDataFuncOverride, saveHashFuncOverride, {
|
|
181
|
+
hashOverride: true
|
|
182
|
+
})
|
|
183
|
+
|
|
184
|
+
// Assert
|
|
185
|
+
test.deepEqual(result, expected, 'hash saved')
|
|
186
|
+
test.ok(saveHashFuncOverride.calledOnceWith(id, generatedHashOverride))
|
|
187
|
+
test.end()
|
|
188
|
+
} catch (err) {
|
|
189
|
+
// Assert
|
|
190
|
+
Logger.error(`duplicateCheckComparator failed with error - ${err}`)
|
|
191
|
+
test.fail()
|
|
192
|
+
test.end()
|
|
193
|
+
}
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
duplicateCheckComparatorTest.test('save hash when id not found with empty object and generatedHashOverride is injected', async test => {
|
|
197
|
+
try {
|
|
198
|
+
// Arrange
|
|
199
|
+
const hash = 'helper.hash'
|
|
200
|
+
const generatedHashOverride = 'helper.hash.override'
|
|
201
|
+
const duplicateCheckComparator = Proxyquire('#src/util/comparators/duplicateCheckComparator', {
|
|
202
|
+
'../hash': {
|
|
203
|
+
generateSha256: sandbox.stub().returns(hash)
|
|
204
|
+
}
|
|
205
|
+
})
|
|
206
|
+
const id = 1
|
|
207
|
+
const object = null // We don't actually care about the object when we override the hash by setting the generatedHashOverride
|
|
208
|
+
const getDuplicateDataFuncOverride = sandbox.stub().resolves(null)
|
|
209
|
+
const saveHashFuncOverride = sandbox.stub().resolves(true)
|
|
210
|
+
|
|
211
|
+
const expected = {
|
|
212
|
+
hasDuplicateId: false,
|
|
213
|
+
hasDuplicateHash: false
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Act
|
|
217
|
+
const result = await duplicateCheckComparator(id, object, getDuplicateDataFuncOverride, saveHashFuncOverride, {
|
|
218
|
+
hashOverride: false
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
// Assert
|
|
222
|
+
test.deepEqual(result, expected, 'hash saved')
|
|
223
|
+
test.ok(saveHashFuncOverride.calledOnceWith(id, generatedHashOverride))
|
|
224
|
+
test.fail()
|
|
225
|
+
test.end()
|
|
226
|
+
} catch (err) {
|
|
227
|
+
// Assert
|
|
228
|
+
Logger.error(`duplicateCheckComparator failed with error - ${err}`)
|
|
229
|
+
test.ok(err)
|
|
230
|
+
test.end()
|
|
231
|
+
}
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
duplicateCheckComparatorTest.test('save hash when id not found with empty object and generatedHashOverride is injected', async test => {
|
|
235
|
+
try {
|
|
236
|
+
// Arrange
|
|
237
|
+
const hash = 'helper.hash'
|
|
238
|
+
const generatedHashOverride = 'helper.hash.override'
|
|
239
|
+
const duplicateCheckComparator = Proxyquire('#src/util/comparators/duplicateCheckComparator', {
|
|
240
|
+
'../hash': {
|
|
241
|
+
generateSha256: sandbox.stub().returns(hash)
|
|
242
|
+
}
|
|
243
|
+
})
|
|
244
|
+
const id = 1
|
|
245
|
+
const object = null // We don't actually care about the object when we override the hash by setting the generatedHashOverride
|
|
246
|
+
const getDuplicateDataFuncOverride = sandbox.stub().resolves(null)
|
|
247
|
+
const saveHashFuncOverride = sandbox.stub().resolves(true)
|
|
248
|
+
|
|
249
|
+
const expected = {
|
|
250
|
+
hasDuplicateId: false,
|
|
251
|
+
hasDuplicateHash: false
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
// Act
|
|
255
|
+
const result = await duplicateCheckComparator(id, object, getDuplicateDataFuncOverride, saveHashFuncOverride, {
|
|
256
|
+
hashOverride: true
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
// Assert
|
|
260
|
+
test.deepEqual(result, expected, 'hash saved')
|
|
261
|
+
test.ok(saveHashFuncOverride.calledOnceWith(id, generatedHashOverride))
|
|
262
|
+
test.fail()
|
|
263
|
+
test.end()
|
|
264
|
+
} catch (err) {
|
|
265
|
+
// Assert
|
|
266
|
+
Logger.error(`duplicateCheckComparator failed with error - ${err}`)
|
|
267
|
+
test.ok(err)
|
|
268
|
+
test.end()
|
|
269
|
+
}
|
|
270
|
+
})
|
|
271
|
+
|
|
100
272
|
duplicateCheckComparatorTest.end()
|
|
101
273
|
})
|
|
102
274
|
|
package/.ncurc.js
DELETED
package/audit-resolve.json
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"decisions": {
|
|
3
|
-
"1067553|better-ajv-errors>jsonpointer": {
|
|
4
|
-
"decision": "ignore",
|
|
5
|
-
"madeAt": 1652887989276,
|
|
6
|
-
"expiresAt": 1655479973082
|
|
7
|
-
},
|
|
8
|
-
"1070256|ejs": {
|
|
9
|
-
"decision": "ignore",
|
|
10
|
-
"madeAt": 1652887990649,
|
|
11
|
-
"expiresAt": 1655479973082
|
|
12
|
-
},
|
|
13
|
-
"1070030|shins>markdown-it": {
|
|
14
|
-
"decision": "ignore",
|
|
15
|
-
"madeAt": 1652951732905,
|
|
16
|
-
"expiresAt": 1655543725868
|
|
17
|
-
},
|
|
18
|
-
"1068155|shins>markdown-it>sanitize-html": {
|
|
19
|
-
"decision": "ignore",
|
|
20
|
-
"madeAt": 1652887992740,
|
|
21
|
-
"expiresAt": 1655479973082
|
|
22
|
-
},
|
|
23
|
-
"1070260|shins>markdown-it>sanitize-html": {
|
|
24
|
-
"decision": "ignore",
|
|
25
|
-
"madeAt": 1652887993909,
|
|
26
|
-
"expiresAt": 1655479973082
|
|
27
|
-
},
|
|
28
|
-
"1068310|widdershins>oas-resolver>yargs>yargs-parser": {
|
|
29
|
-
"decision": "ignore",
|
|
30
|
-
"madeAt": 1652887994946,
|
|
31
|
-
"expiresAt": 1655479973082
|
|
32
|
-
},
|
|
33
|
-
"1067946|widdershins>oas-resolver>yargs>yargs-parser>swagger2openapi>oas-validator>ajv": {
|
|
34
|
-
"decision": "ignore",
|
|
35
|
-
"madeAt": 1652887996204,
|
|
36
|
-
"expiresAt": 1655479973082
|
|
37
|
-
},
|
|
38
|
-
"1070030|widdershins>markdown-it": {
|
|
39
|
-
"decision": "ignore",
|
|
40
|
-
"madeAt": 1652951732905,
|
|
41
|
-
"expiresAt": 1655543725868
|
|
42
|
-
},
|
|
43
|
-
"1067553|swagger2openapi>better-ajv-errors>jsonpointer": {
|
|
44
|
-
"decision": "ignore",
|
|
45
|
-
"madeAt": 1652951735762,
|
|
46
|
-
"expiresAt": 1655543725868
|
|
47
|
-
},
|
|
48
|
-
"1067946|swagger2openapi>better-ajv-errors>jsonpointer>oas-validator>ajv": {
|
|
49
|
-
"decision": "ignore",
|
|
50
|
-
"madeAt": 1652951738877,
|
|
51
|
-
"expiresAt": 1655543725868
|
|
52
|
-
},
|
|
53
|
-
"1068310|widdershins>markdown-it>yargs>yargs-parser": {
|
|
54
|
-
"decision": "ignore",
|
|
55
|
-
"madeAt": 1652951741588,
|
|
56
|
-
"expiresAt": 1655543725868
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
"rules": {},
|
|
60
|
-
"version": 1
|
|
61
|
-
}
|