apacuana-sdk-core 1.0.0 → 1.1.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/.eslintrc.cjs +22 -0
- package/CHANGELOG.md +1 -0
- package/README.md +794 -0
- package/babel.config.cjs +11 -0
- package/coverage/clover.xml +627 -0
- package/coverage/coverage-final.json +13 -0
- package/coverage/lcov-report/api/index.html +131 -0
- package/coverage/lcov-report/api/signatures.js.html +1093 -0
- package/coverage/lcov-report/api/users.js.html +292 -0
- package/coverage/lcov-report/base.css +224 -0
- package/coverage/lcov-report/block-navigation.js +87 -0
- package/coverage/lcov-report/certs.js.html +175 -0
- package/coverage/lcov-report/config/index.html +116 -0
- package/coverage/lcov-report/config/index.js.html +208 -0
- package/coverage/lcov-report/errors/index.html +116 -0
- package/coverage/lcov-report/errors/index.js.html +148 -0
- package/coverage/lcov-report/favicon.png +0 -0
- package/coverage/lcov-report/index.html +191 -0
- package/coverage/lcov-report/prettify.css +1 -0
- package/coverage/lcov-report/prettify.js +2 -0
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +210 -0
- package/coverage/lcov-report/src/api/certs.js.html +853 -0
- package/coverage/lcov-report/src/api/faceLiveness.js.html +523 -0
- package/coverage/lcov-report/src/api/index.html +176 -0
- package/coverage/lcov-report/src/api/revocations.js.html +412 -0
- package/coverage/lcov-report/src/api/signatures.js.html +1420 -0
- package/coverage/lcov-report/src/api/users.js.html +466 -0
- package/coverage/lcov-report/src/config/index.html +116 -0
- package/coverage/lcov-report/src/config/index.js.html +256 -0
- package/coverage/lcov-report/src/errors/index.html +116 -0
- package/coverage/lcov-report/src/errors/index.js.html +148 -0
- package/coverage/lcov-report/src/index.html +116 -0
- package/coverage/lcov-report/src/index.js.html +592 -0
- 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 +256 -0
- package/coverage/lcov-report/src/utils/helpers.js.html +1195 -0
- package/coverage/lcov-report/src/utils/httpClient.js.html +622 -0
- package/coverage/lcov-report/src/utils/index.html +146 -0
- package/coverage/lcov-report/utils/constant.js.html +145 -0
- package/coverage/lcov-report/utils/httpClient.js.html +646 -0
- package/coverage/lcov-report/utils/index.html +131 -0
- package/coverage/lcov.info +1258 -0
- package/dist/api/certs.d.ts +15 -0
- package/dist/api/faceLiveness.d.ts +6 -0
- package/dist/api/revocations.d.ts +6 -0
- package/dist/api/signatures.d.ts +19 -0
- package/dist/api/users.d.ts +47 -0
- package/dist/config/index.d.ts +22 -0
- package/dist/errors/index.d.ts +10 -0
- package/dist/index.d.ts +25 -0
- package/dist/index.js +34492 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +34490 -0
- package/dist/index.mjs.map +1 -0
- package/dist/success/index.d.ts +7 -0
- package/dist/types/certs.d.ts +83 -0
- package/dist/types/faceLiveness.d.ts +11 -0
- package/dist/types/revocations.d.ts +51 -0
- package/dist/types/signatures.d.ts +162 -0
- package/dist/types/users.d.ts +260 -0
- package/dist/utils/constant.d.ts +49 -0
- package/dist/utils/helpers.d.ts +25 -0
- package/dist/utils/httpClient.d.ts +3 -0
- package/jest.config.cjs +12 -0
- package/package.json +51 -9
- package/rollup.config.js +32 -0
- package/src/api/certs.js +256 -0
- package/src/api/faceLiveness.js +146 -0
- package/src/api/revocations.js +109 -0
- package/src/api/signatures.js +445 -0
- package/src/api/users.js +127 -0
- package/src/config/index.js +57 -0
- package/src/errors/index.js +21 -0
- package/src/index.js +169 -0
- package/src/success/index.js +8 -0
- package/src/types/certs.js +67 -0
- package/src/types/faceLiveness.js +16 -0
- package/src/types/revocations.js +45 -0
- package/src/types/signatures.js +96 -0
- package/src/types/users.js +73 -0
- package/src/utils/constant.js +57 -0
- package/src/utils/helpers.js +370 -0
- package/src/utils/httpClient.js +179 -0
- package/tests/api/certs.test.js +311 -0
- package/tests/api/faceLiveness.test.js +170 -0
- package/tests/api/revocations.test.js +119 -0
- package/tests/api/signatures.test.js +530 -0
- package/tests/api/users.test.js +117 -0
- package/tests/index.test.js +131 -0
- package/tsconfig.json +16 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
// tests/index.test.js
|
|
2
|
+
import apacuana from "../src/index.js";
|
|
3
|
+
import { setConfig, getConfig } from "../src/config/index.js";
|
|
4
|
+
import { initHttpClient, setAuthToken } from "../src/utils/httpClient.js";
|
|
5
|
+
import ApacuanaSuccess from "../src/success/index.js";
|
|
6
|
+
import { getCustomer } from "../src/api/users.js";
|
|
7
|
+
|
|
8
|
+
// Mockear todas las dependencias del index.js
|
|
9
|
+
jest.mock("../src/config/index.js", () => ({
|
|
10
|
+
setConfig: jest.fn(),
|
|
11
|
+
getConfig: jest.fn(),
|
|
12
|
+
}));
|
|
13
|
+
jest.mock("../src/utils/httpClient.js", () => ({
|
|
14
|
+
initHttpClient: jest.fn(),
|
|
15
|
+
setAuthToken: jest.fn(), // Agregar el mock de setAuthToken
|
|
16
|
+
}));
|
|
17
|
+
jest.mock("../src/api/users.js", () => ({
|
|
18
|
+
__esModule: true,
|
|
19
|
+
default: jest.fn(),
|
|
20
|
+
getCustomer: jest.fn(),
|
|
21
|
+
}));
|
|
22
|
+
|
|
23
|
+
describe("Apacuana SDK Initialization (init)", () => {
|
|
24
|
+
const mockConfig = {
|
|
25
|
+
apiUrl: "http://test-api.com",
|
|
26
|
+
secretKey: "mock-secret",
|
|
27
|
+
apiKey: "mock-api-key",
|
|
28
|
+
verificationId: "mock-verify-id",
|
|
29
|
+
customerId: "mock-customer-id",
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
beforeEach(() => {
|
|
33
|
+
// Limpiar todos los mocks antes de cada prueba.
|
|
34
|
+
jest.clearAllMocks();
|
|
35
|
+
|
|
36
|
+
// Configurar el mock de getConfig para devolver una configuración válida por defecto.
|
|
37
|
+
getConfig.mockReturnValue(mockConfig);
|
|
38
|
+
|
|
39
|
+
// Mockear la respuesta exitosa de getCustomer para la mayoría de las pruebas.
|
|
40
|
+
getCustomer.mockResolvedValue({
|
|
41
|
+
success: true,
|
|
42
|
+
data: {
|
|
43
|
+
token: "mock-session-token",
|
|
44
|
+
userData: { id: "mock-user-id" },
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
// Opcional: Mockear console.log para no ensuciar la consola durante las pruebas.
|
|
49
|
+
jest.spyOn(console, "log").mockImplementation(() => {});
|
|
50
|
+
jest.spyOn(console, "error").mockImplementation(() => {});
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
afterEach(() => {
|
|
54
|
+
// Restaurar los mocks de console después de cada prueba.
|
|
55
|
+
console.log.mockRestore();
|
|
56
|
+
console.error.mockRestore();
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test("debe llamar a setConfig, initHttpClient y getCustomer en orden y devolver true al finalizar", async () => {
|
|
60
|
+
const result = await apacuana.init(mockConfig);
|
|
61
|
+
|
|
62
|
+
// 1. Verificar que setConfig fue llamado con los parámetros correctos.
|
|
63
|
+
expect(setConfig).toHaveBeenCalledWith(mockConfig);
|
|
64
|
+
|
|
65
|
+
// 2. Verificar que initHttpClient fue llamado sin argumentos.
|
|
66
|
+
expect(initHttpClient).toHaveBeenCalled();
|
|
67
|
+
|
|
68
|
+
// 3. Verificar que getCustomer fue llamado.
|
|
69
|
+
expect(getCustomer).toHaveBeenCalledWith();
|
|
70
|
+
|
|
71
|
+
// 4. Verificar que se retorna una instancia de ApacuanaSuccess al finalizar la inicialización.
|
|
72
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
73
|
+
expect(result.data).toEqual({
|
|
74
|
+
initialized: true,
|
|
75
|
+
message: "SDK inicializado con sesión de usuario.",
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// 5. Verificar que las funciones se llamaron el número correcto de veces.
|
|
79
|
+
expect(setConfig).toHaveBeenCalledTimes(2); // Una vez inicial, una vez para guardar token
|
|
80
|
+
expect(initHttpClient).toHaveBeenCalledTimes(1);
|
|
81
|
+
expect(getCustomer).toHaveBeenCalledTimes(1);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("debe lanzar un error si la configuración inicial está incompleta", async () => {
|
|
85
|
+
// Sobrescribir el mock de setConfig para que lance un error.
|
|
86
|
+
setConfig.mockImplementationOnce(() => {
|
|
87
|
+
throw new Error("Apacuana SDK: La configuración inicial debe incluir...");
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
// Verificar que el método init lanza el error esperado.
|
|
91
|
+
await expect(apacuana.init({})).rejects.toThrow(
|
|
92
|
+
"Apacuana SDK: La configuración inicial debe incluir..."
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Verificar que initHttpClient y getCustomer no fueron llamados.
|
|
96
|
+
expect(initHttpClient).not.toHaveBeenCalled();
|
|
97
|
+
expect(getCustomer).not.toHaveBeenCalled();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
test("debe lanzar un error si getCustomer falla", async () => {
|
|
101
|
+
// Configurar el mock de getCustomer para que rechace la promesa.
|
|
102
|
+
getCustomer.mockRejectedValueOnce(
|
|
103
|
+
new Error("Error del servidor al obtener token")
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
// Verificar que el método init propaga el error de getCustomer.
|
|
107
|
+
await expect(apacuana.init(mockConfig)).rejects.toThrow(
|
|
108
|
+
"Error del servidor al obtener token"
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
// Verificar que setConfig e initHttpClient sí fueron llamados, pero getCustomer falló.
|
|
112
|
+
expect(setConfig).toHaveBeenCalledWith(mockConfig);
|
|
113
|
+
expect(initHttpClient).toHaveBeenCalled();
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
test("debe llamar a getConfig y setConfig para guardar el token", async () => {
|
|
117
|
+
const result = await apacuana.init(mockConfig);
|
|
118
|
+
|
|
119
|
+
// La primera llamada a setConfig se hace con la configuración inicial.
|
|
120
|
+
// La segunda llamada se hace para guardar el token y userData.
|
|
121
|
+
expect(setConfig).toHaveBeenCalledTimes(2);
|
|
122
|
+
expect(setConfig).toHaveBeenLastCalledWith({
|
|
123
|
+
...mockConfig,
|
|
124
|
+
token: "mock-session-token",
|
|
125
|
+
userData: { id: "mock-user-id" },
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// Verificar que la respuesta es una instancia de ApacuanaSuccess.
|
|
129
|
+
expect(result).toBeInstanceOf(ApacuanaSuccess);
|
|
130
|
+
});
|
|
131
|
+
});
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2020",
|
|
4
|
+
"module": "esnext",
|
|
5
|
+
"lib": ["es2022", "dom"],
|
|
6
|
+
"allowJs": true,
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"emitDeclarationOnly": true,
|
|
9
|
+
"outDir": "./dist",
|
|
10
|
+
"strict": true,
|
|
11
|
+
"moduleResolution": "node",
|
|
12
|
+
"esModuleInterop": true
|
|
13
|
+
},
|
|
14
|
+
"include": ["src"],
|
|
15
|
+
"exclude": ["nodev_modules", "dist", "tests"]
|
|
16
|
+
}
|