Arreglo de config de tests para jwt

This commit is contained in:
2026-01-27 10:00:51 +01:00
parent 1d8af66564
commit 453cb05228
11 changed files with 150 additions and 44 deletions

View File

@@ -1,26 +1,3 @@
PORT=3000
RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
ENVIORMENT=development
RABBITMQ_HOST=rabbitmq-sim-broker
#RABBITMQ_HOST=localhost
RABBITMQ_PORT=5672
RABBITMQ_USER=guest
RABBITMQ_PASSWORD=guest
RABBITMQ_SECURE=false
RABBITMQ_VHOST=sim-vhost
# Hay cosas que unificar de varios servicios
POSTGRES_DB=postgres
POSTGRES_DATABASE=postres
POSTGRES_HOST=postgresql-sim-1
POSTGRES_PORT=5432
DEV_POSTGRES_PORT=5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=1234
# claves de Objenious
OBJ_PEM_PATH=./obj.pem
OBJ_AUTHORIZATION=XOc7FtwXD8hUX2SFVX94XSty8wkOmChkwDNF09O_aIxPubMDdFUdCDCB4zpzSIxi8nOcTg7r_LM_nmd5qm7uLbksf_XArjI8iAyhjKz_2BAXPhmvKs4Fc9f3vv5LDfCVrPB9lP8P7rJ66_qnWs4jvhLQxSfn29m96hgXeCf8oySdIDUjN2q9Js3KAS5LL52Ri6ryvUeO1PvMhaPQMWRqoHIqTV1wPfPtiqQwcjUPmu5GeW164Kq1JLgV3KaGzfCZ9Qv9lbv30EJrukXxWuLCAhBS0kzrBXZoWvf2pb9uh3Am_93_dDxiIGQfIap9ZU_m8ZD1HPgvZOMCY6ZkxQconQ

View File

@@ -0,0 +1,15 @@
import { test, describe } from "vitest"
import { JWTService } from "./JWT.service"
import { loadEnvFile } from "node:process"
describe("Tokens Objenious", () => {
const jwtService = new JWTService()
loadEnvFile("packages/sim-consumidor-activaciones/.env")
console.log("test env", process.env.OBJ_CLIENT_ID)
test("Solicicitud normal de auth", async () => {
//const token = await jwtService.getAccessToken()
})
})

View File

@@ -6,7 +6,6 @@ import {
JWTToken
} from "#shared/domain/JWT"
import axios from "axios";
import { throwDeprecation } from "node:process";
type GrantAccessRequestBody = {
grant_type: string,
@@ -15,7 +14,7 @@ type GrantAccessRequestBody = {
client_assertion: string
}
type GrantAccessRequestResponse = {
type TokensRequestResponse = {
"access_token": string,
"expires_in": number,
"refresh_token": string
@@ -79,8 +78,10 @@ export class JWTService {
let res;
try {
res = (await req).data as GrantAccessRequestResponse;
res = (await req).data as TokensRequestResponse;
this.authToken = new JWTToken(res.access_token)
this.refreshToken = new JWTToken(res.refresh_token)
return this.authToken
} catch (e) {
const errorString = "No se ha podido conseguir el token de acceso de OBJENIOUS"
console.error(errorString, e)
@@ -107,7 +108,10 @@ export class JWTService {
let res;
try {
res = (await req).data as GrantAccessRequestResponse;
res = (await req).data as TokensRequestResponse;
this.authToken = new JWTToken(res.access_token)
this.refreshToken = new JWTToken(res.refresh_token)
return this.authToken
} catch (e) {
const errorString = "No se ha podido conseguir el token de acceso de OBJENIOUS"
console.error(errorString, e)

View File

@@ -1,8 +1,9 @@
import { loadEnvFile } from "node:process";
import path from "node:path";
loadEnvFile("../../../../.env") // Global
loadEnvFile("../../.env") // Especifica del servicio
loadEnvFile(path.join(__dirname, "../../../../.env")) // Global
loadEnvFile(path.join(__dirname, "../../.env")) // base
export const env = {
ENVIRONMENT: process.env.ENVIORMENT,
@@ -30,3 +31,4 @@ export const env = {
};
console.log("env", env)

View File

@@ -1,7 +1,7 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/sim-consumidor",
"outDir": "../../dist/sim-consumidor-activaciones",
"baseUrl": ".",
"paths": {
"#config/*": [
@@ -22,6 +22,9 @@
"#shared/*": [
"../shared/*"
],
"#root/*": [
"../../*"
],
}
},
"exclude": [

View File

@@ -0,0 +1,15 @@
import { defineConfig } from 'vitest/config'
import tsconfigPaths from 'vite-tsconfig-paths'
import { loadEnv } from 'vite'
export default defineConfig(({ mode }) => ({
test: {
env: loadEnv(mode, process.cwd(), '')
},
plugins: [
tsconfigPaths({
root: "./"
})
]
}))