@velocitycareerlabs/server-webwallet 1.25.0-dev-build.1a0f93709 → 1.25.0-dev-build.1dc2525a2
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/package.json +15 -15
- package/src/entities/credentials/orchestrators/load-additional-render-info.js +17 -10
- package/test/credentials-controller.test.js +6 -12
- package/test/helpers/mock-fetch.js +12 -0
- package/test/issuing-controller/issuing-by-deeplink.test.js +13 -17
- package/test/mocks/credential-types.js +16 -0
- package/test/mocks/index.js +1 -0
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@velocitycareerlabs/server-webwallet",
|
3
|
-
"version": "1.25.0-dev-build.
|
3
|
+
"version": "1.25.0-dev-build.1dc2525a2",
|
4
4
|
"description": "Web Wallet application",
|
5
5
|
"repository": "https://github.com/velocitycareerlabs/packages",
|
6
6
|
"engines": {
|
@@ -28,17 +28,17 @@
|
|
28
28
|
"@fastify/autoload": "5.10.0",
|
29
29
|
"@fastify/multipart": "~8.3.1",
|
30
30
|
"@spencejs/spence-mongo-repos": "^0.10.2",
|
31
|
-
"@velocitycareerlabs/auth": "1.25.0-dev-build.
|
32
|
-
"@velocitycareerlabs/common-functions": "1.25.0-dev-build.
|
33
|
-
"@velocitycareerlabs/common-schemas": "1.25.0-dev-build.
|
34
|
-
"@velocitycareerlabs/config": "1.25.0-dev-build.
|
35
|
-
"@velocitycareerlabs/fastify-plugins": "1.25.0-dev-build.
|
36
|
-
"@velocitycareerlabs/jwt": "1.25.0-dev-build.
|
37
|
-
"@velocitycareerlabs/migrations": "1.25.0-dev-build.
|
38
|
-
"@velocitycareerlabs/request": "1.25.0-dev-build.
|
39
|
-
"@velocitycareerlabs/server-provider": "1.25.0-dev-build.
|
40
|
-
"@velocitycareerlabs/vc-checks": "1.25.0-dev-build.
|
41
|
-
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "1.25.0-dev-build.
|
31
|
+
"@velocitycareerlabs/auth": "1.25.0-dev-build.1dc2525a2",
|
32
|
+
"@velocitycareerlabs/common-functions": "1.25.0-dev-build.1dc2525a2",
|
33
|
+
"@velocitycareerlabs/common-schemas": "1.25.0-dev-build.1dc2525a2",
|
34
|
+
"@velocitycareerlabs/config": "1.25.0-dev-build.1dc2525a2",
|
35
|
+
"@velocitycareerlabs/fastify-plugins": "1.25.0-dev-build.1dc2525a2",
|
36
|
+
"@velocitycareerlabs/jwt": "1.25.0-dev-build.1dc2525a2",
|
37
|
+
"@velocitycareerlabs/migrations": "1.25.0-dev-build.1dc2525a2",
|
38
|
+
"@velocitycareerlabs/request": "1.25.0-dev-build.1dc2525a2",
|
39
|
+
"@velocitycareerlabs/server-provider": "1.25.0-dev-build.1dc2525a2",
|
40
|
+
"@velocitycareerlabs/vc-checks": "1.25.0-dev-build.1dc2525a2",
|
41
|
+
"@velocitycareerlabs/vnf-nodejs-wallet-sdk": "1.25.0-dev-build.1dc2525a2",
|
42
42
|
"blueimp-md5": "2.19.0",
|
43
43
|
"env-var": "^7.0.0",
|
44
44
|
"fastify": "4.29.0",
|
@@ -51,8 +51,8 @@
|
|
51
51
|
},
|
52
52
|
"devDependencies": {
|
53
53
|
"@spencejs/spence-factories": "0.10.2",
|
54
|
-
"@velocitycareerlabs/crypto": "1.25.0-dev-build.
|
55
|
-
"@velocitycareerlabs/tests-helpers": "1.25.0-dev-build.
|
54
|
+
"@velocitycareerlabs/crypto": "1.25.0-dev-build.1dc2525a2",
|
55
|
+
"@velocitycareerlabs/tests-helpers": "1.25.0-dev-build.1dc2525a2",
|
56
56
|
"dotenv": "16.4.7",
|
57
57
|
"eslint": "8.57.1",
|
58
58
|
"eslint-config-airbnb-base": "14.2.1",
|
@@ -68,5 +68,5 @@
|
|
68
68
|
"nodemon": "3.1.9",
|
69
69
|
"prettier": "2.8.8"
|
70
70
|
},
|
71
|
-
"gitHead": "
|
71
|
+
"gitHead": "ab707d5fd7b5a1ed27e6c0e1725df5276e24720d"
|
72
72
|
}
|
@@ -4,10 +4,6 @@ const {
|
|
4
4
|
VCLOrganizationsSearchDescriptor,
|
5
5
|
VCLFilter,
|
6
6
|
} = require('@velocitycareerlabs/vnf-nodejs-wallet-sdk');
|
7
|
-
const {
|
8
|
-
normalizeJsonSchemaName,
|
9
|
-
} = require('@velocitycareerlabs/common-functions');
|
10
|
-
const { getCredentialDisplaySchema } = require('../../../fetchers/lib-api');
|
11
7
|
|
12
8
|
const loadAdditionalRenderInfo = async (credentials, context) => {
|
13
9
|
return {
|
@@ -37,13 +33,10 @@ const loadIssuersInfo = async (credentials, context) => {
|
|
37
33
|
}, {});
|
38
34
|
};
|
39
35
|
|
40
|
-
const getCredentialSchemaByType = async (credentialTypes
|
36
|
+
const getCredentialSchemaByType = async (credentialTypes) => {
|
41
37
|
const schemas = await Promise.all(
|
42
38
|
map(
|
43
|
-
(type) =>
|
44
|
-
getCredentialDisplaySchema(normalizeJsonSchemaName(type), context).then(
|
45
|
-
(data) => [type, data]
|
46
|
-
),
|
39
|
+
([type, url]) => fetchDisplayDescriptor(url).then((data) => [type, data]),
|
47
40
|
credentialTypes
|
48
41
|
)
|
49
42
|
);
|
@@ -51,10 +44,24 @@ const getCredentialSchemaByType = async (credentialTypes, context) => {
|
|
51
44
|
return fromPairs(schemas);
|
52
45
|
};
|
53
46
|
|
47
|
+
const fetchDisplayDescriptor = async (url) => {
|
48
|
+
const response = await fetch(url);
|
49
|
+
if (!response.ok) {
|
50
|
+
throw new Error(`Failed to fetch descriptor from ${url}`);
|
51
|
+
}
|
52
|
+
return response.json();
|
53
|
+
};
|
54
|
+
|
54
55
|
const loadCredentialTypeDisplaySchemas = async (credentials, context) => {
|
55
56
|
const credentialTypes = flow(map('type.0'), compact, uniq)(credentials);
|
57
|
+
const typesInfo = await context.vclSdk.credentialTypes;
|
58
|
+
const matchedTypes = credentialTypes.map((type) => [
|
59
|
+
type,
|
60
|
+
typesInfo.all.find((info) => info.credentialType === type)?.payload
|
61
|
+
.displayDescriptorUrls.en,
|
62
|
+
]);
|
56
63
|
|
57
|
-
return getCredentialSchemaByType(
|
64
|
+
return getCredentialSchemaByType(matchedTypes, context);
|
58
65
|
};
|
59
66
|
|
60
67
|
module.exports = {
|
@@ -1,3 +1,4 @@
|
|
1
|
+
const { mock } = require('node:test');
|
1
2
|
const { mongoDb } = require('@spencejs/spence-mongo-repos');
|
2
3
|
const { omit } = require('lodash/fp');
|
3
4
|
const nock = require('nock');
|
@@ -13,6 +14,7 @@ const {
|
|
13
14
|
errorResponseMatcher,
|
14
15
|
} = require('@velocitycareerlabs/tests-helpers/src/error-matchers');
|
15
16
|
const buildFastify = require('./helpers/webwallet-build-fastify');
|
17
|
+
const { mockFetch } = require('./helpers/mock-fetch');
|
16
18
|
const { mockSchema, mockedCredentialCategories } = require('./mocks');
|
17
19
|
const initCredentialsFactory = require('./factories/credentials');
|
18
20
|
const { WebWalletServerError } = require('../src/errors/error-codes');
|
@@ -22,7 +24,7 @@ const auth0Token =
|
|
22
24
|
'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IktFWSJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlzcyI6Imh0dHBzOi8vbG9jYWxob3N0LyIsImF1ZCI6ImZvbyIsInNjb3BlIjoicmVhZDp1c2VycyJ9.VwIIUqx9T-AxqbfL_FyNRAeOxTwiC2JpcwtrqnEWN3DdF07ijUkF1WYy8Ahfr_p4R3KnoPbiefZnIbVANCt-lt0ej32rfil2yHhQEsvFxSOjcrx6ARmPp0YAfWlN-5Sotzkxy29jaOZMEDkmRFZg3jkdC7wosPW_S6M-olC4g3HHfylpZI8O3Jdd87Qr9wD_QtUzANwnPbl2Q-9NEyxVjAZIWg_HWK9JAAaf_2IY5VwHBvyp0oeQSEHKi4hogcM59EOc4FxdR5WH45B_PenVa6W4mHFBkH8sAXxt2Zs9s2efujkfWYfyXvgL_lN7vT-TEADlAPP2L6CpWpDISOMsQWUSgGHcN_KwRh_E7qJwahR6mv4QHY6ReEoyjkmSS3swrD1l74jNs7QLAdsMywvzCMDsHabs7DYcEMGQBdP14PJ_ucLFnkivZeBDAc6sS445ocbyrpyO40XMaMorD5khRd9ej89SxR7d_v0W6Ne2Nn4XgW3pAZzu5Rdc4JvqfzLFxkp95jxy1MTAddjWISPmNOYYyXHM9SSqSpqVECOFS0f4z2zycHRqXUcOytWrvED6VGo9x7-IVCgu8vFzj0zToIWQmsDs3UoH9RnV12z0PMwGXQzca1lT_zGwJxBF3e4zJjmcJ05OMF2JgZ2_G48O3M4Dtb0jlgWbKLd0kWlIFzQ;';
|
23
25
|
|
24
26
|
jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
|
25
|
-
const { mockIssuers } = require('./mocks');
|
27
|
+
const { mockIssuers, mockCredentialTypes } = require('./mocks');
|
26
28
|
const originalModule = jest.requireActual(
|
27
29
|
'@velocitycareerlabs/vnf-nodejs-wallet-sdk'
|
28
30
|
);
|
@@ -32,6 +34,7 @@ jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
|
|
32
34
|
getInstance: jest.fn().mockReturnValue({
|
33
35
|
initialize: jest.fn().mockResolvedValue(null),
|
34
36
|
searchForOrganizations: jest.fn().mockResolvedValue(mockIssuers),
|
37
|
+
credentialTypes: mockCredentialTypes,
|
35
38
|
}),
|
36
39
|
},
|
37
40
|
};
|
@@ -41,14 +44,12 @@ const vclSdk = VCLProvider.getInstance();
|
|
41
44
|
|
42
45
|
describe('Test credentials controller', () => {
|
43
46
|
let fastify;
|
44
|
-
let schemaNock;
|
45
47
|
let persistCredentials;
|
46
48
|
|
47
49
|
beforeAll(async () => {
|
48
50
|
fastify = buildFastify();
|
49
51
|
|
50
52
|
nock('https://localhost/').get('/.well-known/jwks.json').reply(200, jwks);
|
51
|
-
schemaNock = nockSchemaRequest(fastify);
|
52
53
|
|
53
54
|
await fastify.ready();
|
54
55
|
({ persistCredentials } = initCredentialsFactory(fastify));
|
@@ -77,6 +78,7 @@ describe('Test credentials controller', () => {
|
|
77
78
|
}),
|
78
79
|
]);
|
79
80
|
|
81
|
+
mock.method(global, 'fetch', () => mockFetch(200, mockSchema));
|
80
82
|
const response = await fastify.injectJson({
|
81
83
|
method: 'GET',
|
82
84
|
url: '/credentials',
|
@@ -93,8 +95,7 @@ describe('Test credentials controller', () => {
|
|
93
95
|
new VCLFilter(currentUserCredential.issuer.id)
|
94
96
|
)
|
95
97
|
);
|
96
|
-
|
97
|
-
expect(schemaNock.isDone()).toBe(true);
|
98
|
+
expect(global.fetch.mock.calls).toHaveLength(1);
|
98
99
|
|
99
100
|
expect(response.json).toEqual({
|
100
101
|
credentials: [
|
@@ -256,13 +257,6 @@ describe('Test credentials controller', () => {
|
|
256
257
|
});
|
257
258
|
});
|
258
259
|
|
259
|
-
const nockSchemaRequest = (fastify) => {
|
260
|
-
return nock(fastify.config.libUrl)
|
261
|
-
.get('/display-descriptors/open-badge-v2.0.descriptor.json')
|
262
|
-
.once()
|
263
|
-
.reply(200, mockSchema);
|
264
|
-
};
|
265
|
-
|
266
260
|
const jwks = {
|
267
261
|
keys: [
|
268
262
|
{
|
@@ -1,3 +1,4 @@
|
|
1
|
+
const { mock } = require('node:test');
|
1
2
|
const nock = require('nock');
|
2
3
|
const { mongoDb } = require('@spencejs/spence-mongo-repos');
|
3
4
|
const { omit } = require('lodash/fp');
|
@@ -13,6 +14,7 @@ const {
|
|
13
14
|
VCLVerifiableCredential,
|
14
15
|
} = require('@velocitycareerlabs/vnf-nodejs-wallet-sdk');
|
15
16
|
const { deepLink } = require('./mocks');
|
17
|
+
const { mockFetch } = require('../helpers/mock-fetch');
|
16
18
|
|
17
19
|
jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
|
18
20
|
const originalModule = jest.requireActual(
|
@@ -23,6 +25,7 @@ jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
|
|
23
25
|
const { mockOffers } = require('./mocks/offers');
|
24
26
|
const { mockIssuers } = require('./mocks/issuers');
|
25
27
|
const { mockAcceptedCredentials } = require('./mocks/accepted-credentials');
|
28
|
+
const { mockCredentialTypes } = require('../mocks');
|
26
29
|
|
27
30
|
return {
|
28
31
|
...originalModule,
|
@@ -35,6 +38,7 @@ jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
|
|
35
38
|
generateOffers: jest.fn().mockResolvedValue(mockOffers),
|
36
39
|
searchForOrganizations: jest.fn().mockResolvedValue(mockIssuers),
|
37
40
|
finalizeOffers: jest.fn().mockResolvedValue(mockAcceptedCredentials),
|
41
|
+
credentialTypes: mockCredentialTypes,
|
38
42
|
}),
|
39
43
|
},
|
40
44
|
};
|
@@ -134,7 +138,7 @@ describe('Test Deep Link issuing controller', () => {
|
|
134
138
|
|
135
139
|
describe('GET /issuing/deep-link/offers - get offers by deep link', () => {
|
136
140
|
it('should return offers by pre-auth token (vendorOriginContext) successfully', async () => {
|
137
|
-
|
141
|
+
mock.method(global, 'fetch', () => mockFetch(200, mockSchema));
|
138
142
|
|
139
143
|
const response = await fastify.injectJson({
|
140
144
|
method: 'POST',
|
@@ -153,24 +157,23 @@ describe('Test Deep Link issuing controller', () => {
|
|
153
157
|
|
154
158
|
expect(response.statusCode).toBe(200);
|
155
159
|
|
156
|
-
expect(vclSdk.getCredentialManifest).
|
160
|
+
expect(vclSdk.getCredentialManifest).toHaveBeenCalledTimes(0); // important!
|
157
161
|
|
158
|
-
expect(vclSdk.generateOffers).
|
159
|
-
expect(vclSdk.generateOffers).
|
162
|
+
expect(vclSdk.generateOffers).toHaveBeenCalledTimes(1);
|
163
|
+
expect(vclSdk.generateOffers).toHaveBeenCalledWith(
|
160
164
|
expect.objectContaining(
|
161
165
|
new VCLGenerateOffersDescriptor(vclMockCredentialManifest, [], [], [])
|
162
166
|
)
|
163
167
|
);
|
164
168
|
|
165
|
-
expect(vclSdk.searchForOrganizations).
|
166
|
-
expect(vclSdk.searchForOrganizations).
|
169
|
+
expect(vclSdk.searchForOrganizations).toHaveBeenCalledTimes(1);
|
170
|
+
expect(vclSdk.searchForOrganizations).toHaveBeenCalledWith(
|
167
171
|
new VCLOrganizationsSearchDescriptor(
|
168
172
|
new VCLFilter(mockOffers.all[0].payload.issuer.id)
|
169
173
|
)
|
170
174
|
);
|
171
175
|
|
172
|
-
expect(
|
173
|
-
|
176
|
+
expect(global.fetch.mock.calls).toHaveLength(1);
|
174
177
|
const { offers, credentialManifest } = response.json;
|
175
178
|
expect(credentialManifest.jwt).toBe(
|
176
179
|
vclMockCredentialManifest.jwt.encodedJwt
|
@@ -179,7 +182,7 @@ describe('Test Deep Link issuing controller', () => {
|
|
179
182
|
});
|
180
183
|
|
181
184
|
it('should return offers by Input Credentials successfully', async () => {
|
182
|
-
|
185
|
+
mock.method(global, 'fetch', () => mockFetch(200, mockSchema));
|
183
186
|
const inputCredential = await persistCredentials({
|
184
187
|
encodedCredential: 'InputCredentialForOffers',
|
185
188
|
});
|
@@ -228,7 +231,7 @@ describe('Test Deep Link issuing controller', () => {
|
|
228
231
|
)
|
229
232
|
);
|
230
233
|
|
231
|
-
expect(
|
234
|
+
expect(global.fetch.mock.calls).toHaveLength(1);
|
232
235
|
|
233
236
|
const { offers, credentialManifest } = response.json;
|
234
237
|
expect(credentialManifest.jwt).toBe(
|
@@ -483,10 +486,3 @@ describe('Test Deep Link issuing controller', () => {
|
|
483
486
|
});
|
484
487
|
});
|
485
488
|
});
|
486
|
-
|
487
|
-
const nockSchemaRequest = (fastify) => {
|
488
|
-
return nock(fastify.config.libUrl)
|
489
|
-
.get('/display-descriptors/open-badge-v2.0.descriptor.json')
|
490
|
-
.once()
|
491
|
-
.reply(200, mockSchema);
|
492
|
-
};
|
@@ -0,0 +1,16 @@
|
|
1
|
+
const mockCredentialTypes = {
|
2
|
+
all: [
|
3
|
+
{
|
4
|
+
credentialType: 'OpenBadgeV2.0',
|
5
|
+
payload: {
|
6
|
+
displayDescriptorUrls: {
|
7
|
+
en: 'http://lib.localhost.test/display-descriptors/open-badge-v2.0.descriptor.json',
|
8
|
+
},
|
9
|
+
},
|
10
|
+
},
|
11
|
+
],
|
12
|
+
};
|
13
|
+
|
14
|
+
module.exports = {
|
15
|
+
mockCredentialTypes,
|
16
|
+
};
|