@@ -255,6 +255,95 @@ describe('createConfigStore', () => {
255255 } ) ;
256256 } ) ;
257257
258+ describe ( 'multi-target contexts' , ( ) => {
259+ it ( 'should create a context with targets' , ( ) => {
260+ const store = createStore ( ) ;
261+ const ctx = store . createContext ( 'production' , {
262+ endpoint : 'https://api.example.com/graphql' ,
263+ targets : {
264+ auth : { endpoint : 'https://auth.example.com/graphql' } ,
265+ members : { endpoint : 'https://members.example.com/graphql' } ,
266+ app : { endpoint : 'https://app.example.com/graphql' } ,
267+ } ,
268+ } ) ;
269+ expect ( ctx . targets ) . toBeDefined ( ) ;
270+ expect ( ctx . targets ! . auth . endpoint ) . toBe ( 'https://auth.example.com/graphql' ) ;
271+ expect ( ctx . targets ! . members . endpoint ) . toBe ( 'https://members.example.com/graphql' ) ;
272+ expect ( ctx . targets ! . app . endpoint ) . toBe ( 'https://app.example.com/graphql' ) ;
273+ } ) ;
274+
275+ it ( 'should load a context with targets' , ( ) => {
276+ const store = createStore ( ) ;
277+ store . createContext ( 'production' , {
278+ endpoint : 'https://api.example.com/graphql' ,
279+ targets : {
280+ auth : { endpoint : 'https://auth.example.com/graphql' } ,
281+ } ,
282+ } ) ;
283+ const ctx = store . loadContext ( 'production' ) ;
284+ expect ( ctx ! . targets ! . auth . endpoint ) . toBe ( 'https://auth.example.com/graphql' ) ;
285+ } ) ;
286+
287+ it ( 'should create a context without targets (backward compatible)' , ( ) => {
288+ const store = createStore ( ) ;
289+ const ctx = store . createContext ( 'production' , {
290+ endpoint : 'https://api.example.com/graphql' ,
291+ } ) ;
292+ expect ( ctx . targets ) . toBeUndefined ( ) ;
293+ } ) ;
294+
295+ it ( 'should get target endpoint from multi-target context' , ( ) => {
296+ const store = createStore ( ) ;
297+ store . createContext ( 'production' , {
298+ endpoint : 'https://api.example.com/graphql' ,
299+ targets : {
300+ auth : { endpoint : 'https://auth.example.com/graphql' } ,
301+ app : { endpoint : 'https://app.example.com/graphql' } ,
302+ } ,
303+ } ) ;
304+ store . setCurrentContext ( 'production' ) ;
305+ expect ( store . getTargetEndpoint ( 'auth' ) ) . toBe ( 'https://auth.example.com/graphql' ) ;
306+ expect ( store . getTargetEndpoint ( 'app' ) ) . toBe ( 'https://app.example.com/graphql' ) ;
307+ } ) ;
308+
309+ it ( 'should fall back to main endpoint for unknown target' , ( ) => {
310+ const store = createStore ( ) ;
311+ store . createContext ( 'production' , {
312+ endpoint : 'https://api.example.com/graphql' ,
313+ targets : {
314+ auth : { endpoint : 'https://auth.example.com/graphql' } ,
315+ } ,
316+ } ) ;
317+ store . setCurrentContext ( 'production' ) ;
318+ expect ( store . getTargetEndpoint ( 'unknown' ) ) . toBe ( 'https://api.example.com/graphql' ) ;
319+ } ) ;
320+
321+ it ( 'should fall back to main endpoint for single-target context' , ( ) => {
322+ const store = createStore ( ) ;
323+ store . createContext ( 'production' , {
324+ endpoint : 'https://api.example.com/graphql' ,
325+ } ) ;
326+ store . setCurrentContext ( 'production' ) ;
327+ expect ( store . getTargetEndpoint ( 'anything' ) ) . toBe ( 'https://api.example.com/graphql' ) ;
328+ } ) ;
329+
330+ it ( 'should return null when no current context for getTargetEndpoint' , ( ) => {
331+ const store = createStore ( ) ;
332+ expect ( store . getTargetEndpoint ( 'auth' ) ) . toBeNull ( ) ;
333+ } ) ;
334+
335+ it ( 'should get target endpoint by explicit context name' , ( ) => {
336+ const store = createStore ( ) ;
337+ store . createContext ( 'staging' , {
338+ endpoint : 'https://staging.example.com/graphql' ,
339+ targets : {
340+ auth : { endpoint : 'https://auth.staging.example.com/graphql' } ,
341+ } ,
342+ } ) ;
343+ expect ( store . getTargetEndpoint ( 'auth' , 'staging' ) ) . toBe ( 'https://auth.staging.example.com/graphql' ) ;
344+ } ) ;
345+ } ) ;
346+
258347 describe ( 'full workflow' , ( ) => {
259348 it ( 'should support the complete context + auth workflow' , ( ) => {
260349 const store = createStore ( ) ;
0 commit comments