@velocitycareerlabs/server-webwallet 1.25.0-dev-build.12642c864

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.
Files changed (193) hide show
  1. package/.localdev.env +57 -0
  2. package/.standalone.env +22 -0
  3. package/LICENSE +248 -0
  4. package/README.md +11 -0
  5. package/jest.config.js +20 -0
  6. package/migrate-mongo.config.js +23 -0
  7. package/package.json +72 -0
  8. package/src/config/config.js +74 -0
  9. package/src/controllers/accounts/autohooks.js +28 -0
  10. package/src/controllers/accounts/controller.js +209 -0
  11. package/src/controllers/accounts/schemas/index.js +6 -0
  12. package/src/controllers/accounts/schemas/webwallet-accounts-request.schema.js +25 -0
  13. package/src/controllers/accounts/schemas/webwallet-accounts-response.schema.js +72 -0
  14. package/src/controllers/accounts/schemas/webwallet-accounts-update-request.schema.js +23 -0
  15. package/src/controllers/accounts/schemas/webwallet-test-personas-response.schema.js +110 -0
  16. package/src/controllers/consent/autohooks.js +14 -0
  17. package/src/controllers/consent/controller.js +91 -0
  18. package/src/controllers/consent/schemas/index.js +3 -0
  19. package/src/controllers/consent/schemas/webwallet-consent-response.schema.js +23 -0
  20. package/src/controllers/credentials/autohooks.js +36 -0
  21. package/src/controllers/credentials/controller.js +92 -0
  22. package/src/controllers/credentials/schemas/index.js +4 -0
  23. package/src/controllers/credentials/schemas/webwallet-credential-categories-response.schema.js +21 -0
  24. package/src/controllers/credentials/schemas/webwallet-credentials-response.schema.js +29 -0
  25. package/src/controllers/disclosures/autohooks.js +21 -0
  26. package/src/controllers/disclosures/controller.js +168 -0
  27. package/src/controllers/disclosures/schemas/index.js +7 -0
  28. package/src/controllers/disclosures/schemas/webwallet-accept-presentation-request-body.schema.js +28 -0
  29. package/src/controllers/disclosures/schemas/webwallet-accept-presentation-response.schema.js +16 -0
  30. package/src/controllers/disclosures/schemas/webwallet-get-disclosures-response.schema.js +18 -0
  31. package/src/controllers/disclosures/schemas/webwallet-get-presentation-request-query.schema.js +21 -0
  32. package/src/controllers/disclosures/schemas/webwallet-get-presentation-request-response.schema.js +16 -0
  33. package/src/controllers/feedback/autohooks.js +11 -0
  34. package/src/controllers/feedback/controller.js +48 -0
  35. package/src/controllers/issuing/common-schemas/index.js +10 -0
  36. package/src/controllers/issuing/common-schemas/webwallet-get-credential-manifest-query.schema.js +27 -0
  37. package/src/controllers/issuing/common-schemas/webwallet-get-credential-manifest-response.schema.js +31 -0
  38. package/src/controllers/issuing/deep-link/autohooks.js +51 -0
  39. package/src/controllers/issuing/deep-link/controller.js +192 -0
  40. package/src/controllers/issuing/deep-link/schemas/index.js +6 -0
  41. package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-accept-offers-request.schema.js +30 -0
  42. package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-accept-offers-response.schema.js +36 -0
  43. package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-offers-request.schema.js +28 -0
  44. package/src/controllers/issuing/deep-link/schemas/webwallet-deep-link-offers-response.schema.js +48 -0
  45. package/src/controllers/issuing/identity-credentials/autohooks.js +42 -0
  46. package/src/controllers/issuing/identity-credentials/controller.js +188 -0
  47. package/src/controllers/issuing/identity-credentials/schemas/index.js +6 -0
  48. package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-confirm-body.schema.js +20 -0
  49. package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-confirm-response.schema.js +37 -0
  50. package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-request-code-body.schema.js +14 -0
  51. package/src/controllers/issuing/identity-credentials/schemas/webwallet-identity-credentials-request-code-params.schema.js +19 -0
  52. package/src/controllers/linkedin/autohooks.js +16 -0
  53. package/src/controllers/linkedin/controller.js +276 -0
  54. package/src/controllers/linkedin/schemas/index.js +3 -0
  55. package/src/controllers/linkedin/schemas/webwallet-linkedin-me-response.schema.js +14 -0
  56. package/src/controllers/root/controller.js +29 -0
  57. package/src/entities/.gitkeep +0 -0
  58. package/src/entities/accounts/constants.js +5 -0
  59. package/src/entities/accounts/domains/extract-auth0-id-token-or-access-token.js +22 -0
  60. package/src/entities/accounts/domains/index.js +5 -0
  61. package/src/entities/accounts/domains/validate-account-permissions.js +36 -0
  62. package/src/entities/accounts/domains/validate-logo-size.js +25 -0
  63. package/src/entities/accounts/index.js +5 -0
  64. package/src/entities/accounts/repos/accounts.repo.js +63 -0
  65. package/src/entities/credentials/domains/index.js +3 -0
  66. package/src/entities/credentials/domains/offer-to-credential-mongo-dto.js +43 -0
  67. package/src/entities/credentials/index.js +6 -0
  68. package/src/entities/credentials/orchestrators/index.js +3 -0
  69. package/src/entities/credentials/orchestrators/load-additional-render-info.js +65 -0
  70. package/src/entities/credentials/repos/credentials.repo.js +132 -0
  71. package/src/entities/credentials/schemas/index.js +4 -0
  72. package/src/entities/credentials/schemas/webwallet-credential-response.schema.js +138 -0
  73. package/src/entities/credentials/schemas/webwallet-credentials-response.schemas.js +95 -0
  74. package/src/entities/credentials/schemas/webwallet-display-descriptor-response.schema.js +106 -0
  75. package/src/entities/disclosures/index.js +4 -0
  76. package/src/entities/disclosures/repos/disclosures.repo.js +31 -0
  77. package/src/entities/disclosures/schemas/index.js +10 -0
  78. package/src/entities/disclosures/schemas/webwallet-disclosure.schema.js +39 -0
  79. package/src/entities/disclosures/schemas/webwallet-presentation-request-field.schema.js +45 -0
  80. package/src/entities/disclosures/schemas/webwallet-presentation-request-filter.schema.js +30 -0
  81. package/src/entities/disclosures/schemas/webwallet-presentation-request-format.schema.js +36 -0
  82. package/src/entities/disclosures/schemas/webwallet-presentation-request-input-descriptors.schema.js +111 -0
  83. package/src/entities/disclosures/schemas/webwallet-presentation-request-schema.schema.js +14 -0
  84. package/src/entities/disclosures/schemas/webwallet-presentation-request-submission-requirements.schema.js +37 -0
  85. package/src/entities/disclosures/schemas/webwallet-presentation-request.schema.js +79 -0
  86. package/src/entities/index.js +6 -0
  87. package/src/entities/issuing/domain/constants.js +8 -0
  88. package/src/entities/issuing/domain/does-user-have-fresh-pending-verification.js +26 -0
  89. package/src/entities/issuing/domain/get-credentials-from-offers.js +18 -0
  90. package/src/entities/issuing/domain/index.js +5 -0
  91. package/src/entities/issuing/index.js +5 -0
  92. package/src/entities/issuing/orchestrators/build-issuing-input-credentials.js +35 -0
  93. package/src/entities/issuing/orchestrators/generate-offers-by-deep-link.js +74 -0
  94. package/src/entities/issuing/orchestrators/get-identity-issuer.js +35 -0
  95. package/src/entities/issuing/orchestrators/get-identity-offers-by-deeplink.js +74 -0
  96. package/src/entities/issuing/orchestrators/index.js +6 -0
  97. package/src/entities/issuing/schemas/index.js +9 -0
  98. package/src/entities/issuing/schemas/webwallet-credential-manifest.schema.js +198 -0
  99. package/src/errors/error-codes.js +12 -0
  100. package/src/fetchers/career-wallet/create-account-fetcher.js +7 -0
  101. package/src/fetchers/career-wallet/create-did-fetcher.js +17 -0
  102. package/src/fetchers/career-wallet/get-app-config.js +11 -0
  103. package/src/fetchers/career-wallet/get-consents.js +13 -0
  104. package/src/fetchers/career-wallet/get-credential-categories.js +7 -0
  105. package/src/fetchers/career-wallet/get-personas.js +7 -0
  106. package/src/fetchers/career-wallet/index.js +12 -0
  107. package/src/fetchers/career-wallet/post-consent.js +9 -0
  108. package/src/fetchers/career-wallet/send-feedback.js +14 -0
  109. package/src/fetchers/career-wallet/sign-fetcher.js +14 -0
  110. package/src/fetchers/career-wallet/verify-id-credential-confirm-code.js +19 -0
  111. package/src/fetchers/career-wallet/verify-id-credential-request-code.js +20 -0
  112. package/src/fetchers/index.js +4 -0
  113. package/src/fetchers/lib-api/get-credential-display-schema.js +12 -0
  114. package/src/fetchers/lib-api/index.js +3 -0
  115. package/src/fetchers/linkedin/create-linkedin-post.js +45 -0
  116. package/src/fetchers/linkedin/get-access-token.js +26 -0
  117. package/src/fetchers/linkedin/get-linkedin-user-email.js +13 -0
  118. package/src/fetchers/linkedin/get-linkedin-user-id.js +16 -0
  119. package/src/fetchers/linkedin/index.js +9 -0
  120. package/src/fetchers/linkedin/register-image-to-upload.js +30 -0
  121. package/src/fetchers/linkedin/revoke-linkedin-access.js +20 -0
  122. package/src/fetchers/linkedin/upload-image-to-linkedin.js +16 -0
  123. package/src/index.js +15 -0
  124. package/src/init-server.js +108 -0
  125. package/src/plugins/crypto-services/index.js +5 -0
  126. package/src/plugins/crypto-services/jwt-sign-service-impl.js +72 -0
  127. package/src/plugins/crypto-services/jwt-verify-service-impl.js +21 -0
  128. package/src/plugins/crypto-services/key-service-impl.js +28 -0
  129. package/src/plugins/fetch-errors-handler-plugin.js +64 -0
  130. package/src/plugins/index.js +4 -0
  131. package/src/plugins/vnf-sdk-plugin.js +53 -0
  132. package/src/standalone.js +8 -0
  133. package/test/accounts-controller.test.js +618 -0
  134. package/test/consent-controller.test.js +185 -0
  135. package/test/credentials-controller.test.js +307 -0
  136. package/test/crypro-services/jwt-sign-service-impl.test.js +83 -0
  137. package/test/crypro-services/jwt-verify-service-impl.test.js +27 -0
  138. package/test/crypro-services/key-service-impl.test.js +76 -0
  139. package/test/crypro-services/mocks/index.js +4 -0
  140. package/test/crypro-services/mocks/jwt-mock.js +15 -0
  141. package/test/crypro-services/mocks/public-jwk.js +14 -0
  142. package/test/disclosures-controller/disclosure-credentials.test.js +428 -0
  143. package/test/disclosures-controller/get-disclosures.test.js +169 -0
  144. package/test/disclosures-controller/mocks/get-credential-manifest.js +20 -0
  145. package/test/disclosures-controller/mocks/index.js +6 -0
  146. package/test/disclosures-controller/mocks/presentation-request.js +32 -0
  147. package/test/disclosures-controller/mocks/presentation-submission.js +21 -0
  148. package/test/disclosures-controller/mocks/submission-result.js +19 -0
  149. package/test/factories/accounts.js +25 -0
  150. package/test/factories/credentials.js +66 -0
  151. package/test/factories/disclosures.js +106 -0
  152. package/test/feedback-controller.test.js +125 -0
  153. package/test/fetch-errors-handler-plugin.test.js +97 -0
  154. package/test/filter-deleted-credentials-extension.test.js +82 -0
  155. package/test/helpers/.env.test +10 -0
  156. package/test/helpers/nock-consent-add.js +16 -0
  157. package/test/helpers/nock-consents-get.js +15 -0
  158. package/test/helpers/nock-feedback.js +9 -0
  159. package/test/helpers/nock-linkedin-access-token.js +9 -0
  160. package/test/helpers/nock-linkedin-email.js +15 -0
  161. package/test/helpers/nock-linkedin-image-register.js +28 -0
  162. package/test/helpers/nock-linkedin-me.js +13 -0
  163. package/test/helpers/nock-linkedin-post.js +37 -0
  164. package/test/helpers/nock-linkedin-revoke.js +9 -0
  165. package/test/helpers/nock-test-personas.js +13 -0
  166. package/test/helpers/webwallet-build-fastify.js +17 -0
  167. package/test/issuing-controller/issuing-by-deeplink-empty-offers.test.js +142 -0
  168. package/test/issuing-controller/issuing-by-deeplink-failed-offers.test.js +142 -0
  169. package/test/issuing-controller/issuing-by-deeplink.test.js +492 -0
  170. package/test/issuing-controller/issuing-identity-credentials.test.js +377 -0
  171. package/test/issuing-controller/mocks/accept-offers-response.js +90 -0
  172. package/test/issuing-controller/mocks/accepted-credentials.js +47 -0
  173. package/test/issuing-controller/mocks/credential-manifest-presentation.js +72 -0
  174. package/test/issuing-controller/mocks/credential-manifest.js +45 -0
  175. package/test/issuing-controller/mocks/identity-issuing/accept-offers.js +22 -0
  176. package/test/issuing-controller/mocks/identity-issuing/confirm-verification-code.js +5 -0
  177. package/test/issuing-controller/mocks/identity-issuing/get-app-config.js +52 -0
  178. package/test/issuing-controller/mocks/identity-issuing/get-organization.js +118 -0
  179. package/test/issuing-controller/mocks/identity-issuing/index.js +6 -0
  180. package/test/issuing-controller/mocks/index.js +6 -0
  181. package/test/issuing-controller/mocks/issuers.js +126 -0
  182. package/test/issuing-controller/mocks/offers.js +48 -0
  183. package/test/issuing-controller/mocks/schema.js +107 -0
  184. package/test/linkedin-controller.test.js +452 -0
  185. package/test/mocks/credential-categories.js +115 -0
  186. package/test/mocks/credentials.js +15 -0
  187. package/test/mocks/didjwk.js +25 -0
  188. package/test/mocks/index.js +7 -0
  189. package/test/mocks/issuers.js +88 -0
  190. package/test/mocks/jwk.js +53 -0
  191. package/test/mocks/schema.js +107 -0
  192. package/test/root.test.js +42 -0
  193. package/test/vcl-sdk-plugin.test.js +86 -0
@@ -0,0 +1,492 @@
1
+ const nock = require('nock');
2
+ const { mongoDb } = require('@spencejs/spence-mongo-repos');
3
+ const { omit } = require('lodash/fp');
4
+ const { errorResponseMatcher } = require('@velocitycareerlabs/tests-helpers');
5
+ const {
6
+ VCLFinalizeOffersDescriptor,
7
+ VCLCredentialManifestDescriptorByDeepLink,
8
+ VCLFilter,
9
+ VCLDeepLink,
10
+ VCLOrganizationsSearchDescriptor,
11
+ VCLProvider,
12
+ VCLGenerateOffersDescriptor,
13
+ VCLVerifiableCredential,
14
+ } = require('@velocitycareerlabs/vnf-nodejs-wallet-sdk');
15
+ const { deepLink } = require('./mocks');
16
+
17
+ jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
18
+ const originalModule = jest.requireActual(
19
+ '@velocitycareerlabs/vnf-nodejs-wallet-sdk'
20
+ );
21
+
22
+ const { vclMockCredentialManifest } = require('./mocks');
23
+ const { mockOffers } = require('./mocks/offers');
24
+ const { mockIssuers } = require('./mocks/issuers');
25
+ const { mockAcceptedCredentials } = require('./mocks/accepted-credentials');
26
+
27
+ return {
28
+ ...originalModule,
29
+ VCLProvider: {
30
+ getInstance: jest.fn().mockReturnValue({
31
+ initialize: jest.fn().mockResolvedValue(null),
32
+ getCredentialManifest: jest
33
+ .fn()
34
+ .mockResolvedValue(vclMockCredentialManifest),
35
+ generateOffers: jest.fn().mockResolvedValue(mockOffers),
36
+ searchForOrganizations: jest.fn().mockResolvedValue(mockIssuers),
37
+ finalizeOffers: jest.fn().mockResolvedValue(mockAcceptedCredentials),
38
+ }),
39
+ },
40
+ };
41
+ });
42
+
43
+ const vclSdk = VCLProvider.getInstance();
44
+ const initAccountsFactory = require('../factories/accounts');
45
+ const initCredentialsFactory = require('../factories/credentials');
46
+
47
+ const { mockSchema } = require('../mocks');
48
+
49
+ const { mockOffers, mockParsedResponse } = require('./mocks');
50
+
51
+ const buildFastify = require('../helpers/webwallet-build-fastify');
52
+ const { vclMockCredentialManifest } = require('./mocks/credential-manifest');
53
+ const { Jwk } = require('../mocks/jwk');
54
+ const { WebWalletServerError } = require('../../src/errors/error-codes');
55
+
56
+ const idToken =
57
+ // eslint-disable-next-line max-len
58
+ 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6IktFWSJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiYWRtaW4iOnRydWUsImlzcyI6Imh0dHBzOi8vbG9jYWxob3N0LyIsImF1ZCI6ImZvbyIsInNjb3BlIjoicmVhZDp1c2VycyJ9.VwIIUqx9T-AxqbfL_FyNRAeOxTwiC2JpcwtrqnEWN3DdF07ijUkF1WYy8Ahfr_p4R3KnoPbiefZnIbVANCt-lt0ej32rfil2yHhQEsvFxSOjcrx6ARmPp0YAfWlN-5Sotzkxy29jaOZMEDkmRFZg3jkdC7wosPW_S6M-olC4g3HHfylpZI8O3Jdd87Qr9wD_QtUzANwnPbl2Q-9NEyxVjAZIWg_HWK9JAAaf_2IY5VwHBvyp0oeQSEHKi4hogcM59EOc4FxdR5WH45B_PenVa6W4mHFBkH8sAXxt2Zs9s2efujkfWYfyXvgL_lN7vT-TEADlAPP2L6CpWpDISOMsQWUSgGHcN_KwRh_E7qJwahR6mv4QHY6ReEoyjkmSS3swrD1l74jNs7QLAdsMywvzCMDsHabs7DYcEMGQBdP14PJ_ucLFnkivZeBDAc6sS445ocbyrpyO40XMaMorD5khRd9ej89SxR7d_v0W6Ne2Nn4XgW3pAZzu5Rdc4JvqfzLFxkp95jxy1MTAddjWISPmNOYYyXHM9SSqSpqVECOFS0f4z2zycHRqXUcOytWrvED6VGo9x7-IVCgu8vFzj0zToIWQmsDs3UoH9RnV12z0PMwGXQzca1lT_zGwJxBF3e4zJjmcJ05OMF2JgZ2_G48O3M4Dtb0jlgWbKLd0kWlIFzQ';
59
+
60
+ describe('Test Deep Link issuing controller', () => {
61
+ let fastify;
62
+ let persistAccounts;
63
+ let persistCredentials;
64
+
65
+ beforeAll(async () => {
66
+ fastify = buildFastify();
67
+
68
+ await fastify.ready();
69
+
70
+ ({ persistAccounts } = initAccountsFactory(fastify));
71
+ ({ persistCredentials } = initCredentialsFactory(fastify));
72
+ });
73
+
74
+ beforeEach(async () => {
75
+ nock('https://localhost/').get('/.well-known/jwks.json').reply(200, Jwk);
76
+
77
+ await persistAccounts({
78
+ userId: '1234567890',
79
+ did: 'did:example:123',
80
+ });
81
+ });
82
+
83
+ afterEach(async () => {
84
+ nock.cleanAll();
85
+ jest.clearAllMocks();
86
+ await mongoDb().collection('credentials').deleteMany();
87
+ await mongoDb().collection('accounts').deleteMany();
88
+ });
89
+
90
+ afterAll(async () => {
91
+ nock.restore();
92
+ await mongoDb().collection('accounts').deleteMany();
93
+ await fastify.close();
94
+ });
95
+
96
+ describe('GET /issuing/deep-link/manifest - get manifest by deep link', () => {
97
+ it('should return credential manifest successfully for issuing request', async () => {
98
+ const response = await fastify.injectJson({
99
+ method: 'GET',
100
+ url: `/issuing/deep-link/get-credential-manifest?link=${encodeURIComponent(
101
+ deepLink
102
+ )}`,
103
+ headers: {
104
+ authorization: `Bearer ${idToken}`,
105
+ },
106
+ });
107
+
108
+ expect(response.statusCode).toBe(200);
109
+
110
+ expect(vclSdk.getCredentialManifest).toHaveBeenCalledTimes(1);
111
+ expect(vclSdk.getCredentialManifest).toHaveBeenCalledWith(
112
+ new VCLCredentialManifestDescriptorByDeepLink(new VCLDeepLink(deepLink))
113
+ );
114
+
115
+ const { credentialManifest } = response.json;
116
+ expect(credentialManifest).toEqual({
117
+ presentation: {
118
+ exchange_id: expect.any(String),
119
+ exp: expect.any(Number),
120
+ iat: expect.any(Number),
121
+ iss: expect.any(String),
122
+ issuer: expect.any(Object),
123
+ metadata: expect.any(Object),
124
+ nbf: expect.any(Number),
125
+ presentation_definition: expect.any(Object),
126
+ output_descriptors: expect.any(Array),
127
+ },
128
+ jwt: expect.any(String),
129
+ link: expect.any(String),
130
+ verifiedProfile: expect.any(Object),
131
+ });
132
+ });
133
+ });
134
+
135
+ describe('GET /issuing/deep-link/offers - get offers by deep link', () => {
136
+ it('should return offers by pre-auth token (vendorOriginContext) successfully', async () => {
137
+ const schemaNock = nockSchemaRequest(fastify);
138
+
139
+ const response = await fastify.injectJson({
140
+ method: 'POST',
141
+ url: '/issuing/deep-link/offers',
142
+ headers: {
143
+ authorization: `Bearer ${idToken}`,
144
+ },
145
+ payload: {
146
+ credentialManifest: {
147
+ jwt: vclMockCredentialManifest.jwt.encodedJwt,
148
+ link: vclMockCredentialManifest.deepLink.value,
149
+ verifiedProfile: vclMockCredentialManifest.verifiedProfile.payload,
150
+ },
151
+ },
152
+ });
153
+
154
+ expect(response.statusCode).toBe(200);
155
+
156
+ expect(vclSdk.getCredentialManifest).toBeCalledTimes(0); // important!
157
+
158
+ expect(vclSdk.generateOffers).toBeCalledTimes(1);
159
+ expect(vclSdk.generateOffers).toBeCalledWith(
160
+ expect.objectContaining(
161
+ new VCLGenerateOffersDescriptor(vclMockCredentialManifest, [], [], [])
162
+ )
163
+ );
164
+
165
+ expect(vclSdk.searchForOrganizations).toBeCalledTimes(1);
166
+ expect(vclSdk.searchForOrganizations).toBeCalledWith(
167
+ new VCLOrganizationsSearchDescriptor(
168
+ new VCLFilter(mockOffers.all[0].payload.issuer.id)
169
+ )
170
+ );
171
+
172
+ expect(schemaNock.isDone()).toBe(true);
173
+
174
+ const { offers, credentialManifest } = response.json;
175
+ expect(credentialManifest.jwt).toBe(
176
+ vclMockCredentialManifest.jwt.encodedJwt
177
+ );
178
+ expect(offers).toEqual(mockOffers.all.map((offer) => offer.payload));
179
+ });
180
+
181
+ it('should return offers by Input Credentials successfully', async () => {
182
+ const schemaNock = nockSchemaRequest(fastify);
183
+ const inputCredential = await persistCredentials({
184
+ encodedCredential: 'InputCredentialForOffers',
185
+ });
186
+
187
+ const response = await fastify.injectJson({
188
+ method: 'POST',
189
+ url: '/issuing/deep-link/offers',
190
+ headers: {
191
+ authorization: `Bearer ${idToken}`,
192
+ },
193
+ payload: {
194
+ credentialManifest: {
195
+ jwt: vclMockCredentialManifest.jwt.encodedJwt,
196
+ link: vclMockCredentialManifest.deepLink.value,
197
+ verifiedProfile: vclMockCredentialManifest.verifiedProfile.payload,
198
+ },
199
+ inputCredentials: [inputCredential._id],
200
+ },
201
+ });
202
+
203
+ expect(response.statusCode).toBe(200);
204
+
205
+ expect(vclSdk.getCredentialManifest).toBeCalledTimes(0); // important!
206
+
207
+ expect(vclSdk.generateOffers).toBeCalledTimes(1);
208
+ expect(vclSdk.generateOffers).toBeCalledWith(
209
+ expect.objectContaining(
210
+ new VCLGenerateOffersDescriptor(
211
+ vclMockCredentialManifest,
212
+ [],
213
+ [],
214
+ [
215
+ new VCLVerifiableCredential(
216
+ 'OpenBadgeV2.0',
217
+ 'InputCredentialForOffers'
218
+ ),
219
+ ]
220
+ )
221
+ )
222
+ );
223
+
224
+ expect(vclSdk.searchForOrganizations).toHaveBeenCalledTimes(1);
225
+ expect(vclSdk.searchForOrganizations).toHaveBeenCalledWith(
226
+ new VCLOrganizationsSearchDescriptor(
227
+ new VCLFilter(mockOffers.all[0].payload.issuer.id)
228
+ )
229
+ );
230
+
231
+ expect(schemaNock.isDone()).toBe(true);
232
+
233
+ const { offers, credentialManifest } = response.json;
234
+ expect(credentialManifest.jwt).toBe(
235
+ vclMockCredentialManifest.jwt.encodedJwt
236
+ );
237
+ expect(offers).toEqual(mockOffers.all.map((offer) => offer.payload));
238
+ });
239
+
240
+ it('should return 401 if no access token is provided', async () => {
241
+ const response = await fastify.injectJson({
242
+ method: 'POST',
243
+ url: '/issuing/deep-link/offers',
244
+ payload: {
245
+ link: deepLink,
246
+ },
247
+ });
248
+
249
+ expect(response.statusCode).toBe(401);
250
+ });
251
+
252
+ it('should return 400 if no link is provided', async () => {
253
+ const response = await fastify.injectJson({
254
+ method: 'POST',
255
+ url: '/issuing/deep-link/offers',
256
+ headers: {
257
+ authorization: `Bearer ${idToken}`,
258
+ },
259
+ });
260
+
261
+ expect(response.statusCode).toBe(400);
262
+ });
263
+ });
264
+
265
+ describe('POST /issuing/deep-link/accept-offers - accept offers by deep link', () => {
266
+ it('should return offers successfully', async () => {
267
+ const response = await fastify.injectJson({
268
+ method: 'POST',
269
+ url: '/issuing/deep-link/accept-offers',
270
+ payload: {
271
+ credentialManifest: {
272
+ jwt: vclMockCredentialManifest.jwt.encodedJwt,
273
+ link: vclMockCredentialManifest.deepLink.value,
274
+ verifiedProfile: vclMockCredentialManifest.verifiedProfile.payload,
275
+ vendorOriginContext: vclMockCredentialManifest.vendorOriginContext,
276
+ },
277
+ token: mockOffers.sessionToken.value,
278
+ challenge: 'some challenge',
279
+ offerIds: mockOffers.all.map((offer) => offer.payload.id),
280
+ },
281
+ headers: {
282
+ authorization: `Bearer ${idToken}`,
283
+ },
284
+ });
285
+
286
+ expect(response.statusCode).toBe(200);
287
+ expect(response.json).toEqual(mockParsedResponse);
288
+
289
+ expect(vclSdk.getCredentialManifest).toBeCalledTimes(0); // important!
290
+
291
+ expect(vclSdk.finalizeOffers).toBeCalledTimes(1);
292
+ expect(vclSdk.finalizeOffers).toBeCalledWith(
293
+ expect.objectContaining(
294
+ new VCLFinalizeOffersDescriptor(
295
+ vclMockCredentialManifest,
296
+ 'some challenge',
297
+ mockOffers.all.map((offer) => offer.payload.id),
298
+ []
299
+ )
300
+ ),
301
+ expect.objectContaining({
302
+ value: mockOffers.sessionToken.value,
303
+ })
304
+ );
305
+
306
+ const savedCredential = await mongoDb()
307
+ .collection('credentials')
308
+ .findOne();
309
+
310
+ expect({
311
+ ...omit(['_id'], savedCredential),
312
+ id: savedCredential._id.toHexString(),
313
+ updatedAt: savedCredential.updatedAt.toISOString(),
314
+ createdAt: savedCredential.createdAt.toISOString(),
315
+ }).toEqual(mockParsedResponse.passedCredentials[0]);
316
+ });
317
+
318
+ it('should not allow accepting offers if email is not verified', async () => {
319
+ await mongoDb()
320
+ .collection('accounts')
321
+ .updateOne(
322
+ { userId: '1234567890' },
323
+ { $unset: { verificationInfo: '' } }
324
+ );
325
+
326
+ const response = await fastify.injectJson({
327
+ method: 'POST',
328
+ url: '/issuing/deep-link/accept-offers',
329
+ payload: {
330
+ credentialManifest: {
331
+ jwt: vclMockCredentialManifest.jwt.encodedJwt,
332
+ link: vclMockCredentialManifest.deepLink.value,
333
+ verifiedProfile: vclMockCredentialManifest.verifiedProfile.payload,
334
+ },
335
+ token: mockOffers.sessionToken.value,
336
+ offerIds: mockOffers.all.map((offer) => offer.id),
337
+ },
338
+ headers: {
339
+ authorization: `Bearer ${idToken}`,
340
+ },
341
+ });
342
+
343
+ expect(response.statusCode).toBe(403);
344
+ expect(response.json).toEqual(
345
+ errorResponseMatcher({
346
+ statusCode: 403,
347
+ error: 'Forbidden',
348
+ errorCode: WebWalletServerError,
349
+ message: 'Email verification is required.',
350
+ })
351
+ );
352
+ });
353
+
354
+ it('should not allow accepting offers if phone is not verified', async () => {
355
+ await mongoDb()
356
+ .collection('accounts')
357
+ .updateOne(
358
+ { userId: '1234567890' },
359
+ { $unset: { 'verificationInfo.phone': '' } }
360
+ );
361
+
362
+ const response = await fastify.injectJson({
363
+ method: 'POST',
364
+ url: '/issuing/deep-link/accept-offers',
365
+ payload: {
366
+ credentialManifest: {
367
+ jwt: vclMockCredentialManifest.jwt.encodedJwt,
368
+ link: vclMockCredentialManifest.deepLink.value,
369
+ verifiedProfile: vclMockCredentialManifest.verifiedProfile.payload,
370
+ },
371
+ token: mockOffers.sessionToken.value,
372
+ offerIds: mockOffers.all.map((offer) => offer.id),
373
+ },
374
+ headers: {
375
+ authorization: `Bearer ${idToken}`,
376
+ },
377
+ });
378
+
379
+ expect(response.statusCode).toBe(403);
380
+ expect(response.json).toEqual(
381
+ errorResponseMatcher({
382
+ statusCode: 403,
383
+ error: 'Forbidden',
384
+ errorCode: WebWalletServerError,
385
+ message: 'Phone verification is required.',
386
+ })
387
+ );
388
+ });
389
+
390
+ it('should not allow accepting offers if profile is not completed', async () => {
391
+ await mongoDb()
392
+ .collection('accounts')
393
+ .updateOne({ userId: '1234567890' }, { $unset: { profileName: '' } });
394
+
395
+ const response = await fastify.injectJson({
396
+ method: 'POST',
397
+ url: '/issuing/deep-link/accept-offers',
398
+ payload: {
399
+ credentialManifest: {
400
+ jwt: vclMockCredentialManifest.jwt.encodedJwt,
401
+ link: vclMockCredentialManifest.deepLink.value,
402
+ verifiedProfile: vclMockCredentialManifest.verifiedProfile.payload,
403
+ },
404
+ token: mockOffers.sessionToken.value,
405
+ offerIds: mockOffers.all.map((offer) => offer.id),
406
+ },
407
+ headers: {
408
+ authorization: `Bearer ${idToken}`,
409
+ },
410
+ });
411
+
412
+ expect(response.statusCode).toBe(403);
413
+ expect(response.json).toEqual(
414
+ errorResponseMatcher({
415
+ statusCode: 403,
416
+ error: 'Forbidden',
417
+ errorCode: WebWalletServerError,
418
+ message: 'Profile is not completed.',
419
+ })
420
+ );
421
+ });
422
+
423
+ it('should return 401 if no access token is provided', async () => {
424
+ const response = await fastify.injectJson({
425
+ method: 'POST',
426
+ url: '/issuing/deep-link/accept-offers',
427
+ payload: {
428
+ link: deepLink,
429
+ token: mockOffers.sessionToken.value,
430
+ offerIds: mockOffers.all.map((offer) => offer.id),
431
+ },
432
+ });
433
+
434
+ expect(response.statusCode).toBe(401);
435
+ });
436
+
437
+ it('should return 400 if no link is provided', async () => {
438
+ const response = await fastify.injectJson({
439
+ method: 'POST',
440
+ url: '/issuing/deep-link/accept-offers',
441
+ payload: {
442
+ token: mockOffers.sessionToken.value,
443
+ offerIds: mockOffers.all.map((offer) => offer.id),
444
+ },
445
+ headers: {
446
+ authorization: `Bearer ${idToken}`,
447
+ },
448
+ });
449
+
450
+ expect(response.statusCode).toBe(400);
451
+ });
452
+
453
+ it('should return 400 if no token is provided', async () => {
454
+ const response = await fastify.injectJson({
455
+ method: 'POST',
456
+ url: '/issuing/deep-link/accept-offers',
457
+ payload: {
458
+ link: deepLink,
459
+ offerIds: mockOffers.all.map((offer) => offer.id),
460
+ },
461
+ headers: {
462
+ authorization: `Bearer ${idToken}`,
463
+ },
464
+ });
465
+
466
+ expect(response.statusCode).toBe(400);
467
+ });
468
+
469
+ it('should return 400 if no offerIds is provided', async () => {
470
+ const response = await fastify.injectJson({
471
+ method: 'POST',
472
+ url: '/issuing/deep-link/accept-offers',
473
+ payload: {
474
+ link: deepLink,
475
+ token: mockOffers.sessionToken.value,
476
+ },
477
+ headers: {
478
+ authorization: `Bearer ${idToken}`,
479
+ },
480
+ });
481
+
482
+ expect(response.statusCode).toBe(400);
483
+ });
484
+ });
485
+ });
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
+ };