apacuana-sdk-core 1.3.0 → 1.6.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/coverage/clover.xml +79 -78
- package/coverage/coverage-final.json +2 -2
- package/coverage/lcov-report/index.html +11 -11
- package/coverage/lcov-report/src/api/certs.js.html +16 -10
- package/coverage/lcov-report/src/api/faceLiveness.js.html +1 -1
- package/coverage/lcov-report/src/api/index.html +11 -11
- package/coverage/lcov-report/src/api/revocations.js.html +1 -1
- package/coverage/lcov-report/src/api/signatures.js.html +1 -1
- package/coverage/lcov-report/src/api/users.js.html +3 -3
- 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 +1 -1
- package/coverage/lcov-report/src/index.html +1 -1
- package/coverage/lcov-report/src/index.js.html +1 -1
- package/coverage/lcov-report/src/success/index.html +1 -1
- package/coverage/lcov-report/src/success/index.js.html +1 -1
- package/coverage/lcov-report/src/utils/constant.js.html +1 -1
- 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 +122 -121
- package/dist/index.js +224 -203
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +224 -203
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/api/certs.js +5 -3
- package/tests/api/certs.test.js +38 -14
package/package.json
CHANGED
package/src/api/certs.js
CHANGED
|
@@ -15,6 +15,7 @@ import helpers from "../utils/helpers";
|
|
|
15
15
|
import { ApacuanaAPIError } from "../errors";
|
|
16
16
|
import ApacuanaSuccess from "../success";
|
|
17
17
|
import { INTEGRATION_TYPE, PARSE_STATUS } from "../utils/constant";
|
|
18
|
+
import { getCustomer } from "./users";
|
|
18
19
|
|
|
19
20
|
/**
|
|
20
21
|
* @param {EncryptedCSRObject} encryptedCSR
|
|
@@ -82,14 +83,15 @@ export const generateCert = async (encryptedCSR) => {
|
|
|
82
83
|
* @param {boolean} [isCertificateInDevice=false] - Indicates if the certificate is already on the device.
|
|
83
84
|
* @returns {GetCertStatusResponse} Object with the certificate status and a success indicator.
|
|
84
85
|
*/
|
|
85
|
-
export const getCertStatus = (isCertificateInDevice = false) => {
|
|
86
|
+
export const getCertStatus = async (isCertificateInDevice = false) => {
|
|
86
87
|
const config = getConfig();
|
|
88
|
+
const customer = await getCustomer();
|
|
89
|
+
const { userData } = customer.data;
|
|
87
90
|
const status = helpers.getCertificateStatus(
|
|
88
|
-
|
|
91
|
+
userData,
|
|
89
92
|
isCertificateInDevice,
|
|
90
93
|
config.integrationType
|
|
91
94
|
);
|
|
92
|
-
console.log(status, "Core sdk");
|
|
93
95
|
const parseStatus = PARSE_STATUS[status];
|
|
94
96
|
|
|
95
97
|
return new ApacuanaSuccess({ status: parseStatus });
|
package/tests/api/certs.test.js
CHANGED
|
@@ -3,6 +3,7 @@ import { httpRequest } from "../../src/utils/httpClient";
|
|
|
3
3
|
import helpers from "../../src/utils/helpers";
|
|
4
4
|
import { ApacuanaAPIError } from "../../src/errors";
|
|
5
5
|
import ApacuanaSuccess from "../../src/success";
|
|
6
|
+
import { getCustomer } from "../../src/api/users"; // <-- NECESARIO para mockear y usar
|
|
6
7
|
import {
|
|
7
8
|
generateCert,
|
|
8
9
|
getCertStatus,
|
|
@@ -15,22 +16,28 @@ import { INTEGRATION_TYPE } from "../../src/utils/constant";
|
|
|
15
16
|
jest.mock("../../src/config/index");
|
|
16
17
|
jest.mock("../../src/utils/httpClient");
|
|
17
18
|
jest.mock("../../src/utils/helpers");
|
|
19
|
+
jest.mock("../../src/api/users"); // <-- Simulación del módulo para getCustomer
|
|
18
20
|
|
|
19
21
|
describe("Certificate API - certs.js", () => {
|
|
22
|
+
// CONFIGURACIÓN BASE REQUERIDA POR getCustomer
|
|
23
|
+
const baseConfig = {
|
|
24
|
+
verificationId: "mock-verify-id",
|
|
25
|
+
customerId: "mock-customer-id",
|
|
26
|
+
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
27
|
+
};
|
|
28
|
+
|
|
20
29
|
beforeEach(() => {
|
|
21
30
|
jest.clearAllMocks();
|
|
31
|
+
|
|
32
|
+
// **Mockeamos getConfig para devolver SIEMPRE las credenciales base**
|
|
33
|
+
getConfig.mockReturnValue(baseConfig);
|
|
22
34
|
});
|
|
23
35
|
|
|
24
36
|
describe("generateCert", () => {
|
|
25
|
-
beforeEach(() => {
|
|
26
|
-
jest.clearAllMocks();
|
|
27
|
-
});
|
|
28
|
-
|
|
29
37
|
// TEST 1: Probar el camino feliz de ONBOARDING
|
|
30
38
|
it("should call generateCertOnBoarding for ONBOARDING integration", async () => {
|
|
31
|
-
getConfig
|
|
32
|
-
|
|
33
|
-
});
|
|
39
|
+
// Configuramos el mock de getConfig con el integrationType necesario
|
|
40
|
+
getConfig.mockReturnValue(baseConfig);
|
|
34
41
|
const mockEncryptedCsr = { csr: "onboarding-csr" };
|
|
35
42
|
const mockApiResponse = {
|
|
36
43
|
cert: "onboarding-cert",
|
|
@@ -79,29 +86,45 @@ describe("Certificate API - certs.js", () => {
|
|
|
79
86
|
)
|
|
80
87
|
);
|
|
81
88
|
});
|
|
82
|
-
|
|
83
|
-
// Se eliminan los otros tests que asumían un comportamiento "estándar"
|
|
84
89
|
});
|
|
85
90
|
|
|
86
91
|
describe("getCertStatus", () => {
|
|
87
|
-
|
|
92
|
+
// Test debe ser async para esperar getCertStatus y getCustomer
|
|
93
|
+
it("should return the certificate status from helpers", async () => {
|
|
94
|
+
// Datos simulados que el helper necesita para trabajar
|
|
88
95
|
const mockUserData = { certStatus: "SOLICITUD" };
|
|
96
|
+
|
|
97
|
+
// 1. Simular la CONFIGURACIÓN: Incluye credenciales base + userData
|
|
89
98
|
getConfig.mockReturnValue({
|
|
99
|
+
...baseConfig,
|
|
90
100
|
userData: mockUserData,
|
|
91
|
-
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
92
101
|
});
|
|
102
|
+
|
|
103
|
+
// 2. Simular la respuesta de getCustomer (Asíncrono)
|
|
104
|
+
// Debe devolver los datos de usuario requeridos.
|
|
105
|
+
getCustomer.mockResolvedValue({
|
|
106
|
+
success: true,
|
|
107
|
+
data: {
|
|
108
|
+
userData: mockUserData,
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
// 3. Simular el resultado del Helper (getCertificateStatus)
|
|
93
113
|
helpers.getCertificateStatus.mockReturnValue("SOLICITUD");
|
|
94
114
|
|
|
95
|
-
|
|
115
|
+
// 4. Llamar y esperar el resultado (await)
|
|
116
|
+
const result = await getCertStatus(true);
|
|
117
|
+
|
|
118
|
+
// 5. Verificar las llamadas y el resultado
|
|
119
|
+
expect(getCustomer).toHaveBeenCalledTimes(1);
|
|
96
120
|
|
|
97
121
|
expect(helpers.getCertificateStatus).toHaveBeenCalledWith(
|
|
98
122
|
mockUserData,
|
|
99
123
|
true,
|
|
100
124
|
INTEGRATION_TYPE.ONBOARDING
|
|
101
125
|
);
|
|
102
|
-
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
103
126
|
|
|
104
|
-
|
|
127
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
105
128
|
expect(result.data).toEqual({
|
|
106
129
|
status: {
|
|
107
130
|
text: "Por verificar",
|
|
@@ -115,6 +138,7 @@ describe("Certificate API - certs.js", () => {
|
|
|
115
138
|
describe("getCertTypes", () => {
|
|
116
139
|
it("should call getCertTypesOnBoarding for ONBOARDING integration", async () => {
|
|
117
140
|
getConfig.mockReturnValue({
|
|
141
|
+
...baseConfig,
|
|
118
142
|
integrationType: INTEGRATION_TYPE.ONBOARDING,
|
|
119
143
|
});
|
|
120
144
|
const mockApiResponse = { types: [{ id: "1", name: "Type 1" }] };
|