@@ -47,7 +47,7 @@ describe('minimal sanity client', () => {
47
47
client . fetch ( '*[_type == "article"' )
48
48
49
49
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 ' ,
51
51
expect . not . objectContaining ( { method : 'post' } ) ,
52
52
)
53
53
} )
@@ -148,4 +148,36 @@ describe('minimal sanity client', () => {
148
148
} ,
149
149
)
150
150
} )
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
+ } )
151
183
} )
0 commit comments