@@ -17,78 +17,114 @@ vi.mock('@junobuild/config-loader', async () => {
17
17
} ) ;
18
18
19
19
describe ( 'init' , ( ) => {
20
- describe ( 'initConfig (with config-loader mocks)' , ( ) => {
21
- const args : ConfigArgs = {
20
+ const args : ConfigArgs = {
21
+ params : { } ,
22
+ mode : 'production'
23
+ } ;
24
+
25
+ let spyJunoConfigExist : MockInstance ;
26
+ let spyReadJunoConfig : MockInstance ;
27
+
28
+ beforeEach ( ( ) => {
29
+ vi . clearAllMocks ( ) ;
30
+
31
+ spyJunoConfigExist = vi . spyOn ( configLoader , 'junoConfigExist' ) . mockResolvedValue ( true ) ;
32
+ spyReadJunoConfig = vi . spyOn ( configLoader , 'readJunoConfig' ) . mockResolvedValue ( {
33
+ satellite : { ids : { production : 'mock-satellite-id' } } ,
34
+ orbiter : { id : 'mock-orbiter-id' }
35
+ } ) ;
36
+ } ) ;
37
+
38
+ it ( 'returns config for development' , async ( ) => {
39
+ const result = await initConfig ( {
22
40
params : { } ,
23
41
mode : 'development'
24
- } ;
42
+ } ) ;
25
43
26
- let spyJunoConfigExist : MockInstance ;
27
- let spyReadJunoConfig : MockInstance ;
44
+ expect ( result ) . toEqual ( {
45
+ orbiterId : undefined ,
46
+ satelliteId : 'jx5yt-yyaaa-aaaal-abzbq-cai' ,
47
+ icpIds : {
48
+ internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
49
+ icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
50
+ icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
51
+ } ,
52
+ container : 'http://127.0.0.1:5987'
53
+ } ) ;
28
54
29
- beforeEach ( ( ) => {
30
- vi . clearAllMocks ( ) ;
55
+ expect ( spyJunoConfigExist ) . not . toHaveBeenCalled ( ) ;
56
+ expect ( spyReadJunoConfig ) . not . toHaveBeenCalled ( ) ;
57
+ } ) ;
31
58
32
- spyJunoConfigExist = vi . spyOn ( configLoader , 'junoConfigExist' ) . mockResolvedValue ( true ) ;
33
- spyReadJunoConfig = vi . spyOn ( configLoader , 'readJunoConfig' ) . mockResolvedValue ( {
34
- satellite : { ids : { development : 'mock-satellite-id' } } ,
35
- orbiter : { id : 'mock-orbiter-id' }
36
- } ) ;
59
+ it ( 'returns config without container for production' , async ( ) => {
60
+ const result = await initConfig ( args ) ;
61
+
62
+ expect ( result ) . toEqual ( {
63
+ satelliteId : 'mock-satellite-id' ,
64
+ orbiterId : 'mock-orbiter-id' ,
65
+ icpIds : {
66
+ internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
67
+ icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
68
+ icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
69
+ } ,
70
+ container : undefined
37
71
} ) ;
38
72
39
- it ( 'returns config when not using Docker container' , async ( ) => {
40
- const result = await initConfig ( args ) ;
73
+ expect ( spyJunoConfigExist ) . toHaveBeenCalled ( ) ;
74
+ expect ( spyReadJunoConfig ) . toHaveBeenCalled ( ) ;
75
+ } ) ;
41
76
42
- expect ( result ) . toEqual ( {
43
- satelliteId : 'mock-satellite-id' ,
44
- orbiterId : 'mock-orbiter-id' ,
45
- icpIds : {
46
- internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
47
- icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
48
- icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
49
- } ,
50
- container : undefined
51
- } ) ;
77
+ it ( 'skips assertJunoConfig when using Docker container' , async ( ) => {
78
+ const dockerArgs : ConfigArgs = {
79
+ params : { container : true } ,
80
+ mode : 'development'
81
+ } ;
52
82
53
- expect ( spyJunoConfigExist ) . toHaveBeenCalled ( ) ;
54
- expect ( spyReadJunoConfig ) . toHaveBeenCalled ( ) ;
83
+ const result = await initConfig ( dockerArgs ) ;
84
+
85
+ expect ( result ) . toEqual ( {
86
+ satelliteId : 'jx5yt-yyaaa-aaaal-abzbq-cai' , // fallback to docker const
87
+ orbiterId : undefined ,
88
+ icpIds : {
89
+ internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
90
+ icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
91
+ icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
92
+ } ,
93
+ container : 'http://127.0.0.1:5987'
55
94
} ) ;
56
95
57
- it ( 'skips assertJunoConfig when using Docker container' , async ( ) => {
58
- const dockerArgs : ConfigArgs = {
59
- params : { container : true } ,
60
- mode : 'development'
61
- } ;
62
-
63
- const result = await initConfig ( dockerArgs ) ;
96
+ expect ( spyJunoConfigExist ) . not . toHaveBeenCalled ( ) ;
97
+ expect ( spyReadJunoConfig ) . not . toHaveBeenCalled ( ) ;
98
+ } ) ;
64
99
65
- expect ( result ) . toEqual ( {
66
- satelliteId : 'jx5yt-yyaaa-aaaal-abzbq-cai' , // fallback to docker const
67
- orbiterId : undefined ,
68
- icpIds : {
69
- internetIdentityId : 'rdmx6-jaaaa-aaaaa-aaadq-cai' ,
70
- icpLedgerId : 'ryjl3-tyaaa-aaaaa-aaaba-cai' ,
71
- icpIndexId : 'qhbym-qaaaa-aaaaa-aaafq-cai'
72
- } ,
73
- container : 'http://127.0.0.1:5987'
74
- } ) ;
100
+ it ( 'throws if config does not exist and mode is production' , async ( ) => {
101
+ vi . spyOn ( configLoader , 'junoConfigExist' ) . mockResolvedValue ( false ) ;
75
102
76
- expect ( spyJunoConfigExist ) . not . toHaveBeenCalled ( ) ;
77
- expect ( spyReadJunoConfig ) . not . toHaveBeenCalled ( ) ;
78
- } ) ;
103
+ await expect ( initConfig ( args ) ) . rejects . toThrow ( / N o J u n o c o n f i g u r a t i o n f o u n d / ) ;
104
+ } ) ;
79
105
80
- it ( 'throws if config does not exist' , async ( ) => {
81
- vi . spyOn ( configLoader , 'junoConfigExist' ) . mockResolvedValue ( false ) ;
106
+ it ( 'throws if satelliteId is missing in config if container is set to false' , async ( ) => {
107
+ vi . spyOn ( configLoader , 'readJunoConfig' ) . mockResolvedValueOnce ( {
108
+ satellite : { }
109
+ } as unknown as JunoConfig ) ;
82
110
83
- await expect ( initConfig ( args ) ) . rejects . toThrow ( / N o J u n o c o n f i g u r a t i o n f o u n d / ) ;
84
- } ) ;
111
+ await expect (
112
+ initConfig ( {
113
+ params : {
114
+ container : false
115
+ } ,
116
+ mode : 'development'
117
+ } )
118
+ ) . rejects . toThrow ( / A s a t e l l i t e I D f o r d e v e l o p m e n t m u s t b e s e t / ) ;
119
+ } ) ;
85
120
86
- it ( 'throws if satelliteId is missing in config' , async ( ) => {
87
- vi . spyOn ( configLoader , 'readJunoConfig' ) . mockResolvedValueOnce ( {
88
- satellite : { }
89
- } as unknown as JunoConfig ) ;
121
+ it ( 'throws if satelliteId is missing in config' , async ( ) => {
122
+ vi . spyOn ( configLoader , 'readJunoConfig' ) . mockResolvedValueOnce ( {
123
+ satellite : { }
124
+ } as unknown as JunoConfig ) ;
90
125
91
- await expect ( initConfig ( args ) ) . rejects . toThrow ( / A s a t e l l i t e I D f o r d e v e l o p m e n t m u s t b e s e t / ) ;
92
- } ) ;
126
+ await expect ( initConfig ( args ) ) . rejects . toThrow (
127
+ / Y o u r c o n f i g u r a t i o n i s i n v a l i d . A s a t e l l i t e I D f o r p r o d u c t i o n m u s t b e s e t i n y o u r c o n f i g u r a t i o n f i l e ./
128
+ ) ;
93
129
} ) ;
94
130
} ) ;
0 commit comments