11import  { filter ,  firstValueFrom ,  of ,  Subject ,  take }  from  'rxjs' 
22import  { describe ,  expect ,  it ,  vi }  from  'vitest' 
33
4- import  { type  PerspectiveHandle ,   type   ReleasePerspective }  from  '../config/sanityConfig' 
4+ import  { type  ReleasePerspective ,   sourceFor }  from  '../config/sanityConfig' 
55import  { createSanityInstance ,  type  SanityInstance }  from  '../store/createSanityInstance' 
66import  { listenQuery  as  mockListenQuery }  from  '../utils/listenQuery' 
77import  { getPerspectiveState }  from  './getPerspectiveState' 
@@ -20,6 +20,7 @@ vi.mock('../client/clientStore', () => ({
2020} ) ) 
2121
2222describe ( 'getPerspectiveState' ,  ( )  =>  { 
23+   const  source  =  sourceFor ( { projectId : 'test' ,  dataset : 'test' } ) 
2324  let  instance : SanityInstance 
2425  let  mockReleasesQuerySubject : Subject < ReleaseDocument [ ] > 
2526
@@ -53,40 +54,22 @@ describe('getPerspectiveState', () => {
5354    vi . clearAllMocks ( ) 
5455  } ) 
5556
56-   it ( 'should return default perspective if no options or instance perspective is provided' ,  async  ( )  =>  { 
57-     const  state  =  getPerspectiveState ( instance ,  { } ) 
58-     mockReleasesQuerySubject . next ( [ ] ) 
59-     const  perspective  =  await  firstValueFrom ( state . observable ) 
60-     expect ( perspective ) . toBe ( 'drafts' ) 
61-   } ) 
62- 
63-   it ( 'should return instance perspective if provided and no options perspective' ,  async  ( )  =>  { 
64-     instance . config . perspective  =  'published' 
65-     const  state  =  getPerspectiveState ( instance ,  { } ) 
66-     mockReleasesQuerySubject . next ( [ ] ) 
67-     const  perspective  =  await  firstValueFrom ( state . observable ) 
68-     expect ( perspective ) . toBe ( 'published' ) 
69-   } ) 
70- 
7157  it ( 'should return options perspective if provided' ,  async  ( )  =>  { 
72-     const  options : PerspectiveHandle  =  { perspective : 'raw' } 
73-     const  state  =  getPerspectiveState ( instance ,  options ) 
58+     const  state  =  getPerspectiveState ( instance ,  { perspective : 'raw' ,  source} ) 
7459    mockReleasesQuerySubject . next ( [ ] ) 
7560    const  perspective  =  await  firstValueFrom ( state . observable ) 
7661    expect ( perspective ) . toBe ( 'raw' ) 
7762  } ) 
7863
7964  it ( 'should return undefined if release perspective is requested but no active releases' ,  async  ( )  =>  { 
80-     const  options : PerspectiveHandle  =  { perspective : { releaseName : 'release1' } } 
81-     const  state  =  getPerspectiveState ( instance ,  options ) 
65+     const  state  =  getPerspectiveState ( instance ,  { perspective : { releaseName : 'release1' } ,  source} ) 
8266    mockReleasesQuerySubject . next ( [ ] ) 
8367    const  perspective  =  await  firstValueFrom ( state . observable ) 
8468    expect ( perspective ) . toBeUndefined ( ) 
8569  } ) 
8670
8771  it ( 'should calculate perspective based on active releases and releaseName' ,  async  ( )  =>  { 
88-     const  options : PerspectiveHandle  =  { perspective : { releaseName : 'release1' } } 
89-     const  state  =  getPerspectiveState ( instance ,  options ) 
72+     const  state  =  getPerspectiveState ( instance ,  { perspective : { releaseName : 'release1' } ,  source} ) 
9073    mockReleasesQuerySubject . next ( activeReleases ) 
9174
9275    const  perspective  =  await  firstValueFrom ( 
@@ -99,8 +82,7 @@ describe('getPerspectiveState', () => {
9982  } ) 
10083
10184  it ( 'should calculate perspective including multiple releases up to the specified releaseName' ,  async  ( )  =>  { 
102-     const  options : PerspectiveHandle  =  { perspective : { releaseName : 'release2' } } 
103-     const  state  =  getPerspectiveState ( instance ,  options ) 
85+     const  state  =  getPerspectiveState ( instance ,  { perspective : { releaseName : 'release2' } ,  source} ) 
10486    mockReleasesQuerySubject . next ( activeReleases ) 
10587    const  perspective  =  await  firstValueFrom ( 
10688      state . observable . pipe ( 
@@ -116,8 +98,7 @@ describe('getPerspectiveState', () => {
11698      releaseName : 'release2' , 
11799      excludedPerspectives : [ 'drafts' ,  'release1' ] , 
118100    } 
119-     const  options : PerspectiveHandle  =  { perspective : perspectiveConfig } 
120-     const  state  =  getPerspectiveState ( instance ,  options ) 
101+     const  state  =  getPerspectiveState ( instance ,  { perspective : perspectiveConfig ,  source} ) 
121102    mockReleasesQuerySubject . next ( activeReleases ) 
122103    const  perspective  =  await  firstValueFrom ( 
123104      state . observable . pipe ( 
@@ -129,8 +110,7 @@ describe('getPerspectiveState', () => {
129110  } ) 
130111
131112  it ( 'should throw if the specified releaseName is not found in active releases' ,  async  ( )  =>  { 
132-     const  options : PerspectiveHandle  =  { perspective : { releaseName : 'nonexistent' } } 
133-     const  state  =  getPerspectiveState ( instance ,  options ) 
113+     const  state  =  getPerspectiveState ( instance ,  { perspective : { releaseName : 'nonexistent' } ,  source} ) 
134114    mockReleasesQuerySubject . next ( activeReleases ) 
135115
136116    await  expect ( 
@@ -144,10 +124,10 @@ describe('getPerspectiveState', () => {
144124  } ) 
145125
146126  it ( 'should reuse the same options object for identical inputs (cache test)' ,  async  ( )  =>  { 
147-     const  options1 :  PerspectiveHandle  =  { perspective : { releaseName : 'release1' } } 
148-     const  options2 :  PerspectiveHandle  =  { perspective : { releaseName : 'release1' } } 
127+     const  options1  =  { perspective : { releaseName : 'release1' } } 
128+     const  options2  =  { perspective : { releaseName : 'release1' } } 
149129
150-     const  state1  =  getPerspectiveState ( instance ,  options1 ) 
130+     const  state1  =  getPerspectiveState ( instance ,  { ... options1 ,  source } ) 
151131    mockReleasesQuerySubject . next ( activeReleases ) 
152132    await  firstValueFrom ( 
153133      state1 . observable . pipe ( 
@@ -156,15 +136,14 @@ describe('getPerspectiveState', () => {
156136      ) , 
157137    ) 
158138
159-     const  state2  =  getPerspectiveState ( instance ,  options2 ) 
139+     const  state2  =  getPerspectiveState ( instance ,  { ... options2 ,  source } ) 
160140    const  perspective2  =  state2 . getCurrent ( ) 
161141
162142    expect ( perspective2 ) . toEqual ( [ 'drafts' ,  'release1' ] ) 
163143  } ) 
164144
165145  it ( 'should handle changes in activeReleases (cache test)' ,  async  ( )  =>  { 
166-     const  options : PerspectiveHandle  =  { perspective : { releaseName : 'release1' } } 
167- 
146+     const  options  =  { perspective : { releaseName : 'release1' } ,  source} 
168147    const  state1  =  getPerspectiveState ( instance ,  options ) 
169148    mockReleasesQuerySubject . next ( activeReleases ) 
170149    const  perspective1  =  await  firstValueFrom ( 
0 commit comments