apacuana-sdk-core 0.8.0 → 0.9.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 +85 -0
- package/coverage/clover.xml +196 -128
- package/coverage/coverage-final.json +7 -7
- package/coverage/lcov-report/index.html +29 -29
- package/coverage/lcov-report/src/api/certs.js.html +1 -1
- package/coverage/lcov-report/src/api/index.html +32 -32
- package/coverage/lcov-report/src/api/revocations.js.html +79 -43
- package/coverage/lcov-report/src/api/signatures.js.html +595 -73
- package/coverage/lcov-report/src/api/users.js.html +1 -1
- package/coverage/lcov-report/src/config/index.html +1 -1
- package/coverage/lcov-report/src/config/index.js.html +6 -6
- 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 +36 -3
- 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 +65 -35
- package/coverage/lcov-report/src/utils/index.html +15 -15
- package/coverage/lcov.info +352 -220
- package/dist/api/signatures.d.ts +5 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +374 -79
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +374 -79
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/revocations.js +14 -2
- package/src/api/signatures.js +174 -0
- package/src/index.js +12 -1
- package/src/utils/httpClient.js +29 -19
- package/tests/api/revocations.test.js +118 -5
- package/tests/api/signatures.test.js +306 -0
package/package.json
CHANGED
package/src/api/revocations.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { httpRequest } from "../utils/httpClient";
|
|
2
2
|
import { ApacuanaAPIError } from "../errors/index";
|
|
3
|
+
import { getConfig } from "../config";
|
|
4
|
+
import { INTEGRATION_TYPE } from "../utils/constant";
|
|
3
5
|
|
|
4
6
|
/**
|
|
5
7
|
* @typedef {object} RequestRevocationResponse
|
|
@@ -60,11 +62,21 @@ export const requestRevocation = async (reasonCode) => {
|
|
|
60
62
|
* @throws {ApacuanaAPIError} If fetching the reasons fails.
|
|
61
63
|
*/
|
|
62
64
|
export const getRevocationReasons = async () => {
|
|
65
|
+
const { integrationType } = getConfig();
|
|
66
|
+
|
|
67
|
+
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
68
|
+
throw new ApacuanaAPIError(
|
|
69
|
+
`Get revocation reasons is not supported for integration type: ${integrationType}`,
|
|
70
|
+
501,
|
|
71
|
+
"NOT_IMPLEMENTED"
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
63
75
|
try {
|
|
64
76
|
const response = await httpRequest(
|
|
77
|
+
"GET",
|
|
65
78
|
"config/api/revocation/reasonsonboarding",
|
|
66
|
-
{}
|
|
67
|
-
"GET"
|
|
79
|
+
{}
|
|
68
80
|
);
|
|
69
81
|
|
|
70
82
|
if (!response.records) {
|
package/src/api/signatures.js
CHANGED
|
@@ -218,6 +218,85 @@ const getDocsOnBoarding = async (data) => {
|
|
|
218
218
|
}
|
|
219
219
|
};
|
|
220
220
|
|
|
221
|
+
const uploadSignatureVariantOnBoarding = async ({ file }) => {
|
|
222
|
+
try {
|
|
223
|
+
const response = await httpRequest(
|
|
224
|
+
"services/api/customer/signaturephoto",
|
|
225
|
+
{ file },
|
|
226
|
+
"POST"
|
|
227
|
+
);
|
|
228
|
+
return { ...response, success: true };
|
|
229
|
+
} catch (error) {
|
|
230
|
+
if (error instanceof ApacuanaAPIError) {
|
|
231
|
+
throw error;
|
|
232
|
+
}
|
|
233
|
+
throw new ApacuanaAPIError(
|
|
234
|
+
`Failed to upload signature variant: ${error.message || "Unknown error"}`
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const uploadSignatureVariantOnPremise = async () => {
|
|
240
|
+
throw new ApacuanaAPIError(
|
|
241
|
+
"Uploading signature variants is not supported for integration type: ONPREMISE",
|
|
242
|
+
501,
|
|
243
|
+
"NOT_IMPLEMENTED"
|
|
244
|
+
);
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
const getSignatureVariantOnBoarding = async () => {
|
|
248
|
+
const { customerId } = getConfig();
|
|
249
|
+
try {
|
|
250
|
+
const response = await httpRequest(
|
|
251
|
+
`services/api/customer/getsignaturephotosdk/${customerId}`,
|
|
252
|
+
{},
|
|
253
|
+
"GET"
|
|
254
|
+
);
|
|
255
|
+
return { ...response, success: true };
|
|
256
|
+
} catch (error) {
|
|
257
|
+
if (error instanceof ApacuanaAPIError) {
|
|
258
|
+
throw error;
|
|
259
|
+
}
|
|
260
|
+
throw new ApacuanaAPIError(
|
|
261
|
+
`Failed to get signature variant: ${error.message || "Unknown error"}`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
const getSignatureVariantOnPremise = async () => {
|
|
267
|
+
throw new ApacuanaAPIError(
|
|
268
|
+
"Getting signature variants is not supported for integration type: ONPREMISE",
|
|
269
|
+
501,
|
|
270
|
+
"NOT_IMPLEMENTED"
|
|
271
|
+
);
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const deleteSignatureVariantOnBoarding = async () => {
|
|
275
|
+
try {
|
|
276
|
+
const response = await httpRequest(
|
|
277
|
+
"services/api/customer/cleansignaturephoto",
|
|
278
|
+
{},
|
|
279
|
+
"DELETE"
|
|
280
|
+
);
|
|
281
|
+
return { ...response, success: true };
|
|
282
|
+
} catch (error) {
|
|
283
|
+
if (error instanceof ApacuanaAPIError) {
|
|
284
|
+
throw error;
|
|
285
|
+
}
|
|
286
|
+
throw new ApacuanaAPIError(
|
|
287
|
+
`Failed to delete signature variant: ${error.message || "Unknown error"}`
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
const deleteSignatureVariantOnPremise = async () => {
|
|
293
|
+
throw new ApacuanaAPIError(
|
|
294
|
+
"Deleting signature variants is not supported for integration type: ONPREMISE",
|
|
295
|
+
501,
|
|
296
|
+
"NOT_IMPLEMENTED"
|
|
297
|
+
);
|
|
298
|
+
};
|
|
299
|
+
|
|
221
300
|
// =================================================================
|
|
222
301
|
// Exported Functions
|
|
223
302
|
// =================================================================
|
|
@@ -358,3 +437,98 @@ export const getDocs = async (data) => {
|
|
|
358
437
|
"NOT_IMPLEMENTED"
|
|
359
438
|
);
|
|
360
439
|
};
|
|
440
|
+
|
|
441
|
+
/**
|
|
442
|
+
* Sube una variante de firma para un firmante.
|
|
443
|
+
* @param {object} data - Datos para la subida.
|
|
444
|
+
* @param {File} data.file - El archivo de la variante de firma (debe ser PNG).
|
|
445
|
+
* @returns {Promise<object>} Una promesa que resuelve a un objeto con el resultado de la operación.
|
|
446
|
+
* @throws {ApacuanaAPIError} Si los datos son inválidos o la llamada a la API falla.
|
|
447
|
+
*/
|
|
448
|
+
export const uploadSignatureVariant = async (data) => {
|
|
449
|
+
if (!data || !data.file) {
|
|
450
|
+
throw new ApacuanaAPIError(
|
|
451
|
+
"El parámetro 'file' es requerido.",
|
|
452
|
+
400,
|
|
453
|
+
"INVALID_PARAMETER"
|
|
454
|
+
);
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
if (typeof File === "undefined" || !(data.file instanceof File)) {
|
|
458
|
+
throw new ApacuanaAPIError(
|
|
459
|
+
"El parámetro 'file' debe ser una instancia de 'File'.",
|
|
460
|
+
400,
|
|
461
|
+
"INVALID_PARAMETER"
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
if (data.file.type !== "image/png") {
|
|
466
|
+
throw new ApacuanaAPIError(
|
|
467
|
+
"El archivo debe ser de tipo PNG (image/png).",
|
|
468
|
+
400,
|
|
469
|
+
"INVALID_PARAMETER"
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
const { integrationType } = getConfig();
|
|
474
|
+
|
|
475
|
+
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
476
|
+
return uploadSignatureVariantOnBoarding(data);
|
|
477
|
+
}
|
|
478
|
+
|
|
479
|
+
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
480
|
+
return uploadSignatureVariantOnPremise();
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
throw new ApacuanaAPIError(
|
|
484
|
+
`Unsupported integration type: ${integrationType}`,
|
|
485
|
+
400,
|
|
486
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
487
|
+
);
|
|
488
|
+
};
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Obtiene la variante de firma del firmante.
|
|
492
|
+
* @returns {Promise<object>} Una promesa que resuelve a un objeto con los datos de la variante de firma.
|
|
493
|
+
* @throws {ApacuanaAPIError} Si la llamada a la API falla o el tipo de integración no es soportado.
|
|
494
|
+
*/
|
|
495
|
+
export const getSignatureVariant = async () => {
|
|
496
|
+
const { integrationType } = getConfig();
|
|
497
|
+
|
|
498
|
+
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
499
|
+
return getSignatureVariantOnBoarding();
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
503
|
+
return getSignatureVariantOnPremise();
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
throw new ApacuanaAPIError(
|
|
507
|
+
`Unsupported integration type: ${integrationType}`,
|
|
508
|
+
400,
|
|
509
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
510
|
+
);
|
|
511
|
+
};
|
|
512
|
+
|
|
513
|
+
/**
|
|
514
|
+
* Elimina la variante de firma del firmante.
|
|
515
|
+
* @returns {Promise<object>} Una promesa que resuelve a un objeto con el resultado de la operación.
|
|
516
|
+
* @throws {ApacuanaAPIError} Si la llamada a la API falla o el tipo de integración no es soportado.
|
|
517
|
+
*/
|
|
518
|
+
export const deleteSignatureVariant = async () => {
|
|
519
|
+
const { integrationType } = getConfig();
|
|
520
|
+
|
|
521
|
+
if (integrationType === INTEGRATION_TYPE.ONBOARDING) {
|
|
522
|
+
return deleteSignatureVariantOnBoarding();
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
if (integrationType === INTEGRATION_TYPE.ONPREMISE) {
|
|
526
|
+
return deleteSignatureVariantOnPremise();
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
throw new ApacuanaAPIError(
|
|
530
|
+
`Unsupported integration type: ${integrationType}`,
|
|
531
|
+
400,
|
|
532
|
+
"UNSUPPORTED_INTEGRATION_TYPE"
|
|
533
|
+
);
|
|
534
|
+
};
|
package/src/index.js
CHANGED
|
@@ -3,7 +3,15 @@ import { initHttpClient, setAuthToken } from "./utils/httpClient";
|
|
|
3
3
|
import getCustomer from "./api/users";
|
|
4
4
|
import { requestRevocation, getRevocationReasons } from "./api/revocations";
|
|
5
5
|
import { generateCert, getCertStatus } from "./api/certs";
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
addSigner,
|
|
8
|
+
deleteSignatureVariant,
|
|
9
|
+
getDigest,
|
|
10
|
+
getDocs,
|
|
11
|
+
getSignatureVariant,
|
|
12
|
+
signDocument,
|
|
13
|
+
uploadSignatureVariant,
|
|
14
|
+
} from "./api/signatures";
|
|
7
15
|
|
|
8
16
|
const apacuana = {
|
|
9
17
|
/**
|
|
@@ -50,6 +58,9 @@ const apacuana = {
|
|
|
50
58
|
signDocument,
|
|
51
59
|
getDigest,
|
|
52
60
|
getRevocationReasons,
|
|
61
|
+
uploadSignatureVariant,
|
|
62
|
+
getSignatureVariant,
|
|
63
|
+
deleteSignatureVariant,
|
|
53
64
|
};
|
|
54
65
|
|
|
55
66
|
export default apacuana;
|
package/src/utils/httpClient.js
CHANGED
|
@@ -27,7 +27,6 @@ export const initHttpClient = () => {
|
|
|
27
27
|
axiosInstance = axios.create({
|
|
28
28
|
baseURL: config.apiUrl,
|
|
29
29
|
headers: {
|
|
30
|
-
"Content-Type": "application/json",
|
|
31
30
|
"APACUANA-API-Key": config.apiKey,
|
|
32
31
|
"APACUANA-SECRET-Key": config.secretKey,
|
|
33
32
|
// La cabecera Authorization se deja vacía al inicio.
|
|
@@ -41,9 +40,12 @@ export const initHttpClient = () => {
|
|
|
41
40
|
(response) => {
|
|
42
41
|
// Maneja errores lógicos de la API (si el backend devuelve status 2xx con { success: false })
|
|
43
42
|
if (response.data && response.data.success === false) {
|
|
43
|
+
const errorMessage =
|
|
44
|
+
response.data?.msg ||
|
|
45
|
+
response.data?.message ||
|
|
46
|
+
"Error lógico desconocido desde la API.";
|
|
44
47
|
throw new ApacuanaAPIError(
|
|
45
|
-
|
|
46
|
-
"Error lógico en la respuesta de la API (status 2xx)",
|
|
48
|
+
errorMessage,
|
|
47
49
|
response.status,
|
|
48
50
|
response.data.code || "LOGICAL_API_ERROR"
|
|
49
51
|
);
|
|
@@ -60,10 +62,12 @@ export const initHttpClient = () => {
|
|
|
60
62
|
|
|
61
63
|
if (error.response) {
|
|
62
64
|
const { status, data } = error.response;
|
|
65
|
+
const errorMessage =
|
|
66
|
+
data?.msg || data?.message || "Error desconocido desde la API.";
|
|
63
67
|
throw new ApacuanaAPIError(
|
|
64
|
-
|
|
68
|
+
errorMessage,
|
|
65
69
|
status,
|
|
66
|
-
data
|
|
70
|
+
data?.code || "API_ERROR"
|
|
67
71
|
);
|
|
68
72
|
}
|
|
69
73
|
if (error.request) {
|
|
@@ -122,12 +126,21 @@ export const httpRequest = async (path, data = {}, method = "POST") => {
|
|
|
122
126
|
);
|
|
123
127
|
}
|
|
124
128
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
const dataToSend = {
|
|
128
|
-
...data,
|
|
129
|
-
};
|
|
129
|
+
let dataToSend;
|
|
130
|
+
const requestConfig = {};
|
|
130
131
|
|
|
132
|
+
const hasFile = Object.values(data).some(
|
|
133
|
+
(value) => typeof File !== "undefined" && value instanceof File
|
|
134
|
+
);
|
|
135
|
+
if (hasFile) {
|
|
136
|
+
const formData = new FormData();
|
|
137
|
+
Object.keys(data).forEach((key) => {
|
|
138
|
+
formData.append(key, data[key]);
|
|
139
|
+
});
|
|
140
|
+
dataToSend = formData;
|
|
141
|
+
} else {
|
|
142
|
+
dataToSend = { ...data };
|
|
143
|
+
}
|
|
131
144
|
try {
|
|
132
145
|
let response;
|
|
133
146
|
switch (method.toUpperCase()) {
|
|
@@ -135,13 +148,16 @@ export const httpRequest = async (path, data = {}, method = "POST") => {
|
|
|
135
148
|
response = await axiosInstance.get(path, { params: dataToSend });
|
|
136
149
|
break;
|
|
137
150
|
case "POST":
|
|
138
|
-
response = await axiosInstance.post(path, dataToSend);
|
|
151
|
+
response = await axiosInstance.post(path, dataToSend, requestConfig);
|
|
139
152
|
break;
|
|
140
153
|
case "PUT":
|
|
141
|
-
response = await axiosInstance.put(path, dataToSend);
|
|
154
|
+
response = await axiosInstance.put(path, dataToSend, requestConfig);
|
|
142
155
|
break;
|
|
143
156
|
case "DELETE":
|
|
144
|
-
response = await axiosInstance.delete(path, {
|
|
157
|
+
response = await axiosInstance.delete(path, {
|
|
158
|
+
data: dataToSend,
|
|
159
|
+
...requestConfig,
|
|
160
|
+
});
|
|
145
161
|
break;
|
|
146
162
|
default:
|
|
147
163
|
throw new ApacuanaAPIError(
|
|
@@ -151,14 +167,8 @@ export const httpRequest = async (path, data = {}, method = "POST") => {
|
|
|
151
167
|
);
|
|
152
168
|
}
|
|
153
169
|
|
|
154
|
-
// Si la promesa se resolvió, la respuesta es exitosa.
|
|
155
|
-
// El interceptor ya manejó los errores 4xx/5xx y los errores lógicos 2xx.
|
|
156
|
-
// eslint-disable-next-line no-console
|
|
157
170
|
return response.data;
|
|
158
171
|
} catch (error) {
|
|
159
|
-
// Si la petición falla, el interceptor ya procesó el error.
|
|
160
|
-
// Simplemente relanzamos el error para que sea capturado por la función de API.
|
|
161
|
-
// eslint-disable-next-line no-console
|
|
162
172
|
console.error(`[HTTP Client] Fallo en la petición a ${path}:`, error);
|
|
163
173
|
throw error;
|
|
164
174
|
}
|
|
@@ -1,6 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { httpRequest } from "../../src/utils/httpClient";
|
|
2
|
+
import { ApacuanaAPIError } from "../../src/errors";
|
|
3
|
+
import {
|
|
4
|
+
requestRevocation,
|
|
5
|
+
getRevocationReasons,
|
|
6
|
+
} from "../../src/api/revocations";
|
|
7
|
+
import { getConfig } from "../../src/config";
|
|
8
|
+
import { INTEGRATION_TYPE } from "../../src/utils/constant";
|
|
9
|
+
|
|
10
|
+
jest.mock("../../src/utils/httpClient");
|
|
11
|
+
jest.mock("../../src/config");
|
|
12
|
+
|
|
13
|
+
describe("Revocations API", () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
jest.clearAllMocks();
|
|
5
16
|
});
|
|
6
|
-
|
|
17
|
+
|
|
18
|
+
describe("requestRevocation", () => {
|
|
19
|
+
it("should throw an error if reasonCode is not provided", async () => {
|
|
20
|
+
await expect(requestRevocation(null)).rejects.toThrow(
|
|
21
|
+
"Código de motivo es requerido para requestRevocation."
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should make a POST request to the correct endpoint with the reasonCode", async () => {
|
|
26
|
+
const reasonCode = "COMPROMISED";
|
|
27
|
+
const mockResponse = { success: true, message: "Revocation requested" };
|
|
28
|
+
httpRequest.mockResolvedValue(mockResponse);
|
|
29
|
+
|
|
30
|
+
const result = await requestRevocation(reasonCode);
|
|
31
|
+
|
|
32
|
+
expect(httpRequest).toHaveBeenCalledWith(
|
|
33
|
+
"services/api/onboardingclient/requestcert",
|
|
34
|
+
{ reason: reasonCode },
|
|
35
|
+
"POST"
|
|
36
|
+
);
|
|
37
|
+
expect(result).toEqual(mockResponse);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("should throw a generic error if the httpRequest fails", async () => {
|
|
41
|
+
const reasonCode = "COMPROMISED";
|
|
42
|
+
const apiError = new Error("Network error");
|
|
43
|
+
httpRequest.mockRejectedValue(apiError);
|
|
44
|
+
|
|
45
|
+
await expect(requestRevocation(reasonCode)).rejects.toThrow(
|
|
46
|
+
`Fallo en la solicitud de revocación: ${apiError.message}`
|
|
47
|
+
);
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
describe("getRevocationReasons", () => {
|
|
52
|
+
it("should make a GET request and return the reasons for ONBOARDING", async () => {
|
|
53
|
+
getConfig.mockReturnValue({
|
|
54
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
55
|
+
});
|
|
56
|
+
const mockReasons = [
|
|
57
|
+
{ code: "0", description: "Unspecified" },
|
|
58
|
+
{ code: "1", description: "Key Compromise" },
|
|
59
|
+
];
|
|
60
|
+
httpRequest.mockResolvedValue({ records: mockReasons });
|
|
61
|
+
|
|
62
|
+
const result = await getRevocationReasons();
|
|
63
|
+
|
|
64
|
+
expect(httpRequest).toHaveBeenCalledWith(
|
|
65
|
+
"GET",
|
|
66
|
+
"config/api/revocation/reasonsonboarding",
|
|
67
|
+
{}
|
|
68
|
+
);
|
|
69
|
+
expect(result).toEqual(mockReasons);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should throw an error if the API response does not contain 'records'", async () => {
|
|
73
|
+
getConfig.mockReturnValue({
|
|
74
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
75
|
+
});
|
|
76
|
+
httpRequest.mockResolvedValue({ data: [] }); // Respuesta inválida
|
|
77
|
+
|
|
78
|
+
await expect(getRevocationReasons()).rejects.toThrow(
|
|
79
|
+
new ApacuanaAPIError("Failed to fetch revocation reasons.")
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should re-throw ApacuanaAPIError if caught", async () => {
|
|
84
|
+
getConfig.mockReturnValue({
|
|
85
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
86
|
+
});
|
|
87
|
+
const apiError = new ApacuanaAPIError("API is down", 500);
|
|
88
|
+
httpRequest.mockRejectedValue(apiError);
|
|
89
|
+
|
|
90
|
+
await expect(getRevocationReasons()).rejects.toThrow(apiError);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it("should throw a generic error for other types of errors", async () => {
|
|
94
|
+
getConfig.mockReturnValue({
|
|
95
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
96
|
+
});
|
|
97
|
+
const genericError = new Error("Something went wrong");
|
|
98
|
+
httpRequest.mockRejectedValue(genericError);
|
|
99
|
+
|
|
100
|
+
await expect(getRevocationReasons()).rejects.toThrow(
|
|
101
|
+
"Failed to get revocation reasons. Please try again later."
|
|
102
|
+
);
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it("should throw not implemented for ONPREMISE integration", async () => {
|
|
106
|
+
getConfig.mockReturnValue({
|
|
107
|
+
integrationType: INTEGRATION_TYPE.ONPREMISE,
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
await expect(getRevocationReasons()).rejects.toThrow(
|
|
111
|
+
new ApacuanaAPIError(
|
|
112
|
+
"Get revocation reasons is not supported for integration type: ONPREMISE",
|
|
113
|
+
501,
|
|
114
|
+
"NOT_IMPLEMENTED"
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|