@@ -8,27 +8,57 @@ import process from 'node:process';
8
8
import { AxiosError } from 'axios' ;
9
9
import { MCDocument } from './types.js' ;
10
10
11
- // hard-coded, replace with your own project,
12
- // or ask alois is you want this to be shared with your account
13
- const testProjectId = '316557b3-cb6f-47ed-acf7-fcfb7ce188d5' ;
11
+ let testProjectId = '316557b3-cb6f-47ed-acf7-fcfb7ce188d5' ;
12
+ let baseURL = new URL ( 'https://test.mermaidchart.com' ) ;
14
13
15
14
let client : MermaidChart ;
16
15
17
16
beforeAll ( async ( ) => {
17
+ if ( process . env . TEST_MERMAIDCHART_BASE_URL ) {
18
+ try {
19
+ baseURL = new URL ( process . env . TEST_MERMAIDCHART_BASE_URL ) ;
20
+ } catch ( err ) {
21
+ throw new Error ( "Invalid URL in environment variable TEST_MERMAIDCHART_BASE_URL" , { cause : err } ) ;
22
+ }
23
+ } else {
24
+ process . emitWarning ( `Missing environment variable TEST_MERMAIDCHART_BASE_URL. Defaulting to ${ baseURL . href } .` ) ;
25
+ }
26
+
18
27
if ( ! process . env . TEST_MERMAIDCHART_API_TOKEN ) {
19
28
throw new Error (
20
29
"Missing required environment variable TEST_MERMAIDCHART_API_TOKEN. "
21
- + " Please go to https://test.mermaidchart.com/ app/user/settings and create one."
30
+ + ` Please go to ${ new URL ( '/ app/user/settings' , baseURL ) } and create one.`
22
31
) ;
23
32
}
24
33
25
34
client = new MermaidChart ( {
26
35
clientID : '00000000-0000-0000-0000-000000git000test' ,
27
- baseURL : 'https://test.mermaidchart.com' ,
36
+ baseURL : baseURL . href ,
28
37
redirectURI : 'https://localhost.invalid' ,
29
38
} ) ;
30
39
31
40
await client . setAccessToken ( process . env . TEST_MERMAIDCHART_API_TOKEN ) ;
41
+
42
+ const projects = await client . getProjects ( ) ;
43
+
44
+ // confirm that testProjectId is valid
45
+ if ( process . env . TEST_MERMAIDCHART_PROJECT_ID ) {
46
+ testProjectId = process . env . TEST_MERMAIDCHART_PROJECT_ID ;
47
+ if ( ! projects . find ( ( project ) => project . id === testProjectId ) ) {
48
+ throw new Error (
49
+ `Missing environment variable TEST_MERMAIDCHART_PROJECT_ID. `
50
+ + `Please go to ${ new URL ( '/app/projects' , baseURL ) } and create one.`
51
+ ) ;
52
+ }
53
+ } else {
54
+ if ( ! projects . find ( ( project ) => project . id === testProjectId ) ) {
55
+ throw new Error (
56
+ `Missing environment variable TEST_MERMAIDCHART_PROJECT_ID. `
57
+ + `Please go to ${ new URL ( '/app/projects' , baseURL ) } and create one.`
58
+ ) ;
59
+ }
60
+ process . emitWarning ( `Missing optional environment variable TEST_MERMAIDCHART_PROJECT_ID. Defaulting to ${ testProjectId } ` ) ;
61
+ }
32
62
} ) ;
33
63
34
64
describe ( 'getUser' , ( ) => {
0 commit comments