1
1
import type { JunoConfig } from '@junobuild/config' ;
2
2
import * as configLoader from '@junobuild/config-loader' ;
3
3
import { beforeEach , describe , expect , it , MockInstance , vi } from 'vitest' ;
4
+ import {
5
+ DOCKER_CONTAINER_URL ,
6
+ DOCKER_SATELLITE_ID ,
7
+ ICP_INDEX_ID ,
8
+ ICP_LEDGER_ID ,
9
+ INTERNET_IDENTITY_ID
10
+ } from './constants' ;
4
11
import { initConfig } from './init' ;
5
12
import type { ConfigArgs } from './types' ;
6
13
@@ -36,23 +43,25 @@ describe('init', () => {
36
43
} ) ;
37
44
38
45
it ( 'returns config for development' , async ( ) => {
46
+ vi . spyOn ( configLoader , 'junoConfigExist' ) . mockResolvedValue ( false ) ;
47
+
39
48
const result = await initConfig ( {
40
49
params : { } ,
41
50
mode : 'development'
42
51
} ) ;
43
52
44
53
expect ( result ) . toEqual ( {
45
54
orbiterId : undefined ,
46
- satelliteId : 'jx5yt-yyaaa-aaaal-abzbq-cai' ,
55
+ satelliteId : DOCKER_SATELLITE_ID ,
47
56
icpIds : {
48
- internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
49
- icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
50
- icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
57
+ internetIdentityId : INTERNET_IDENTITY_ID ,
58
+ icpLedgerId : ICP_LEDGER_ID ,
59
+ icpIndexId : ICP_INDEX_ID
51
60
} ,
52
- container : 'http://127.0.0.1:5987'
61
+ container : DOCKER_CONTAINER_URL
53
62
} ) ;
54
63
55
- expect ( spyJunoConfigExist ) . not . toHaveBeenCalled ( ) ;
64
+ expect ( configLoader . junoConfigExist ) . toHaveBeenCalled ( ) ;
56
65
expect ( spyReadJunoConfig ) . not . toHaveBeenCalled ( ) ;
57
66
} ) ;
58
67
@@ -63,9 +72,9 @@ describe('init', () => {
63
72
satelliteId : 'mock-satellite-id' ,
64
73
orbiterId : 'mock-orbiter-id' ,
65
74
icpIds : {
66
- internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
67
- icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
68
- icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
75
+ internetIdentityId : INTERNET_IDENTITY_ID ,
76
+ icpLedgerId : ICP_LEDGER_ID ,
77
+ icpIndexId : ICP_INDEX_ID
69
78
} ,
70
79
container : undefined
71
80
} ) ;
@@ -74,24 +83,52 @@ describe('init', () => {
74
83
expect ( spyReadJunoConfig ) . toHaveBeenCalled ( ) ;
75
84
} ) ;
76
85
77
- it ( 'returns config for development when params is not passed' , async ( ) => {
78
- const result = await initConfig ( {
79
- mode : 'development'
80
- } ) ;
86
+ describe ( 'no config' , ( ) => {
87
+ it ( 'returns default docker satellite ID in development if config does not exist' , async ( ) => {
88
+ vi . spyOn ( configLoader , 'junoConfigExist' ) . mockResolvedValue ( false ) ;
81
89
82
- expect ( result ) . toEqual ( {
83
- satelliteId : 'jx5yt-yyaaa-aaaal-abzbq-cai' ,
84
- orbiterId : undefined ,
85
- icpIds : {
86
- internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
87
- icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
88
- icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
89
- } ,
90
- container : 'http://127.0.0.1:5987'
90
+ const result = await initConfig ( {
91
+ params : { } ,
92
+ mode : 'development'
93
+ } ) ;
94
+
95
+ expect ( result ) . toEqual ( {
96
+ orbiterId : undefined ,
97
+ satelliteId : DOCKER_SATELLITE_ID ,
98
+ icpIds : {
99
+ internetIdentityId : INTERNET_IDENTITY_ID ,
100
+ icpLedgerId : ICP_LEDGER_ID ,
101
+ icpIndexId : ICP_INDEX_ID
102
+ } ,
103
+ container : DOCKER_CONTAINER_URL
104
+ } ) ;
105
+
106
+ expect ( configLoader . junoConfigExist ) . toHaveBeenCalled ( ) ;
107
+ expect ( spyReadJunoConfig ) . not . toHaveBeenCalled ( ) ;
91
108
} ) ;
92
109
93
- expect ( spyJunoConfigExist ) . not . toHaveBeenCalled ( ) ;
94
- expect ( spyReadJunoConfig ) . not . toHaveBeenCalled ( ) ;
110
+ it ( 'returns fallback Docker satellite ID when using container and config does not exist and container is specified' , async ( ) => {
111
+ vi . spyOn ( configLoader , 'junoConfigExist' ) . mockResolvedValue ( false ) ;
112
+
113
+ const result = await initConfig ( {
114
+ params : { container : true } ,
115
+ mode : 'development'
116
+ } ) ;
117
+
118
+ expect ( result ) . toEqual ( {
119
+ satelliteId : DOCKER_SATELLITE_ID ,
120
+ orbiterId : undefined ,
121
+ icpIds : {
122
+ internetIdentityId : INTERNET_IDENTITY_ID ,
123
+ icpLedgerId : ICP_LEDGER_ID ,
124
+ icpIndexId : ICP_INDEX_ID
125
+ } ,
126
+ container : DOCKER_CONTAINER_URL
127
+ } ) ;
128
+
129
+ expect ( configLoader . junoConfigExist ) . toHaveBeenCalled ( ) ;
130
+ expect ( spyReadJunoConfig ) . not . toHaveBeenCalled ( ) ;
131
+ } ) ;
95
132
} ) ;
96
133
97
134
it ( 'returns config for production when params is not passed' , async ( ) => {
@@ -103,9 +140,9 @@ describe('init', () => {
103
140
satelliteId : 'mock-satellite-id' ,
104
141
orbiterId : 'mock-orbiter-id' ,
105
142
icpIds : {
106
- internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
107
- icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
108
- icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
143
+ internetIdentityId : INTERNET_IDENTITY_ID ,
144
+ icpLedgerId : ICP_LEDGER_ID ,
145
+ icpIndexId : ICP_INDEX_ID
109
146
} ,
110
147
container : undefined
111
148
} ) ;
@@ -114,27 +151,30 @@ describe('init', () => {
114
151
expect ( spyReadJunoConfig ) . toHaveBeenCalled ( ) ;
115
152
} ) ;
116
153
117
- it ( 'skips assertJunoConfig when using Docker container' , async ( ) => {
118
- const dockerArgs : ConfigArgs = {
154
+ it ( 'returns satellite ID from config when using container and config exists' , async ( ) => {
155
+ vi . spyOn ( configLoader , 'junoConfigExist' ) . mockResolvedValue ( true ) ;
156
+ vi . spyOn ( configLoader , 'readJunoConfig' ) . mockResolvedValue ( {
157
+ satellite : { ids : { development : 'custom-docker-id' } }
158
+ } ) ;
159
+
160
+ const result = await initConfig ( {
119
161
params : { container : true } ,
120
162
mode : 'development'
121
- } ;
122
-
123
- const result = await initConfig ( dockerArgs ) ;
163
+ } ) ;
124
164
125
165
expect ( result ) . toEqual ( {
126
- satelliteId : 'jx5yt-yyaaa-aaaal-abzbq-cai' , // fallback to docker const
166
+ satelliteId : 'custom-docker-id' ,
127
167
orbiterId : undefined ,
128
168
icpIds : {
129
- internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
130
- icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
131
- icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
169
+ internetIdentityId : INTERNET_IDENTITY_ID ,
170
+ icpLedgerId : ICP_LEDGER_ID ,
171
+ icpIndexId : ICP_INDEX_ID
132
172
} ,
133
- container : 'http://127.0.0.1:5987'
173
+ container : DOCKER_CONTAINER_URL
134
174
} ) ;
135
175
136
- expect ( spyJunoConfigExist ) . not . toHaveBeenCalled ( ) ;
137
- expect ( spyReadJunoConfig ) . not . toHaveBeenCalled ( ) ;
176
+ expect ( configLoader . junoConfigExist ) . toHaveBeenCalled ( ) ;
177
+ expect ( configLoader . readJunoConfig ) . toHaveBeenCalled ( ) ;
138
178
} ) ;
139
179
140
180
it ( 'throws if config does not exist and mode is production' , async ( ) => {
0 commit comments