@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,88 @@
1
+ /* eslint-disable max-len */
2
+ const mockIssuers = {
3
+ all: [
4
+ {
5
+ payload: {
6
+ name: 'University of Massachusetts Amherst',
7
+ location: {
8
+ countryCode: 'US',
9
+ regionCode: 'MA',
10
+ },
11
+ logo: 'https://upload.wikimedia.org/wikipedia/commons/4/4f/UMass_Seal_Medium_PMS_202.png',
12
+ website: 'https://www.umass.edu/',
13
+ contactEmail: 'test@test.com',
14
+ technicalEmail: 'test@test.com',
15
+ description:
16
+ 'Test org, primarily for Issuing Education and Cource credentials',
17
+ founded: '2023-04-04',
18
+ type: 'company',
19
+ physicalAddress: {
20
+ line1: 'xxxx',
21
+ line2: 'xxxx',
22
+ line3: 'xxxx',
23
+ regionCode: 'XX-XX',
24
+ countryCode: 'XX',
25
+ postcode: 'xxxx',
26
+ },
27
+ linkedInProfile: 'https://xxxx.xxx',
28
+ id: 'did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA',
29
+ verifiableCredentialJwt:
30
+ 'https://devregistrar.velocitynetwork.foundation/api/v0.6/organizations/did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA/resolve-vc/a78a9c37-0345-4eb4-83da-53ad4322500e',
31
+ service: [
32
+ {
33
+ type: 'VlcCareerIssuer_v1',
34
+ id: '#velocity-issuer-1',
35
+ serviceEndpoint:
36
+ 'https://devagent.velocitycareerlabs.io/api/holder/v0.6/org/did:ion:EiApMLdMb4NPb8sae9-hXGHP79W1gisApVSE80USPEbtJA/issue/get-credential-manifest',
37
+ credentialTypes: [
38
+ 'EducationDegree',
39
+ 'EducationDegreeRegistrationV1.0',
40
+ 'EducationDegreeStudyV1.0',
41
+ 'EducationDegreeGraduationV1.0',
42
+ 'EducationDegreeRegistrationV1.1',
43
+ 'EducationDegreeStudyV1.1',
44
+ 'EducationDegreeGraduationV1.1',
45
+ 'PastEmploymentPosition',
46
+ 'CurrentEmploymentPosition',
47
+ 'EmploymentCurrentV1.0',
48
+ 'EmploymentPastV1.0',
49
+ 'EmploymentCurrentV1.1',
50
+ 'EmploymentPastV1.1',
51
+ 'Certification',
52
+ 'CertificationV1.0',
53
+ 'LicenseV1.0',
54
+ 'CertificationV1.1',
55
+ 'LicenseV1.1',
56
+ 'Course',
57
+ 'CourseRegistrationV1.0',
58
+ 'CourseCompletionV1.0',
59
+ 'CourseAttendanceV1.0',
60
+ 'CourseRegistrationV1.1',
61
+ 'CourseCompletionV1.1',
62
+ 'CourseAttendanceV1.1',
63
+ 'AssessmentDec2020',
64
+ 'AssessmentV1.0',
65
+ 'AssessmentV1.1',
66
+ 'Badge',
67
+ 'OpenBadgeV1.0',
68
+ ],
69
+ },
70
+ {
71
+ type: 'VlcInspector_v1',
72
+ id: '#velocity-inspector-1',
73
+ serviceEndpoint: 'https://devagent.velocitycareerlabs.io',
74
+ },
75
+ ],
76
+ permittedVelocityServiceCategory: ['Issuer', 'Inspector'],
77
+ createdAt: '2022-03-01T10:17:38.542Z',
78
+ updatedAt: '2023-06-26T13:36:05.180Z',
79
+ supportsSecureMessages: false,
80
+ },
81
+ TAG: 'VCLOrganization',
82
+ },
83
+ ],
84
+ };
85
+
86
+ module.exports = {
87
+ mockIssuers,
88
+ };
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Created by Michael Avoyan on 08/08/2024.
3
+ *
4
+ * Copyright 2022 Velocity Career Labs inc.
5
+ * SPDX-License-Identifier: Apache-2.0
6
+ */
7
+
8
+ const Jwk = {
9
+ keys: [
10
+ {
11
+ alg: 'RS512',
12
+ kid: 'KEY',
13
+ x5c: ['UNUSED'],
14
+ },
15
+ {
16
+ alg: 'RS256',
17
+ kid: 'KEY',
18
+ x5c: [
19
+ `
20
+ MIIEnjCCAoYCCQDmnGII6qzGlTANBgkqhkiG9w0BAQsFADARMQ8wDQYDVQQDDAZ1
21
+ bnVzZWQwHhcNMjEwOTE5MDcxODQ2WhcNMjExMDE5MDcxODQ2WjARMQ8wDQYDVQQD
22
+ DAZ1bnVzZWQwggIiMA0GCSqGSIb3DQEBAQUAA4ICDwAwggIKAoICAQDY2acJ8JAH
23
+ XjK8j3sAXOokSWwvaEg65UJS0C7KdnfbLTeaeYFHBRY0v9Jkk/PJSXv9hMWw1aD3
24
+ n7NrhVwXeRXi/7VZuW/S4ek+hK+IMDvpKqzn+XeCpaMoRpAgloADeNY0qhYKxpr2
25
+ L0SmRQDwVy1r/g31ECewD2WpEiRSmXsQ2Q2uYT3V60BmbhUw31KGEr4SLXL9pzmb
26
+ arOH/5Rhqg+YFMywNY6i01S3UdOlUtAyWT/mVRAkVTsUEou9tBw61zputPdMrl7p
27
+ d4InmlfCmXNTPFh9EDczPQiAVPq8MDyEdRGP134+HM9+YgQUZjy+WsxmGEvplJIf
28
+ KrYtlWe11//oAXC3690LUYtvg49lNY4+H0/nngjnCDXkZo6f+PEvnBZfYl596VTV
29
+ Fx4FGNOqLwg4bAyE5j5jXtEGW1oKo1pxBg7Oe3MteQUDwMrONB3CbxdxDiN3YH94
30
+ 2nWGW9Le+CeA1QUhfjQqSoZRJURGYGoztVuIXOElnkrgwcJreX4b8y+Uo5kpp2By
31
+ 6UUaD/mMj9XQ+Ygp/J8DlJlqDXOIp6JUJ75aSK5ZIjRtWq/Go5RUjW9IW0ldEehh
32
+ /4j0ZWC0vR1/le2UmAE6tXhkH4sdx9JM84V+qRzjiGqQx3Wn00uwMiHHhte17t41
33
+ vk+b75wuHbfiq9R8irL6wqWeeuzvCC37NwIDAQABMA0GCSqGSIb3DQEBCwUAA4IC
34
+ AQCZOT6S5HLUp0gBtWK6Fxyzb9lWPE+AJipjJ80lS3OnaOIyVtyJexJ2BjTKWldJ
35
+ 48zkzLNIRsTEGEipNS6NkrkElfmoaNBpdbDch2WBkME3UYlFIR9GgbXPMlACQlwJ
36
+ f4qT3iIZ9zjpVMP8F63TzRRr7KEYW2PGHEtVQktMPprGEfU4Sz0OIa9RRV+BLsfh
37
+ x8he2pimJEzoEaWPgyJXV1S+tLUif8A/CEkZVRZ2vADA7WMGl2ZTdbmsTjXh4bf2
38
+ A4l4Zec+jwOjUPiEk5lLJwv1KeYos9wuUczAk7ku8wRzyZbrjwgRam9VQA5qmRzJ
39
+ PegEQwJaKMRu8PPK0L4KFN4v3ma7Ux6D719nko8mZ0kA2oUs6phsFmoWQfsbRbsD
40
+ CdUGnM2fPp6V285r9w9Y6+1nVdtJpbAPFJR3SxIpfYVfx3tI6C3BR9bIMr8uCf81
41
+ G+Ebvo4qTuY6Cg/mTpPLZ4cKpwSvB6cE+xeSHvKIRYm6QUYEReRxQ3b4aUKBSNwl
42
+ FEQufVGhGzeblNC3fjP+mMtqbyC8c1zkHc6tjJYO5yesKf8bjO71by2jgSced7nN
43
+ 5JvJawfEcabgHJ1aAFLj0tlPMrViFzu6y8/A5aZLc5UMISXAZXfB4wIEdyUUXJh4
44
+ rJKE/ZCb2+W8g29N5cv2P6nhahT3mYatMiQ0U/gfaIrA0A==
45
+ `.trim(),
46
+ ],
47
+ },
48
+ ],
49
+ };
50
+
51
+ module.exports = {
52
+ Jwk,
53
+ };
@@ -0,0 +1,107 @@
1
+ const mockSchema = {
2
+ title: {
3
+ path: [
4
+ '$.hasCredential.issuer.name',
5
+ '$.hasCredential.issuer.id',
6
+ '$.hasCredential.issuer',
7
+ ],
8
+ schema: {
9
+ type: 'string',
10
+ },
11
+ fallback: '-',
12
+ },
13
+ subtitle: {
14
+ text: 'Open Badge',
15
+ },
16
+ summary_detail: {
17
+ path: ['$.hasCredential.name'],
18
+ schema: {
19
+ type: 'string',
20
+ },
21
+ fallback: '-',
22
+ },
23
+ description: {
24
+ text: 'Open badge',
25
+ },
26
+ logo: {
27
+ path: ['$.hasCredential.image'],
28
+ schema: {
29
+ type: 'string',
30
+ format: 'uri',
31
+ },
32
+ },
33
+ properties: [
34
+ {
35
+ label: 'Badge name',
36
+ path: ['$.hasCredential.name'],
37
+ schema: {
38
+ type: 'string',
39
+ },
40
+ fallback: '-',
41
+ },
42
+ {
43
+ label: '',
44
+ path: ['$.hasCredential.image'],
45
+ schema: {
46
+ type: 'string',
47
+ },
48
+ },
49
+ {
50
+ label: 'Description',
51
+ path: ['$.hasCredential.description'],
52
+ schema: {
53
+ type: 'string',
54
+ },
55
+ },
56
+ {
57
+ label: 'Type',
58
+ path: ['$.hasCredential.type'],
59
+ schema: {
60
+ type: 'string',
61
+ },
62
+ },
63
+ {
64
+ label: 'Criteria',
65
+ path: ['$.hasCredential.criteria', '$.hasCredential.criteria.narrative'],
66
+ schema: {
67
+ type: 'string',
68
+ },
69
+ },
70
+ {
71
+ label: 'Tags',
72
+ path: ['$.hasCredential.tags'],
73
+ schema: {
74
+ type: 'array',
75
+ items: {
76
+ type: 'string',
77
+ },
78
+ },
79
+ },
80
+ {
81
+ label: 'Alignment',
82
+ path: ['$.hasCredential.alignment[0].targetName'],
83
+ schema: {
84
+ type: 'string',
85
+ },
86
+ },
87
+ {
88
+ label: 'Alignment URL',
89
+ path: ['$.hasCredential.alignment[0].targetUrl'],
90
+ schema: {
91
+ type: 'string',
92
+ format: 'uri',
93
+ },
94
+ },
95
+ {
96
+ label: 'Alignment framework',
97
+ path: ['$.hasCredential.alignment[0].targetFramework'],
98
+ schema: {
99
+ type: 'string',
100
+ },
101
+ },
102
+ ],
103
+ };
104
+
105
+ module.exports = {
106
+ mockSchema,
107
+ };
@@ -0,0 +1,42 @@
1
+ const buildFastify = require('./helpers/webwallet-build-fastify');
2
+
3
+ jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
4
+ const originalModule = jest.requireActual(
5
+ '@velocitycareerlabs/vnf-nodejs-wallet-sdk'
6
+ );
7
+
8
+ return {
9
+ ...originalModule,
10
+ VCLProvider: {
11
+ getInstance: jest.fn().mockReturnValue({
12
+ initialize: jest.fn().mockResolvedValue(null),
13
+ }),
14
+ },
15
+ };
16
+ });
17
+
18
+ describe('Root routes', () => {
19
+ let fastify;
20
+
21
+ beforeAll(async () => {
22
+ fastify = buildFastify();
23
+ await fastify.ready();
24
+ });
25
+
26
+ afterAll(async () => {
27
+ await fastify.close();
28
+ });
29
+
30
+ it('should respond to /', async () => {
31
+ const response = await fastify.inject({
32
+ method: 'GET',
33
+ url: '/',
34
+ payload: { message: 'Hi' },
35
+ });
36
+
37
+ expect(response.statusCode).toEqual(200);
38
+ expect(response.body).toEqual(
39
+ 'Welcome to Webwallet Server\nVersion: 0.5.0-build\n'
40
+ );
41
+ });
42
+ });
@@ -0,0 +1,86 @@
1
+ const mockVclSdkInitialize = jest.fn();
2
+ jest.mock('@velocitycareerlabs/vnf-nodejs-wallet-sdk', () => {
3
+ const originalModule = jest.requireActual(
4
+ '@velocitycareerlabs/vnf-nodejs-wallet-sdk'
5
+ );
6
+ return {
7
+ ...originalModule,
8
+ VCLProvider: {
9
+ getInstance: jest.fn().mockReturnValue({
10
+ initialize: mockVclSdkInitialize,
11
+ }),
12
+ },
13
+ };
14
+ });
15
+ const {
16
+ VCLProvider,
17
+ VCLInitializationDescriptor,
18
+ } = require('@velocitycareerlabs/vnf-nodejs-wallet-sdk');
19
+ const { vnfSdkPlugin } = require('../src/plugins/vnf-sdk-plugin');
20
+
21
+ describe('Test vnf-sdk-plugin sdk initialization', () => {
22
+ const fastifyMock = {
23
+ decorate: jest.fn().mockReturnThis(),
24
+ decorateRequest: jest.fn().mockReturnThis(),
25
+ addHook: jest.fn().mockReturnThis(),
26
+ log: { error: jest.fn() },
27
+ sendError: jest.fn().mockReturnThis(),
28
+ config: {},
29
+ close: jest.fn().mockReturnThis(),
30
+ };
31
+ const next = jest.fn();
32
+
33
+ beforeEach(() => {
34
+ jest.clearAllMocks();
35
+ });
36
+
37
+ it('should initialize vnf sdk successfully', async () => {
38
+ const vclSdk = VCLProvider.getInstance();
39
+ mockVclSdkInitialize.mockResolvedValue(null);
40
+
41
+ await vnfSdkPlugin(fastifyMock, {}, next);
42
+
43
+ expect(VCLProvider.getInstance).toHaveBeenCalled();
44
+ expect(vclSdk.initialize).toHaveBeenCalledWith(
45
+ expect.any(VCLInitializationDescriptor)
46
+ );
47
+ expect(fastifyMock.decorate).toHaveBeenCalledWith('vclSdk', vclSdk);
48
+ expect(fastifyMock.decorateRequest).toHaveBeenCalledWith('vclSdk', null);
49
+ expect(fastifyMock.addHook).toHaveBeenCalledWith(
50
+ 'preValidation',
51
+ expect.any(Function)
52
+ );
53
+ expect(next).toHaveBeenCalledTimes(0);
54
+ // catch block:
55
+ expect(fastifyMock.log.error).toHaveBeenCalledTimes(0);
56
+ expect(fastifyMock.sendError).toHaveBeenCalledTimes(0);
57
+ });
58
+
59
+ it('should handle vnf sdk initialization error', async () => {
60
+ const expectedError = new Error('VNF SDK initialization error');
61
+
62
+ const vclSdk = VCLProvider.getInstance();
63
+ mockVclSdkInitialize.mockRejectedValueOnce(expectedError);
64
+
65
+ await expect(vnfSdkPlugin(fastifyMock, {}, next)).rejects.toThrow(
66
+ expectedError
67
+ );
68
+ expect(VCLProvider.getInstance).toHaveBeenCalled();
69
+ expect(vclSdk.initialize).toHaveBeenCalledWith(
70
+ expect.any(VCLInitializationDescriptor)
71
+ );
72
+ expect(fastifyMock.decorate).toHaveBeenCalledTimes(0);
73
+ expect(fastifyMock.decorateRequest).toHaveBeenCalledTimes(0);
74
+ expect(fastifyMock.addHook).toHaveBeenCalledTimes(0);
75
+ expect(next).toHaveBeenCalledTimes(0);
76
+ // catch block:
77
+ expect(fastifyMock.log.error).toHaveBeenCalledTimes(1);
78
+ expect(fastifyMock.log.error).toHaveBeenCalledWith(
79
+ expect.objectContaining(expectedError)
80
+ );
81
+ expect(fastifyMock.sendError).toHaveBeenCalledTimes(1);
82
+ expect(fastifyMock.sendError).toHaveBeenCalledWith(
83
+ expect.objectContaining(expectedError)
84
+ );
85
+ });
86
+ });