@@ -47,7 +47,7 @@ describe('minimal sanity client', () => {
4747 client . fetch ( '*[_type == "article"' )
4848
4949 expect ( $fetch ) . toBeCalledWith (
50- 'https://sample-project.api.sanity.io/v1/data/query/undefined?query=*%5B_type%20%3D%3D%20%22article%22' ,
50+ 'https://sample-project.api.sanity.io/v1/data/query/undefined?query=*%5B_type%20%3D%3D%20%22article%22&perspective=raw ' ,
5151 expect . not . objectContaining ( { method : 'post' } ) ,
5252 )
5353 } )
@@ -148,4 +148,36 @@ describe('minimal sanity client', () => {
148148 } ,
149149 )
150150 } )
151+
152+ it ( 'appends perspective to the query with GET request' , async ( ) => {
153+ const client = createClient ( {
154+ projectId : 'sample-project' ,
155+ apiVersion : '1' ,
156+ } )
157+ const query = '*[_type == "article"]'
158+ await client . fetch ( query )
159+
160+ expect ( $fetch ) . toBeCalledWith (
161+ `https://${ project } .api.sanity.io/v1/data/query/undefined?query=${ encodeURIComponent ( query ) } &perspective=raw` ,
162+ {
163+ credentials : 'omit' ,
164+ headers : {
165+ Accept : 'application/json' ,
166+ } ,
167+ } ,
168+ )
169+ } )
170+
171+ it ( 'appends perspective to the query with POST request' , ( ) => {
172+ const client = createClient ( {
173+ projectId : 'sample-project' ,
174+ apiVersion : '1' ,
175+ } )
176+ client . fetch ( largeRequest )
177+
178+ expect ( $fetch ) . toBeCalledWith (
179+ 'https://sample-project.api.sanity.io/v1/data/query/undefined' ,
180+ expect . objectContaining ( { method : 'post' , query : { perspective : 'raw' } } ) ,
181+ )
182+ } )
151183} )
0 commit comments