All files / config index.js

27.27% Statements 3/11
0% Branches 0/9
0% Functions 0/2
30% Lines 3/10

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42      1x                     1x                                                   1x  
// src/config/index.js
import { INTEGRATION_TYPE } from '../utils/constant';
 
let config = {
  apiUrl: "",
  secretKey: "",
  apiKey: "",
  verificationId: "",
  customerId: "",
  integrationType: "",
  userData: undefined,
  token: undefined,
};
 
export const setConfig = (newConfig) => {
  const { apiUrl, secretKey, apiKey, verificationId, integrationType } = newConfig;
 
  if (!apiUrl || !secretKey || !apiKey || !verificationId || !integrationType) {
    throw new Error(
      "Apacuana SDK: La configuración inicial debe incluir apiUrl, " +
        "secretKey, apiKey, verificationId e integrationType."
    );
  }
 
  // Nueva validación para el valor de integrationType
  if (!Object.values(INTEGRATION_TYPE).includes(integrationType)) {
    throw new Error(
      `Apacuana SDK: El valor de integrationType ('${integrationType}') no es válido. ` +
      `Valores permitidos: ${Object.values(INTEGRATION_TYPE).join(', ')}`
    );
  }
 
  config = { ...config, ...newConfig };
  // eslint-disable-next-line no-console
  console.log("[Config] SDK Configuración actualizada (desde config):", {
    ...config,
    secretKey: "********",
  });
};
 
export const getConfig = () => ({ ...config });