apacuana-sdk-core 0.9.0 → 0.11.0
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/README.md +320 -236
- package/coverage/clover.xml +341 -212
- package/coverage/coverage-final.json +9 -7
- package/coverage/lcov-report/index.html +34 -19
- package/coverage/lcov-report/src/api/certs.js.html +493 -37
- package/coverage/lcov-report/src/api/faceLiveness.js.html +496 -0
- package/coverage/lcov-report/src/api/index.html +43 -28
- package/coverage/lcov-report/src/api/revocations.js.html +103 -106
- package/coverage/lcov-report/src/api/signatures.js.html +25 -253
- package/coverage/lcov-report/src/api/users.js.html +7 -13
- package/coverage/lcov-report/src/config/index.html +1 -1
- package/coverage/lcov-report/src/config/index.js.html +1 -1
- package/coverage/lcov-report/src/errors/index.html +1 -1
- package/coverage/lcov-report/src/errors/index.js.html +8 -8
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.js.html +48 -3
- package/coverage/lcov-report/src/success/index.html +116 -0
- package/coverage/lcov-report/src/success/index.js.html +106 -0
- package/coverage/lcov-report/src/utils/constant.js.html +4 -4
- package/coverage/lcov-report/src/utils/helpers.js.html +1 -1
- package/coverage/lcov-report/src/utils/httpClient.js.html +1 -1
- package/coverage/lcov-report/src/utils/index.html +1 -1
- package/coverage/lcov.info +591 -352
- package/dist/api/certs.d.ts +13 -30
- package/dist/api/faceLiveness.d.ts +6 -0
- package/dist/api/revocations.d.ts +3 -42
- package/dist/api/signatures.d.ts +11 -153
- package/dist/index.d.ts +10 -0
- package/dist/index.js +630 -214
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +630 -214
- package/dist/index.mjs.map +1 -1
- package/dist/success/index.d.ts +7 -0
- package/dist/types/certs.d.ts +97 -0
- package/dist/types/faceLiveness.d.ts +10 -0
- package/dist/types/revocations.d.ts +40 -0
- package/dist/types/signatures.d.ts +152 -0
- package/dist/types/users.d.ts +260 -0
- package/package.json +1 -1
- package/src/api/certs.js +175 -23
- package/src/api/faceLiveness.js +137 -0
- package/src/api/revocations.js +66 -67
- package/src/api/signatures.js +21 -97
- package/src/api/users.js +4 -6
- package/src/index.js +16 -1
- package/src/success/index.js +8 -0
- package/src/types/certs.js +56 -0
- package/src/types/faceLiveness.js +7 -0
- package/src/types/revocations.js +25 -0
- package/src/types/signatures.js +77 -0
- package/src/types/users.js +73 -0
- package/tests/api/certs.test.js +209 -4
- package/tests/api/faceLiveness.test.js +172 -0
- package/tests/api/revocations.test.js +37 -37
- package/tests/api/signatures.test.js +11 -5
- package/tests/api/users.test.js +3 -2
package/tests/api/certs.test.js
CHANGED
|
@@ -2,7 +2,14 @@ import { getConfig } from "../../src/config/index";
|
|
|
2
2
|
import { httpRequest } from "../../src/utils/httpClient";
|
|
3
3
|
import helpers from "../../src/utils/helpers";
|
|
4
4
|
import { ApacuanaAPIError } from "../../src/errors";
|
|
5
|
-
import
|
|
5
|
+
import ApacuanaSuccess from "../../src/success";
|
|
6
|
+
import {
|
|
7
|
+
generateCert,
|
|
8
|
+
getCertStatus,
|
|
9
|
+
getCertTypes,
|
|
10
|
+
getRequerimentsByTypeUser,
|
|
11
|
+
requestCertificate,
|
|
12
|
+
} from "../../src/api/certs";
|
|
6
13
|
import { INTEGRATION_TYPE } from "../../src/utils/constant";
|
|
7
14
|
|
|
8
15
|
jest.mock("../../src/config/index");
|
|
@@ -38,10 +45,10 @@ describe("Certificate API - certs.js", () => {
|
|
|
38
45
|
mockEncryptedCsr,
|
|
39
46
|
"POST"
|
|
40
47
|
);
|
|
41
|
-
expect(result).
|
|
48
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
49
|
+
expect(result.data).toEqual({
|
|
42
50
|
cert: "onboarding-cert",
|
|
43
51
|
certifiedid: "onboarding-certified-id",
|
|
44
|
-
success: true,
|
|
45
52
|
});
|
|
46
53
|
});
|
|
47
54
|
|
|
@@ -88,7 +95,205 @@ describe("Certificate API - certs.js", () => {
|
|
|
88
95
|
mockUserData,
|
|
89
96
|
true
|
|
90
97
|
);
|
|
91
|
-
expect(result).
|
|
98
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
99
|
+
expect(result.data).toEqual({ status: "VALID" });
|
|
92
100
|
});
|
|
93
101
|
});
|
|
102
|
+
|
|
103
|
+
describe("getCertTypes", () => {
|
|
104
|
+
it("should call getCertTypesOnBoarding for ONBOARDING integration", async () => {
|
|
105
|
+
getConfig.mockReturnValue({
|
|
106
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
107
|
+
});
|
|
108
|
+
const mockApiResponse = { types: [{ id: "1", name: "Type 1" }] };
|
|
109
|
+
httpRequest.mockResolvedValue(mockApiResponse);
|
|
110
|
+
|
|
111
|
+
const result = await getCertTypes();
|
|
112
|
+
|
|
113
|
+
expect(httpRequest).toHaveBeenCalledWith(
|
|
114
|
+
"services/api/customer/typeusers",
|
|
115
|
+
{},
|
|
116
|
+
"GET"
|
|
117
|
+
);
|
|
118
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
119
|
+
expect(result.data).toEqual({ types: mockApiResponse.types });
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
it("should throw an error for ONPREMISE integration", async () => {
|
|
123
|
+
getConfig.mockReturnValue({
|
|
124
|
+
integrationType: INTEGRATION_TYPE.ONPREMISE,
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
await expect(getCertTypes()).rejects.toThrow(
|
|
128
|
+
new ApacuanaAPIError(
|
|
129
|
+
"Getting certificate types is not supported for integration type: ONPREMISE",
|
|
130
|
+
501,
|
|
131
|
+
"NOT_IMPLEMENTED"
|
|
132
|
+
)
|
|
133
|
+
);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("should throw an error for an unsupported integration type", async () => {
|
|
137
|
+
getConfig.mockReturnValue({ integrationType: "INVALID_TYPE" });
|
|
138
|
+
|
|
139
|
+
await expect(getCertTypes()).rejects.toThrow(
|
|
140
|
+
new ApacuanaAPIError(
|
|
141
|
+
"Unsupported integration type: INVALID_TYPE",
|
|
142
|
+
400,
|
|
143
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
144
|
+
)
|
|
145
|
+
);
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
describe("getRequerimentsByTypeUser", () => {
|
|
150
|
+
it("should call getRequerimentsByTypeUserOnBoarding for ONBOARDING integration", async () => {
|
|
151
|
+
getConfig.mockReturnValue({
|
|
152
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
153
|
+
});
|
|
154
|
+
const mockApiResponse = {
|
|
155
|
+
requirements: [{ id: "1", description: "Requirement 1" }],
|
|
156
|
+
};
|
|
157
|
+
httpRequest.mockResolvedValue(mockApiResponse);
|
|
158
|
+
|
|
159
|
+
const result = await getRequerimentsByTypeUser({ type: 1 });
|
|
160
|
+
|
|
161
|
+
expect(httpRequest).toHaveBeenCalledWith(
|
|
162
|
+
"services/api/customer/documentspref?typeuser=1",
|
|
163
|
+
{},
|
|
164
|
+
"GET"
|
|
165
|
+
);
|
|
166
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
167
|
+
expect(result.data).toEqual({
|
|
168
|
+
requirements: mockApiResponse.requirements,
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
it("should throw an error for ONPREMISE integration", async () => {
|
|
173
|
+
getConfig.mockReturnValue({
|
|
174
|
+
integrationType: INTEGRATION_TYPE.ONPREMISE,
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
await expect(getRequerimentsByTypeUser({ type: 1 })).rejects.toThrow(
|
|
178
|
+
new ApacuanaAPIError(
|
|
179
|
+
"Getting requirements by user type is not supported for integration type: ONPREMISE",
|
|
180
|
+
501,
|
|
181
|
+
"NOT_IMPLEMENTED"
|
|
182
|
+
)
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("should throw an error for an unsupported integration type", async () => {
|
|
187
|
+
getConfig.mockReturnValue({ integrationType: "INVALID_TYPE" });
|
|
188
|
+
|
|
189
|
+
await expect(getRequerimentsByTypeUser({ type: 1 })).rejects.toThrow(
|
|
190
|
+
new ApacuanaAPIError(
|
|
191
|
+
"Unsupported integration type: INVALID_TYPE",
|
|
192
|
+
400,
|
|
193
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
194
|
+
)
|
|
195
|
+
);
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
it("should throw an error if params are invalid", async () => {
|
|
199
|
+
await expect(getRequerimentsByTypeUser()).rejects.toThrow(
|
|
200
|
+
'The "params" object with a numeric "type" property is required.'
|
|
201
|
+
);
|
|
202
|
+
await expect(getRequerimentsByTypeUser({})).rejects.toThrow(
|
|
203
|
+
'The "params" object with a numeric "type" property is required.'
|
|
204
|
+
);
|
|
205
|
+
await expect(getRequerimentsByTypeUser({ type: "1" })).rejects.toThrow(
|
|
206
|
+
'The "params" object with a numeric "type" property is required.'
|
|
207
|
+
);
|
|
208
|
+
});
|
|
209
|
+
it("should throw a generic error for other failures", async () => {
|
|
210
|
+
getConfig.mockReturnValue({
|
|
211
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
212
|
+
});
|
|
213
|
+
const genericError = new Error("Network failure");
|
|
214
|
+
httpRequest.mockRejectedValue(genericError);
|
|
215
|
+
|
|
216
|
+
await expect(getRequerimentsByTypeUser({ type: 1 })).rejects.toThrow(
|
|
217
|
+
`Failed to get requirements: ${genericError.message}`
|
|
218
|
+
);
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
|
|
223
|
+
describe("requestCertificate", () => {
|
|
224
|
+
const validParams = { type: 1, documents: [] };
|
|
225
|
+
|
|
226
|
+
afterEach(() => {
|
|
227
|
+
jest.clearAllMocks();
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
it("should throw an error if params are invalid", async () => {
|
|
231
|
+
await expect(requestCertificate()).rejects.toThrow(
|
|
232
|
+
'The "params" object with a numeric "type" property and a "documents" array is required.'
|
|
233
|
+
);
|
|
234
|
+
await expect(requestCertificate({ type: 1 })).rejects.toThrow(
|
|
235
|
+
'The "params" object with a numeric "type" property and a "documents" array is required.'
|
|
236
|
+
);
|
|
237
|
+
await expect(requestCertificate({ documents: [] })).rejects.toThrow(
|
|
238
|
+
'The "params" object with a numeric "type" property and a "documents" array is required.'
|
|
239
|
+
);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("should request a certificate for ONBOARDING integration", async () => {
|
|
243
|
+
getConfig.mockReturnValue({ integrationType: INTEGRATION_TYPE.ONBOARDING });
|
|
244
|
+
const mockResponse = { message: "Certificate requested" };
|
|
245
|
+
httpRequest.mockResolvedValue(mockResponse);
|
|
246
|
+
|
|
247
|
+
const result = await requestCertificate(validParams);
|
|
248
|
+
|
|
249
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
250
|
+
expect(result.data).toEqual(mockResponse);
|
|
251
|
+
expect(httpRequest).toHaveBeenCalledWith(
|
|
252
|
+
"services/api/customer/request-certificate",
|
|
253
|
+
validParams,
|
|
254
|
+
"POST"
|
|
255
|
+
);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("should throw a NOT_IMPLEMENTED error for ONPREMISE integration", async () => {
|
|
259
|
+
getConfig.mockReturnValue({ integrationType: INTEGRATION_TYPE.ONPREMISE });
|
|
260
|
+
|
|
261
|
+
await expect(requestCertificate(validParams)).rejects.toThrow(
|
|
262
|
+
new ApacuanaAPIError(
|
|
263
|
+
"Requesting a certificate is not supported for integration type: ONPREMISE",
|
|
264
|
+
501,
|
|
265
|
+
"NOT_IMPLEMENTED"
|
|
266
|
+
)
|
|
267
|
+
);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
it("should throw an UNSUPPORTED_INTEGRATION_TYPE error for unsupported integration types", async () => {
|
|
271
|
+
getConfig.mockReturnValue({ integrationType: "unsupported-type" });
|
|
272
|
+
|
|
273
|
+
await expect(requestCertificate(validParams)).rejects.toThrow(
|
|
274
|
+
new ApacuanaAPIError(
|
|
275
|
+
"Unsupported integration type: unsupported-type",
|
|
276
|
+
400,
|
|
277
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
278
|
+
)
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
it("should re-throw ApacuanaAPIError if caught", async () => {
|
|
283
|
+
getConfig.mockReturnValue({ integrationType: INTEGRATION_TYPE.ONBOARDING });
|
|
284
|
+
const apiError = new ApacuanaAPIError("API Error", 500, "API_ERROR");
|
|
285
|
+
httpRequest.mockRejectedValue(apiError);
|
|
286
|
+
|
|
287
|
+
await expect(requestCertificate(validParams)).rejects.toThrow(apiError);
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
it("should throw a generic error for other failures", async () => {
|
|
291
|
+
getConfig.mockReturnValue({ integrationType: INTEGRATION_TYPE.ONBOARDING });
|
|
292
|
+
const genericError = new Error("Network failure");
|
|
293
|
+
httpRequest.mockRejectedValue(genericError);
|
|
294
|
+
|
|
295
|
+
await expect(requestCertificate(validParams)).rejects.toThrow(
|
|
296
|
+
`Failed to request certificate: ${genericError.message}`
|
|
297
|
+
);
|
|
298
|
+
});
|
|
94
299
|
});
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
import * as faceLiveness from "../../src/api/faceLiveness";
|
|
2
|
+
import { httpRequest } from "../../src/utils/httpClient";
|
|
3
|
+
import { getConfig } from "../../src/config";
|
|
4
|
+
import { ApacuanaAPIError } from "../../src/errors";
|
|
5
|
+
import ApacuanaSuccess from "../../src/success";
|
|
6
|
+
import { INTEGRATION_TYPE } from "../../src/utils/constant";
|
|
7
|
+
|
|
8
|
+
jest.mock("../../src/utils/httpClient", () => ({
|
|
9
|
+
httpRequest: jest.fn(),
|
|
10
|
+
}));
|
|
11
|
+
|
|
12
|
+
jest.mock("../../src/config", () => ({
|
|
13
|
+
getConfig: jest.fn(),
|
|
14
|
+
}));
|
|
15
|
+
|
|
16
|
+
describe("FaceLiveness API", () => {
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jest.clearAllMocks();
|
|
19
|
+
getConfig.mockReturnValue({ integrationType: INTEGRATION_TYPE.ONBOARDING });
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
describe("createFaceLivenessSession", () => {
|
|
23
|
+
it("should create a session for ONBOARDING integration", async () => {
|
|
24
|
+
httpRequest.mockResolvedValue({ sessionId: "test-session-id" });
|
|
25
|
+
|
|
26
|
+
const result = await faceLiveness.createFaceLivenessSession();
|
|
27
|
+
|
|
28
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
29
|
+
expect(result.data).toEqual({ sessionId: "test-session-id" });
|
|
30
|
+
expect(httpRequest).toHaveBeenCalledWith(
|
|
31
|
+
"services/api/faceliveness/create",
|
|
32
|
+
{},
|
|
33
|
+
"POST"
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("should throw an error if API response does not contain sessionId for ONBOARDING", async () => {
|
|
38
|
+
httpRequest.mockResolvedValue({}); // No sessionId
|
|
39
|
+
|
|
40
|
+
await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
|
|
41
|
+
new ApacuanaAPIError(
|
|
42
|
+
"The API response does not contain the session ID.",
|
|
43
|
+
undefined,
|
|
44
|
+
"INVALID_API_RESPONSE"
|
|
45
|
+
)
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should throw a NOT_IMPLEMENTED error for ONPREMISE integration", async () => {
|
|
50
|
+
getConfig.mockReturnValue({
|
|
51
|
+
integrationType: INTEGRATION_TYPE.ONPREMISE,
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
|
|
55
|
+
new ApacuanaAPIError(
|
|
56
|
+
"Creating a Face Liveness session is not supported for integration type: ONPREMISE",
|
|
57
|
+
501,
|
|
58
|
+
"NOT_IMPLEMENTED"
|
|
59
|
+
)
|
|
60
|
+
);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("should throw an UNSUPPORTED_INTEGRATION_TYPE error for unsupported integration types", async () => {
|
|
64
|
+
getConfig.mockReturnValue({ integrationType: "unsupported-type" });
|
|
65
|
+
|
|
66
|
+
await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
|
|
67
|
+
new ApacuanaAPIError(
|
|
68
|
+
"Unsupported integration type: unsupported-type",
|
|
69
|
+
400,
|
|
70
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
71
|
+
)
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it("should re-throw ApacuanaAPIError if caught during session creation", async () => {
|
|
76
|
+
const apiError = new ApacuanaAPIError("API Error", 500, "API_ERROR");
|
|
77
|
+
httpRequest.mockRejectedValue(apiError);
|
|
78
|
+
|
|
79
|
+
await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
|
|
80
|
+
apiError
|
|
81
|
+
);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it("should throw a generic error for other failures during session creation", async () => {
|
|
85
|
+
const genericError = new Error("Network Error");
|
|
86
|
+
httpRequest.mockRejectedValue(genericError);
|
|
87
|
+
|
|
88
|
+
await expect(faceLiveness.createFaceLivenessSession()).rejects.toThrow(
|
|
89
|
+
`Failed to create Face Liveness session: ${genericError.message}`
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
describe("validateFaceLiveness", () => {
|
|
95
|
+
const sessionId = "test-session-id";
|
|
96
|
+
|
|
97
|
+
it("should throw an error if sessionId is not provided", async () => {
|
|
98
|
+
await expect(faceLiveness.validateFaceLiveness({})).rejects.toThrow(
|
|
99
|
+
new ApacuanaAPIError(
|
|
100
|
+
"sessionId is a required parameter.",
|
|
101
|
+
400,
|
|
102
|
+
"INVALID_PARAMETER"
|
|
103
|
+
)
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("should return 'verified' on status 200", async () => {
|
|
108
|
+
httpRequest.mockResolvedValue({ someData: "data" });
|
|
109
|
+
|
|
110
|
+
const result = await faceLiveness.validateFaceLiveness({ sessionId });
|
|
111
|
+
|
|
112
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
113
|
+
expect(result.data).toEqual({ status: "verified", someData: "data" });
|
|
114
|
+
expect(httpRequest).toHaveBeenCalledWith(
|
|
115
|
+
"services/api/faceliveness/validate",
|
|
116
|
+
{ sessionid: sessionId },
|
|
117
|
+
"POST"
|
|
118
|
+
);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it.each([
|
|
122
|
+
[402, "waitingForScan"],
|
|
123
|
+
[403, "rejected"],
|
|
124
|
+
[406, "processing"],
|
|
125
|
+
[408, "expired"],
|
|
126
|
+
])(
|
|
127
|
+
"should return status '%s' for statusCode %i",
|
|
128
|
+
async (statusCode, status) => {
|
|
129
|
+
const apiError = new ApacuanaAPIError(
|
|
130
|
+
"Error",
|
|
131
|
+
statusCode,
|
|
132
|
+
"API_ERROR"
|
|
133
|
+
);
|
|
134
|
+
httpRequest.mockRejectedValue(apiError);
|
|
135
|
+
|
|
136
|
+
const result = await faceLiveness.validateFaceLiveness({ sessionId });
|
|
137
|
+
|
|
138
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
139
|
+
expect(result.data).toEqual({ status });
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
it("should throw an error for unhandled status codes", async () => {
|
|
144
|
+
const apiError = new ApacuanaAPIError(
|
|
145
|
+
"Unhandled Error",
|
|
146
|
+
500,
|
|
147
|
+
"API_ERROR"
|
|
148
|
+
);
|
|
149
|
+
httpRequest.mockRejectedValue(apiError);
|
|
150
|
+
|
|
151
|
+
await expect(
|
|
152
|
+
faceLiveness.validateFaceLiveness({ sessionId })
|
|
153
|
+
).rejects.toThrow(apiError);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("should throw a NOT_IMPLEMENTED error for ONPREMISE integration", async () => {
|
|
157
|
+
getConfig.mockReturnValue({
|
|
158
|
+
integrationType: INTEGRATION_TYPE.ONPREMISE,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
await expect(
|
|
162
|
+
faceLiveness.validateFaceLiveness({ sessionId })
|
|
163
|
+
).rejects.toThrow(
|
|
164
|
+
new ApacuanaAPIError(
|
|
165
|
+
"Validating a Face Liveness session is not supported for integration type: ONPREMISE",
|
|
166
|
+
501,
|
|
167
|
+
"NOT_IMPLEMENTED"
|
|
168
|
+
)
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
});
|
|
172
|
+
});
|
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { httpRequest } from "../../src/utils/httpClient";
|
|
2
|
-
import { ApacuanaAPIError } from "../../src/errors";
|
|
3
1
|
import {
|
|
4
2
|
requestRevocation,
|
|
5
3
|
getRevocationReasons,
|
|
6
4
|
} from "../../src/api/revocations";
|
|
5
|
+
import { httpRequest } from "../../src/utils/httpClient";
|
|
7
6
|
import { getConfig } from "../../src/config";
|
|
7
|
+
import { ApacuanaAPIError } from "../../src/errors";
|
|
8
|
+
import ApacuanaSuccess from "../../src/success";
|
|
8
9
|
import { INTEGRATION_TYPE } from "../../src/utils/constant";
|
|
9
10
|
|
|
10
11
|
jest.mock("../../src/utils/httpClient");
|
|
@@ -13,67 +14,72 @@ jest.mock("../../src/config");
|
|
|
13
14
|
describe("Revocations API", () => {
|
|
14
15
|
beforeEach(() => {
|
|
15
16
|
jest.clearAllMocks();
|
|
17
|
+
getConfig.mockReturnValue({ integrationType: INTEGRATION_TYPE.ONBOARDING });
|
|
16
18
|
});
|
|
17
19
|
|
|
18
20
|
describe("requestRevocation", () => {
|
|
19
21
|
it("should throw an error if reasonCode is not provided", async () => {
|
|
20
22
|
await expect(requestRevocation(null)).rejects.toThrow(
|
|
21
|
-
"
|
|
23
|
+
'The "params" object with a numeric "reasonCode" property is required.'
|
|
24
|
+
);
|
|
25
|
+
await expect(requestRevocation({})).rejects.toThrow(
|
|
26
|
+
'The "params" object with a numeric "reasonCode" property is required.'
|
|
22
27
|
);
|
|
23
28
|
});
|
|
24
29
|
|
|
25
30
|
it("should make a POST request to the correct endpoint with the reasonCode", async () => {
|
|
26
|
-
const
|
|
27
|
-
const mockResponse = { success: true
|
|
31
|
+
const params = { reasonCode: 1 };
|
|
32
|
+
const mockResponse = { success: true };
|
|
28
33
|
httpRequest.mockResolvedValue(mockResponse);
|
|
29
34
|
|
|
30
|
-
const result = await requestRevocation(
|
|
35
|
+
const result = await requestRevocation(params);
|
|
31
36
|
|
|
32
37
|
expect(httpRequest).toHaveBeenCalledWith(
|
|
33
|
-
"services/api/
|
|
34
|
-
|
|
38
|
+
"services/api/certificate/revocation",
|
|
39
|
+
params,
|
|
35
40
|
"POST"
|
|
36
41
|
);
|
|
37
|
-
expect(result).
|
|
42
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
43
|
+
expect(result.data).toEqual(mockResponse);
|
|
38
44
|
});
|
|
39
45
|
|
|
40
46
|
it("should throw a generic error if the httpRequest fails", async () => {
|
|
41
|
-
const
|
|
42
|
-
const apiError = new Error("
|
|
47
|
+
const params = { reasonCode: 1 };
|
|
48
|
+
const apiError = new Error("Something went wrong");
|
|
43
49
|
httpRequest.mockRejectedValue(apiError);
|
|
44
50
|
|
|
45
|
-
await expect(requestRevocation(
|
|
46
|
-
`
|
|
51
|
+
await expect(requestRevocation(params)).rejects.toThrow(
|
|
52
|
+
`Failed to request revocation: ${apiError.message}`
|
|
47
53
|
);
|
|
48
54
|
});
|
|
55
|
+
|
|
56
|
+
it("should re-throw ApacuanaAPIError if caught", async () => {
|
|
57
|
+
const params = { reasonCode: 1 };
|
|
58
|
+
const apiError = new ApacuanaAPIError("API Error");
|
|
59
|
+
httpRequest.mockRejectedValue(apiError);
|
|
60
|
+
|
|
61
|
+
await expect(requestRevocation(params)).rejects.toThrow(apiError);
|
|
62
|
+
});
|
|
49
63
|
});
|
|
50
64
|
|
|
51
65
|
describe("getRevocationReasons", () => {
|
|
52
66
|
it("should make a GET request and return the reasons for ONBOARDING", async () => {
|
|
53
|
-
|
|
54
|
-
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
55
|
-
});
|
|
56
|
-
const mockReasons = [
|
|
57
|
-
{ code: "0", description: "Unspecified" },
|
|
58
|
-
{ code: "1", description: "Key Compromise" },
|
|
59
|
-
];
|
|
67
|
+
const mockReasons = [{ code: 1, reason: "Test Reason" }];
|
|
60
68
|
httpRequest.mockResolvedValue({ records: mockReasons });
|
|
61
69
|
|
|
62
70
|
const result = await getRevocationReasons();
|
|
63
71
|
|
|
64
72
|
expect(httpRequest).toHaveBeenCalledWith(
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
73
|
+
"services/api/certificate/revocation-reasons",
|
|
74
|
+
{},
|
|
75
|
+
"GET"
|
|
68
76
|
);
|
|
69
|
-
expect(result).
|
|
77
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
78
|
+
expect(result.data).toEqual(mockReasons);
|
|
70
79
|
});
|
|
71
80
|
|
|
72
81
|
it("should throw an error if the API response does not contain 'records'", async () => {
|
|
73
|
-
|
|
74
|
-
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
75
|
-
});
|
|
76
|
-
httpRequest.mockResolvedValue({ data: [] }); // Respuesta inválida
|
|
82
|
+
httpRequest.mockResolvedValue({ data: [] }); // Invalid response
|
|
77
83
|
|
|
78
84
|
await expect(getRevocationReasons()).rejects.toThrow(
|
|
79
85
|
new ApacuanaAPIError("Failed to fetch revocation reasons.")
|
|
@@ -81,24 +87,18 @@ describe("Revocations API", () => {
|
|
|
81
87
|
});
|
|
82
88
|
|
|
83
89
|
it("should re-throw ApacuanaAPIError if caught", async () => {
|
|
84
|
-
|
|
85
|
-
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
86
|
-
});
|
|
87
|
-
const apiError = new ApacuanaAPIError("API is down", 500);
|
|
90
|
+
const apiError = new ApacuanaAPIError("API Error");
|
|
88
91
|
httpRequest.mockRejectedValue(apiError);
|
|
89
92
|
|
|
90
93
|
await expect(getRevocationReasons()).rejects.toThrow(apiError);
|
|
91
94
|
});
|
|
92
95
|
|
|
93
96
|
it("should throw a generic error for other types of errors", async () => {
|
|
94
|
-
getConfig.mockReturnValue({
|
|
95
|
-
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
96
|
-
});
|
|
97
97
|
const genericError = new Error("Something went wrong");
|
|
98
98
|
httpRequest.mockRejectedValue(genericError);
|
|
99
99
|
|
|
100
100
|
await expect(getRevocationReasons()).rejects.toThrow(
|
|
101
|
-
|
|
101
|
+
`Failed to get revocation reasons: ${genericError.message}`
|
|
102
102
|
);
|
|
103
103
|
});
|
|
104
104
|
|
|
@@ -109,7 +109,7 @@ describe("Revocations API", () => {
|
|
|
109
109
|
|
|
110
110
|
await expect(getRevocationReasons()).rejects.toThrow(
|
|
111
111
|
new ApacuanaAPIError(
|
|
112
|
-
"
|
|
112
|
+
"Getting revocation reasons is not supported for integration type: ONPREMISE",
|
|
113
113
|
501,
|
|
114
114
|
"NOT_IMPLEMENTED"
|
|
115
115
|
)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getConfig } from "../../src/config";
|
|
2
2
|
import { httpRequest } from "../../src/utils/httpClient";
|
|
3
3
|
import { ApacuanaAPIError } from "../../src/errors";
|
|
4
|
+
import ApacuanaSuccess from "../../src/success";
|
|
4
5
|
import {
|
|
5
6
|
addSigner,
|
|
6
7
|
getDocs,
|
|
@@ -184,7 +185,8 @@ describe("API - Signatures", () => {
|
|
|
184
185
|
{ publickey: signData.cert },
|
|
185
186
|
"POST"
|
|
186
187
|
);
|
|
187
|
-
expect(result).
|
|
188
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
189
|
+
expect(result.data).toEqual({ digest: "test-digest" });
|
|
188
190
|
});
|
|
189
191
|
|
|
190
192
|
it("should throw an error if digest is not in response for ONBOARDING", async () => {
|
|
@@ -257,7 +259,8 @@ describe("API - Signatures", () => {
|
|
|
257
259
|
},
|
|
258
260
|
"PUT"
|
|
259
261
|
);
|
|
260
|
-
expect(result).
|
|
262
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
263
|
+
expect(result.data).toEqual(mockResponse);
|
|
261
264
|
});
|
|
262
265
|
|
|
263
266
|
it("should throw not implemented for ONPREMISE integration", async () => {
|
|
@@ -346,7 +349,8 @@ describe("API - Signatures", () => {
|
|
|
346
349
|
{ file: validFile },
|
|
347
350
|
"POST"
|
|
348
351
|
);
|
|
349
|
-
expect(result).
|
|
352
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
353
|
+
expect(result.data).toEqual({ success: true, id: "123" });
|
|
350
354
|
});
|
|
351
355
|
|
|
352
356
|
it("should throw not implemented for ONPREMISE integration", async () => {
|
|
@@ -392,7 +396,8 @@ describe("API - Signatures", () => {
|
|
|
392
396
|
{},
|
|
393
397
|
"GET"
|
|
394
398
|
);
|
|
395
|
-
expect(result).
|
|
399
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
400
|
+
expect(result.data).toEqual(mockResponse);
|
|
396
401
|
});
|
|
397
402
|
|
|
398
403
|
it("should throw not implemented for ONPREMISE integration", async () => {
|
|
@@ -436,7 +441,8 @@ describe("API - Signatures", () => {
|
|
|
436
441
|
{},
|
|
437
442
|
"DELETE"
|
|
438
443
|
);
|
|
439
|
-
expect(result).
|
|
444
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
445
|
+
expect(result.data).toEqual(mockResponse);
|
|
440
446
|
});
|
|
441
447
|
|
|
442
448
|
it("should throw not implemented for ONPREMISE integration", async () => {
|
package/tests/api/users.test.js
CHANGED
|
@@ -3,6 +3,7 @@ import { httpRequest } from "../../src/utils/httpClient.js";
|
|
|
3
3
|
import { getConfig } from "../../src/config/index.js";
|
|
4
4
|
import { ApacuanaAPIError } from "../../src/errors/index.js";
|
|
5
5
|
import getCustomer from "../../src/api/users.js";
|
|
6
|
+
import ApacuanaSuccess from "../../src/success/index.js";
|
|
6
7
|
|
|
7
8
|
// Mockear las dependencias:
|
|
8
9
|
jest.mock("../../src/utils/httpClient.js", () => ({
|
|
@@ -56,8 +57,8 @@ describe("getCustomer", () => {
|
|
|
56
57
|
"POST"
|
|
57
58
|
);
|
|
58
59
|
|
|
59
|
-
expect(result).
|
|
60
|
-
|
|
60
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
61
|
+
expect(result.data).toEqual({
|
|
61
62
|
token: "mock-session-id-12345",
|
|
62
63
|
userData: {
|
|
63
64
|
userId: "mock-user",
|