@@ -137,22 +137,27 @@ describe('StencilStart unit tests', () => {
137137 const storeHash = 'storeHash_value' ;
138138 const channelId = 5 ;
139139 const storeUrl = 'https://www.example.com' ;
140- it ( 'should obtain channel id from the api' , async ( ) => {
140+ it ( 'should obtain channel info object from the api when no channelUrl is provided ' , async ( ) => {
141141 const channels = [ { channel_id : channelId , url : storeUrl } ] ;
142142 const themeApiClientStub = {
143143 checkCliVersion : jest . fn ( ) ,
144144 getStoreHash : jest . fn ( ) . mockResolvedValue ( storeHash ) ,
145145 getStoreChannels : jest . fn ( ) . mockResolvedValue ( channels ) ,
146146 } ;
147+ const stencilPushUtilsStub = {
148+ promptUserToSelectChannel : jest . fn ( ) . mockResolvedValue ( channelId ) ,
149+ } ;
147150 const { instance } = createStencilStartInstance ( {
148151 themeApiClient : themeApiClientStub ,
149- stencilPushUtils : stencilPushUtilsModule ,
152+ stencilPushUtils : stencilPushUtilsStub ,
150153 } ) ;
151- const result = await instance . getChannelUrl ( { accessToken } , { apiHost } ) ;
152- expect ( result ) . toEqual ( storeUrl ) ;
154+ const stencilConfig = { accessToken, normalStoreUrl : 'https://example.com' , apiHost } ;
155+ const cliOptions = { apiHost } ;
156+ const result = await instance . getChannelInfo ( stencilConfig , cliOptions ) ;
157+ expect ( result ) . toEqual ( channels [ 0 ] ) ;
153158 } ) ;
154159
155- it ( 'should obtain channel url from the CLI ' , async ( ) => {
160+ it ( 'should return the channelUrl string from cliOptions if provided ' , async ( ) => {
156161 const channelUrl = 'https://shop.bigcommerce.com' ;
157162 const channels = [ { channel_id : channelId , url : storeUrl } ] ;
158163 const themeApiClientStub = {
@@ -164,7 +169,9 @@ describe('StencilStart unit tests', () => {
164169 themeApiClient : themeApiClientStub ,
165170 stencilPushUtils : stencilPushUtilsModule ,
166171 } ) ;
167- const result = await instance . getChannelUrl ( { accessToken } , { apiHost, channelUrl } ) ;
172+ const stencilConfig = { accessToken, normalStoreUrl : 'https://example.com' , apiHost } ;
173+ const cliOptions = { apiHost, channelUrl } ;
174+ const result = await instance . getChannelInfo ( stencilConfig , cliOptions ) ;
168175 expect ( result ) . toEqual ( channelUrl ) ;
169176 } ) ;
170177 } ) ;
@@ -173,9 +180,23 @@ describe('StencilStart unit tests', () => {
173180 it ( 'should read port from the config file' , async ( ) => {
174181 const port = 1234 ;
175182 const browserSyncStub = getBrowserSyncStub ( ) ;
183+ const themeApiClientStub = {
184+ checkCliVersion : jest
185+ . fn ( )
186+ . mockResolvedValue ( { baseUrl : 'example.com' , sslUrl : 'https://example.com' } ) ,
187+ getStoreHash : jest . fn ( ) . mockResolvedValue ( 'storeHash_value' ) ,
188+ getStoreChannels : jest
189+ . fn ( )
190+ . mockResolvedValue ( [ { channel_id : 5 , url : 'https://www.example.com' } ] ) ,
191+ } ;
192+ const stencilPushUtilsStub = {
193+ promptUserToSelectChannel : jest . fn ( ) . mockResolvedValue ( 5 ) ,
194+ } ;
176195 const { instance } = createStencilStartInstance ( {
177196 browserSync : browserSyncStub ,
178197 stencilConfigManager : getStencilConfigManagerStub ( { port } ) ,
198+ themeApiClient : themeApiClientStub ,
199+ stencilPushUtils : stencilPushUtilsStub ,
179200 } ) ;
180201 instance . startLocalServer = jest . fn ( ) ;
181202 instance . getStartUpInfo = jest . fn ( ) . mockReturnValue ( 'Start up info' ) ;
@@ -191,9 +212,23 @@ describe('StencilStart unit tests', () => {
191212 it ( 'should read port from the cli' , async ( ) => {
192213 const port = 1234 ;
193214 const browserSyncStub = getBrowserSyncStub ( ) ;
215+ const themeApiClientStub = {
216+ checkCliVersion : jest
217+ . fn ( )
218+ . mockResolvedValue ( { baseUrl : 'example.com' , sslUrl : 'https://example.com' } ) ,
219+ getStoreHash : jest . fn ( ) . mockResolvedValue ( 'storeHash_value' ) ,
220+ getStoreChannels : jest
221+ . fn ( )
222+ . mockResolvedValue ( [ { channel_id : 5 , url : 'https://www.example.com' } ] ) ,
223+ } ;
224+ const stencilPushUtilsStub = {
225+ promptUserToSelectChannel : jest . fn ( ) . mockResolvedValue ( 5 ) ,
226+ } ;
194227 const { instance } = createStencilStartInstance ( {
195228 browserSync : browserSyncStub ,
196229 stencilConfigManager : getStencilConfigManagerStub ( { port : 5678 } ) ,
230+ themeApiClient : themeApiClientStub ,
231+ stencilPushUtils : stencilPushUtilsStub ,
197232 } ) ;
198233 instance . startLocalServer = jest . fn ( ) ;
199234 instance . getStartUpInfo = jest . fn ( ) . mockReturnValue ( 'Start up info' ) ;
0 commit comments