@velocitycareerlabs/tests-helpers 1.16.0-dev-build.1c05f9227

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.
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const env = require('env-var');
18
+
19
+ const buildMongoConnection = (dbName) => {
20
+ const isTlsMongo = env.get('TLS_MONGO').default('false').asBool();
21
+
22
+ if (!isTlsMongo) {
23
+ return `mongodb://localhost:27017/${dbName}`;
24
+ }
25
+
26
+ const mongoUsername = env.get('MONGO_USERNAME').default('').asString();
27
+ const mongoPassword = env.get('MONGO_PASSWORD').default('').asString();
28
+ const caFilename = env.get('CA_FILENAME').default('').asString();
29
+
30
+ // Uses tlsAllowInvalidHostnames to allow localhost SSH tunnleing to remote DB
31
+ const connUri = `mongodb://${mongoUsername}:${mongoPassword}@localhost:27017/${dbName}`;
32
+ const connOptions = `tls=true&tlsCAFile=${caFilename}&tlsAllowInvalidHostnames=true&retryWrites=false&directConnection=true`;
33
+
34
+ return `${connUri}?${connOptions}`;
35
+ };
36
+
37
+ module.exports = { buildMongoConnection };
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const { last, map, reduce } = require('lodash/fp');
18
+ const { privateJwkMatcher, publicJwkMatcher } = require('./jwk-matchers');
19
+
20
+ const generateDidKeyMatcher = (kid) => ({
21
+ id: last(kid.split('#')),
22
+ type: 'EcdsaSecp256k1VerificationKey2019',
23
+ publicKeyJwk: publicJwkMatcher,
24
+ purposes: ['assertionMethod'],
25
+ });
26
+
27
+ const createInitOp = (services, keys) => ({
28
+ operation: 'create',
29
+ content: {
30
+ publicKeys: map(generateDidKeyMatcher, keys),
31
+ services: map(formatService, services),
32
+ },
33
+ recovery: {
34
+ publicJwk: publicJwkMatcher,
35
+ privateJwk: privateJwkMatcher,
36
+ },
37
+ update: {
38
+ publicJwk: publicJwkMatcher,
39
+ privateJwk: privateJwkMatcher,
40
+ },
41
+ });
42
+
43
+ const addServiceOp = (service, previous, options) => {
44
+ const content = {};
45
+ if (!options.remove) {
46
+ content.addServices = [formatService(service)];
47
+ }
48
+ if (options.replace || options.remove) {
49
+ content.removeServices = [service.id.slice(1)];
50
+ }
51
+
52
+ return {
53
+ operation: 'update',
54
+ content,
55
+ previous,
56
+ update: {
57
+ publicJwk: publicJwkMatcher,
58
+ privateJwk: privateJwkMatcher,
59
+ },
60
+ };
61
+ };
62
+
63
+ const addPublicKeyOp = (publicKey, previous, options) => {
64
+ const content = {};
65
+ if (!options.remove) {
66
+ content.addPublicKeys = [generateDidKeyMatcher(publicKey.id)];
67
+ }
68
+ if (options.replace || options.remove) {
69
+ content.removePublicKeys = [publicKey.id.slice(1)];
70
+ }
71
+
72
+ return {
73
+ operation: 'update',
74
+ content,
75
+ previous,
76
+ update: {
77
+ publicJwk: publicJwkMatcher,
78
+ privateJwk: privateJwkMatcher,
79
+ },
80
+ };
81
+ };
82
+
83
+ const formatService = (service) => ({
84
+ id: service.id.slice(1),
85
+ serviceEndpoint: service.serviceEndpoint,
86
+ type: service.type,
87
+ });
88
+
89
+ // Should really also include initialKeys. See thread at:
90
+ // https://github.com/velocitycareerlabs/monorepo/pull/1271#discussion_r714185994
91
+ const generateIonOperations = (
92
+ initialServices = [],
93
+ additionalServices = [],
94
+ kids = ['vc-signing-key-1', 'eth-account-key-1', 'exchange-key-1'],
95
+ options = {}
96
+ ) => {
97
+ const op0 = createInitOp(initialServices, kids.slice(0, 2));
98
+ const initialOps = reduce(
99
+ (acc, kid) => {
100
+ acc.push(addPublicKeyOp({ id: kid }, last(acc), {}));
101
+ return acc;
102
+ },
103
+ [op0],
104
+ kids.slice(2)
105
+ );
106
+ return reduce(
107
+ (acc, service) => {
108
+ acc.push(addServiceOp(service, last(acc), options));
109
+ return acc;
110
+ },
111
+ initialOps,
112
+ additionalServices
113
+ );
114
+ };
115
+
116
+ module.exports = {
117
+ generateIonOperations,
118
+ generateDidKeyMatcher,
119
+ addPublicKeyOp,
120
+ };
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const { generateKeyPair } = require('@velocitycareerlabs/crypto');
18
+ const { jwkFromSecp256k1Key } = require('@velocitycareerlabs/jwt');
19
+
20
+ const generateKeyPairInHexAndJwk = () => {
21
+ const { publicKey, privateKey } = generateKeyPair();
22
+ return {
23
+ publicKey,
24
+ publicJwk: jwkFromSecp256k1Key(publicKey, false),
25
+ privateKey,
26
+ privateJwk: jwkFromSecp256k1Key(privateKey, true),
27
+ };
28
+ };
29
+
30
+ module.exports = {
31
+ generateKeyPairInHexAndJwk,
32
+ };
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const { last, omit } = require('lodash/fp');
18
+ const { Regexes } = require('@velocitycareerlabs/common-functions');
19
+ const { privateKeyMatcher, publicKeyMatcher } = require('./matchers');
20
+
21
+ // eslint-disable-next-line complexity
22
+ const generateOrganizationKeyMatcher = ({
23
+ kid,
24
+ purpose,
25
+ publicKey,
26
+ format = 'hex',
27
+ type = 'JsonWebKey2020',
28
+ withKidFragment = false,
29
+ }) => {
30
+ if (!withKidFragment) {
31
+ const baseMatcher = {
32
+ algorithm: 'SECP256K1',
33
+ encoding: 'hex',
34
+ id: kidMatcher(kid),
35
+ key:
36
+ format === 'hex'
37
+ ? expect.stringMatching(Regexes.HEX_FORMAT)
38
+ : privateKeyMatcher,
39
+ publicKey:
40
+ format === 'hex'
41
+ ? expect.stringMatching(Regexes.HEX_FORMAT)
42
+ : publicKeyMatcher,
43
+ purposes: [purpose],
44
+ type: expect.stringMatching(
45
+ /^(JsonWebKey2020|Ed25519VerificationKey2018|EcdsaSecp256k1VerificationKey2019)$/
46
+ ),
47
+ };
48
+ if (publicKey) {
49
+ return {
50
+ ...omit(['key'], baseMatcher),
51
+ publicKey,
52
+ };
53
+ }
54
+ return baseMatcher;
55
+ }
56
+
57
+ const baseMatcher = {
58
+ kidFragment: kidMatcher(kid),
59
+ algorithm: 'SECP256K1',
60
+ encoding: 'hex',
61
+ ...(!publicKey && {
62
+ key:
63
+ format === 'hex'
64
+ ? expect.stringMatching(Regexes.HEX_FORMAT)
65
+ : privateKeyMatcher,
66
+ }),
67
+ purposes: [purpose],
68
+ didDocumentKey: {
69
+ id: kid,
70
+ type: expect.stringMatching(
71
+ /^(JsonWebKey2020|Ed25519VerificationKey2018|EcdsaSecp256k1VerificationKey2019)$/
72
+ ),
73
+ controller: expect.any(String),
74
+ ...(type === 'JsonWebKey2020'
75
+ ? {
76
+ publicKeyJwk: publicKeyMatcher,
77
+ }
78
+ : {
79
+ publicKeyMultibase: expect.stringMatching(Regexes.HEX_FORMAT),
80
+ }),
81
+ },
82
+ };
83
+ return baseMatcher;
84
+ };
85
+
86
+ const kidMatcher = (kid) => {
87
+ if (kid instanceof RegExp) {
88
+ return expect.stringMatching(kid);
89
+ }
90
+
91
+ return `#${last(kid.split('#'))}`;
92
+ };
93
+
94
+ module.exports = { generateOrganizationKeyMatcher };
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const { generateKeyPair } = require('@velocitycareerlabs/crypto');
18
+ const { mapWithIndex } = require('@velocitycareerlabs/common-functions');
19
+ const {
20
+ castArray,
21
+ map,
22
+ merge,
23
+ pick,
24
+ set,
25
+ values,
26
+ unset,
27
+ slice,
28
+ size,
29
+ } = require('lodash/fp');
30
+ const { nanoid } = require('nanoid/non-secure');
31
+ const {
32
+ generateDocJwt,
33
+ generateCredentialJwt,
34
+ generatePresentationJwt,
35
+ } = require('@velocitycareerlabs/jwt');
36
+
37
+ const phonePayload = {
38
+ sub: 'did:velocity:0x0a63c18d09d5430363b2f3b270698a677fb513e4',
39
+ vc: {
40
+ '@context': ['https://www.w3.org/2018/credentials/v1'],
41
+ id: 'did:velocity:0x0a63c18d09d5430363b2f3b270698a677fb513e4',
42
+ issuer: { id: 'did:velocity:0x0b154da48d0f213c26c4b1d040dc5ff1dbf99ffa' },
43
+ issued: '2020-08-17T11:27:06.000Z',
44
+ type: ['PhoneV1.0', 'VerifiableCredential'],
45
+ credentialSubject: {
46
+ phone: '+447309917830',
47
+ },
48
+ },
49
+ };
50
+
51
+ const { privateKey } = generateKeyPair();
52
+
53
+ const generateSimpleKYCPresentation = (idDocTypes, options) => {
54
+ const idCredentials = {
55
+ phone: phonePayload,
56
+ };
57
+
58
+ const selectedCredentials = idDocTypes
59
+ ? pick(castArray(idDocTypes), idCredentials)
60
+ : values(idCredentials);
61
+
62
+ return doSimpleGeneratePresentation(
63
+ selectedCredentials,
64
+ 'fooDefinitionId',
65
+ options
66
+ );
67
+ };
68
+
69
+ const doSimpleGeneratePresentation = async (
70
+ credentials,
71
+ definitionId,
72
+ options = { isBrokeVCS: false }
73
+ ) => {
74
+ const signedCredentials = await Promise.all(
75
+ map((c) => generateCredentialJwt(c, privateKey), credentials)
76
+ );
77
+
78
+ const presentation = {
79
+ id: nanoid(),
80
+ verifiableCredential: options.isBrokeVCS
81
+ ? [
82
+ ...slice(0, 1, signedCredentials),
83
+ ...Array(size(signedCredentials) - 1).fill(''),
84
+ ]
85
+ : signedCredentials,
86
+ presentation_submission: {
87
+ id: nanoid(),
88
+ definition_id: definitionId,
89
+ descriptor_map: mapWithIndex(
90
+ (c, i) => ({
91
+ id: nanoid(),
92
+ path: `$.verifiableCredential[${i}]`,
93
+ format: 'jwt_vc',
94
+ }),
95
+ signedCredentials
96
+ ),
97
+ },
98
+ };
99
+
100
+ return {
101
+ presentation,
102
+ credentials,
103
+ override(overrides) {
104
+ return merge(this, { presentation: overrides });
105
+ },
106
+ delete(key) {
107
+ return set('presentation', unset(key, this.presentation), this);
108
+ },
109
+ sign(kid, personPrivateKey, issuer = 'https://self-issued.me') {
110
+ return generateDocJwt(this.presentation, personPrivateKey, {
111
+ issuer,
112
+ kid,
113
+ aud: this.presentation.aud,
114
+ jti: nanoid(),
115
+ });
116
+ },
117
+ selfSign() {
118
+ return generatePresentationJwt(this.presentation, privateKey);
119
+ },
120
+ };
121
+ };
122
+
123
+ module.exports = {
124
+ generateSimpleKYCPresentation,
125
+ phonePayload,
126
+ };
package/src/jsonify.js ADDED
@@ -0,0 +1,38 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const { reduce, isDate, keys } = require('lodash/fp');
18
+ const { ObjectId } = require('mongodb');
19
+
20
+ const jsonify = (obj, convertId = true) =>
21
+ reduce(
22
+ (acc, k) => {
23
+ if (isDate(obj[k])) {
24
+ acc[k] = obj[k].toISOString();
25
+ } else if (convertId && k === '_id') {
26
+ acc.id = obj[k].toString();
27
+ } else if (obj[k] instanceof ObjectId) {
28
+ acc[k] = obj[k].toString();
29
+ } else {
30
+ acc[k] = obj[k];
31
+ }
32
+ return acc;
33
+ },
34
+ {},
35
+ keys(obj)
36
+ );
37
+
38
+ module.exports = { jsonify };
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const { URLSAFE_BASE64_FORMAT } = require('./regexes');
18
+
19
+ const privateJwkMatcher = {
20
+ crv: 'secp256k1',
21
+ kty: 'EC',
22
+ d: expect.stringMatching(URLSAFE_BASE64_FORMAT),
23
+ x: expect.stringMatching(URLSAFE_BASE64_FORMAT),
24
+ y: expect.stringMatching(URLSAFE_BASE64_FORMAT),
25
+ };
26
+
27
+ const publicJwkMatcher = {
28
+ crv: 'secp256k1',
29
+ kty: 'EC',
30
+ x: expect.stringMatching(URLSAFE_BASE64_FORMAT),
31
+ y: expect.stringMatching(URLSAFE_BASE64_FORMAT),
32
+ };
33
+
34
+ module.exports = { publicJwkMatcher, privateJwkMatcher };
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const dotenv = require('dotenv');
18
+ const path = require('path');
19
+
20
+ const loadTestEnv = (
21
+ envFile = path.resolve(__dirname, '..', '.env.test'),
22
+ override = true
23
+ ) => {
24
+ dotenv.config({ path: envFile, override });
25
+ };
26
+
27
+ module.exports = { loadTestEnv };
@@ -0,0 +1,19 @@
1
+ const privateKeyMatcher = {
2
+ crv: 'secp256k1',
3
+ kty: 'EC',
4
+ d: expect.any(String),
5
+ x: expect.any(String),
6
+ y: expect.any(String),
7
+ };
8
+
9
+ const publicKeyMatcher = {
10
+ crv: 'secp256k1',
11
+ kty: 'EC',
12
+ x: expect.any(String),
13
+ y: expect.any(String),
14
+ };
15
+
16
+ module.exports = {
17
+ privateKeyMatcher,
18
+ publicKeyMatcher,
19
+ };
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const { ObjectId } = require('mongodb');
18
+ const { first, isPlainObject, map, mapValues } = require('lodash/fp');
19
+ const { ISO_DATETIME_FORMAT, OBJECT_ID_FORMAT } = require('./regexes');
20
+
21
+ // eslint-disable-next-line complexity
22
+ const mongoify = mapValues((v) => {
23
+ if (ISO_DATETIME_FORMAT.test(v)) {
24
+ return new Date(v);
25
+ }
26
+
27
+ if (Array.isArray(v) && v.length > 0 && OBJECT_ID_FORMAT.test(first(v))) {
28
+ return map((_v) => new ObjectId(_v), v);
29
+ }
30
+
31
+ if (OBJECT_ID_FORMAT.test(v)) {
32
+ return new ObjectId(v);
33
+ }
34
+
35
+ if (Array.isArray(v) && v.length > 0 && isPlainObject(first(v))) {
36
+ return map(mongoify, v);
37
+ }
38
+
39
+ if (isPlainObject(v)) {
40
+ return mongoify(v);
41
+ }
42
+ return v;
43
+ });
44
+
45
+ module.exports = { mongoify };
package/src/regexes.js ADDED
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ module.exports = {
18
+ OBJECT_ID_FORMAT: /^[0-9a-fA-F]{24}$/,
19
+ UUID_FORMAT:
20
+ /^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$/,
21
+ ISO_DATETIME_FORMAT: /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/,
22
+ ISO_DATETIME_FORMAT_ONLY_DATE_SECTION: /^\d{4}-\d{2}-\d{2}/,
23
+ TW0_DECIMAL_POINT_NUMBER: /^[0-9]*\.[0-9]{2}$/,
24
+ TW0_OR_THREE_DECIMAL_POINT_NUMBER: /^[0-9]*\.[0-9]{2,3}$/,
25
+ NUMERIC_FORMAT: /^[0-9]+$/,
26
+ HYPER_ID_FORMAT: /^[0-9a-zA-Z\\+]+$/,
27
+ NANO_ID_FORMAT: /^([A-Za-z0-9_-]+)/,
28
+ JWT_FORMAT: /^[A-Za-z0-9-_=]+\.[A-Za-z0-9-_=]+\.?[A-Za-z0-9-_.+/=]*$/,
29
+ URLSAFE_BASE64_FORMAT: /^[A-Za-z0-9-_=]+$/,
30
+ BASE58_FORMAT: /^[A-NP-Za-z1-9]+$/,
31
+ DID_FORMAT: 'did:[a-z]+:[a-zA-Z0-9_#;?&=\\.-]+',
32
+ ETHEREUM_ADDRESS_FORMAT: /^0x[a-fA-F0-9]{40}$/,
33
+ REQUEST_ID: /req-\w+/,
34
+ };
@@ -0,0 +1,29 @@
1
+ const deleteS3Object = async (s3Client, bucketName) => {
2
+ const data = await s3Client.listObjects({ Bucket: bucketName }).promise();
3
+
4
+ // Check if data.Contents exists and is not empty
5
+ if (data.Contents && data.Contents.length > 0) {
6
+ const objects = data.Contents.map(({ Key }) => ({ Key }));
7
+ await s3Client
8
+ .deleteObjects({ Bucket: bucketName, Delete: { Objects: objects } })
9
+ .promise();
10
+ }
11
+ };
12
+
13
+ const getObject = async ({ s3Client, bucket, key }) => {
14
+ const params = {
15
+ Bucket: bucket,
16
+ Key: key,
17
+ };
18
+
19
+ try {
20
+ return await s3Client.getObject(params).promise();
21
+ } catch (e) {
22
+ return null;
23
+ }
24
+ };
25
+
26
+ module.exports = {
27
+ deleteS3Object,
28
+ getObject,
29
+ };
@@ -0,0 +1,16 @@
1
+ const { set } = require('lodash/fp');
2
+ const { mongoFactory, mongoClose } = require('@spencejs/spence-mongo-repos');
3
+ const { buildMongoConnection } = require('./build-mongo-connection');
4
+ const { loadTestEnv } = require('./load-test-env');
5
+
6
+ const mongoFactoryWrapper = async (dbName, context) => {
7
+ const mongoConnection = buildMongoConnection(dbName);
8
+ loadTestEnv();
9
+
10
+ return mongoFactory(set('config.mongoConnection', mongoConnection, context));
11
+ };
12
+
13
+ module.exports = {
14
+ mongoFactoryWrapper,
15
+ mongoCloseWrapper: mongoClose,
16
+ };
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright 2023 Velocity Team
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+
17
+ const testAuthToken =
18
+ 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VyIjoidmVsb2NpdHkuYWRtaW5AZXhhbXBsZS5jb20ifQ.93NY5S7ohFv37rYYo4_TcPx3NFGdhMucK6yNmvGYE0U';
19
+
20
+ module.exports = { testAuthToken };