11import axios , { AxiosInstance } from "axios" ;
2+ import path from "path" ;
3+ import { DockerComposeEnvironment , StartedDockerComposeEnvironment } from "testcontainers" ;
24import { ConsumptionServices } from "../../src" ;
35import { RuntimeServiceProvider } from "../lib" ;
46
57const runtimeServiceProvider = new RuntimeServiceProvider ( ) ;
68let consumptionServices : ConsumptionServices ;
7- let oid4vcServiceBaseUrl : string ;
89let axiosInstance : AxiosInstance ;
10+ let dockerComposeStack : StartedDockerComposeEnvironment | undefined ;
911
1012beforeAll ( async ( ) => {
1113 const runtimeServices = await runtimeServiceProvider . launch ( 1 ) ;
1214 consumptionServices = runtimeServices [ 0 ] . consumption ;
1315
14- oid4vcServiceBaseUrl = process . env . OPENID4VC_SERVICE_BASEURL ! ;
16+ let oid4vcServiceBaseUrl = process . env . OPENID4VC_SERVICE_BASEURL ! ;
1517 if ( ! oid4vcServiceBaseUrl ) {
16- throw new Error ( "OPENID4VC_SERVICE_BASEURL environment variable is not set" ) ;
18+ dockerComposeStack = await startOid4VcComposeStack ( ) ;
19+ const mappedPort = dockerComposeStack . getContainer ( "oid4vc-service-1" ) . getMappedPort ( 9000 ) ;
20+ oid4vcServiceBaseUrl = `http://localhost:${ mappedPort } ` ;
1721 }
1822
1923 axiosInstance = axios . create ( {
@@ -26,6 +30,7 @@ beforeAll(async () => {
2630
2731afterAll ( async ( ) => {
2832 await runtimeServiceProvider . stop ( ) ;
33+ if ( dockerComposeStack ) await dockerComposeStack . down ( ) ;
2934} ) ;
3035
3136describe ( "OpenID4VCI and OpenID4VCP" , ( ) => {
@@ -144,3 +149,27 @@ describe("OpenID4VCI and OpenID4VCP", () => {
144149 expect ( singleCredentialResult . value [ 0 ] . id ) . toBe ( firstCredentialId ) ;
145150 } , 10000000 ) ;
146151} ) ;
152+
153+ async function startOid4VcComposeStack ( ) {
154+ let baseUrl = process . env . NMSHD_TEST_BASEURL ?? "http://localhost:8080" ;
155+ let addressGenerationHostnameOverride : string | undefined ;
156+
157+ if ( baseUrl . includes ( "localhost" ) ) {
158+ addressGenerationHostnameOverride = "localhost" ;
159+ baseUrl = baseUrl . replace ( "localhost" , "host.docker.internal" ) ;
160+ }
161+
162+ const composeFolder = path . resolve ( path . join ( __dirname , ".." , ".." , ".." , ".." , ".dev" ) ) ;
163+ const composeStack = await new DockerComposeEnvironment ( composeFolder , "compose.openid4vc.yml" )
164+ . withProjectName ( "runtime-oid4vc-tests" )
165+ . withEnvironment ( {
166+ // eslint-disable-next-line @typescript-eslint/naming-convention
167+ NMSHD_TEST_BASEURL : baseUrl ,
168+ // eslint-disable-next-line @typescript-eslint/naming-convention
169+ NMSHD_TEST_ADDRESSGENERATIONHOSTNAMEOVERRIDE : addressGenerationHostnameOverride
170+ } as Record < string , string > )
171+ . withStartupTimeout ( 60000 )
172+ . up ( ) ;
173+
174+ return composeStack ;
175+ }
0 commit comments