@@ -35,7 +35,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
35
35
sp . set ( 'query' , 'foo' )
36
36
const res = await get ( '/api/search/v1?' + sp )
37
37
expect ( res . statusCode ) . toBe ( 200 )
38
- const results = JSON . parse ( res . text )
38
+ const results = JSON . parse ( res . body )
39
39
40
40
expect ( results . meta ) . toBeTruthy ( )
41
41
expect ( results . meta . found . value ) . toBeGreaterThanOrEqual ( 1 )
@@ -77,7 +77,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
77
77
sp . set ( 'debug' , '1' ) // Note!
78
78
const res = await get ( '/api/search/v1?' + sp )
79
79
expect ( res . statusCode ) . toBe ( 200 )
80
- const results = JSON . parse ( res . text )
80
+ const results = JSON . parse ( res . body )
81
81
// safe because we know exactly the fixtures
82
82
const hit = results . hits [ 0 ]
83
83
expect ( hit . popularity ) . toBeTruthy ( )
@@ -92,7 +92,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
92
92
sp . set ( 'query' , 'sill' )
93
93
const res = await get ( '/api/search/v1?' + sp )
94
94
expect ( res . statusCode ) . toBe ( 200 )
95
- const results = JSON . parse ( res . text )
95
+ const results = JSON . parse ( res . body )
96
96
// Fixtures contains no word called 'sill'. It does contain the term
97
97
// 'silly' which, in English, becomes 'silli` when stemmed.
98
98
// Because we don't use `&autocomplete=true` this time, we expect
@@ -107,7 +107,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
107
107
sp . set ( 'autocomplete' , 'true' )
108
108
const res = await get ( '/api/search/v1?' + sp )
109
109
expect ( res . statusCode ) . toBe ( 200 )
110
- const results = JSON . parse ( res . text )
110
+ const results = JSON . parse ( res . body )
111
111
expect ( results . meta . found . value ) . toBeGreaterThanOrEqual ( 1 )
112
112
const hit = results . hits [ 0 ]
113
113
const contentHighlights = hit . highlights . content
@@ -120,7 +120,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
120
120
sp . set ( 'query' , 'xojixjoiwejhfoiuwehjfioweufhj' )
121
121
const res = await get ( '/api/search/v1?' + sp )
122
122
expect ( res . statusCode ) . toBe ( 200 )
123
- const results = JSON . parse ( res . text )
123
+ const results = JSON . parse ( res . body )
124
124
expect ( results . hits . length ) . toBe ( 0 )
125
125
expect ( results . meta . found . value ) . toBe ( 0 )
126
126
} )
@@ -132,7 +132,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
132
132
sp . append ( 'highlights' , 'content' )
133
133
const res = await get ( '/api/search/v1?' + sp )
134
134
expect ( res . statusCode ) . toBe ( 200 )
135
- const results = JSON . parse ( res . text )
135
+ const results = JSON . parse ( res . body )
136
136
expect ( results . meta . found . value ) . toBeGreaterThanOrEqual ( 1 )
137
137
for ( const hit of results . hits ) {
138
138
expect ( hit . highlights . title ) . toBeFalsy ( )
@@ -148,7 +148,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
148
148
sp . set ( 'highlights' , 'headings' )
149
149
const res = await get ( '/api/search/v1?' + sp )
150
150
expect ( res . statusCode ) . toBe ( 200 )
151
- const results = JSON . parse ( res . text )
151
+ const results = JSON . parse ( res . body )
152
152
expect ( results . meta . found . value ) . toBeGreaterThanOrEqual ( 1 )
153
153
for ( const hit of results . hits ) {
154
154
expect ( hit . highlights . headings ) . toBeTruthy ( )
@@ -163,12 +163,12 @@ describeIfElasticsearchURL('search v1 middleware', () => {
163
163
sp . set ( 'version' , 'dotcom' )
164
164
const res1 = await get ( '/api/search/v1?' + sp )
165
165
expect ( res1 . statusCode ) . toBe ( 200 )
166
- const results1 = JSON . parse ( res1 . text )
166
+ const results1 = JSON . parse ( res1 . body )
167
167
168
168
sp . set ( 'version' , 'free-pro-team@latest' )
169
169
const res2 = await get ( '/api/search/v1?' + sp )
170
170
expect ( res2 . statusCode ) . toBe ( 200 )
171
- const results2 = JSON . parse ( res2 . text )
171
+ const results2 = JSON . parse ( res2 . body )
172
172
expect ( results1 . hits [ 0 ] . id ) . toBe ( results2 . hits [ 0 ] . id )
173
173
} )
174
174
@@ -177,15 +177,15 @@ describeIfElasticsearchURL('search v1 middleware', () => {
177
177
{
178
178
const res = await get ( '/api/search/v1' )
179
179
expect ( res . statusCode ) . toBe ( 400 )
180
- expect ( JSON . parse ( res . text ) . error ) . toBeTruthy ( )
180
+ expect ( JSON . parse ( res . body ) . error ) . toBeTruthy ( )
181
181
}
182
182
// query is just whitespace
183
183
{
184
184
const sp = new URLSearchParams ( )
185
185
sp . set ( 'query' , ' ' )
186
186
const res = await get ( '/api/search/v1?' + sp )
187
187
expect ( res . statusCode ) . toBe ( 400 )
188
- expect ( JSON . parse ( res . text ) . error ) . toBeTruthy ( )
188
+ expect ( JSON . parse ( res . body ) . error ) . toBeTruthy ( )
189
189
}
190
190
// unrecognized language
191
191
{
@@ -194,7 +194,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
194
194
sp . set ( 'language' , 'xxx' )
195
195
const res = await get ( '/api/search/v1?' + sp )
196
196
expect ( res . statusCode ) . toBe ( 400 )
197
- expect ( JSON . parse ( res . text ) . error ) . toMatch ( 'language' )
197
+ expect ( JSON . parse ( res . body ) . error ) . toMatch ( 'language' )
198
198
}
199
199
// unrecognized page
200
200
{
@@ -203,7 +203,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
203
203
sp . set ( 'page' , '9999' )
204
204
const res = await get ( '/api/search/v1?' + sp )
205
205
expect ( res . statusCode ) . toBe ( 400 )
206
- expect ( JSON . parse ( res . text ) . error ) . toMatch ( 'page' )
206
+ expect ( JSON . parse ( res . body ) . error ) . toMatch ( 'page' )
207
207
}
208
208
// unrecognized version
209
209
{
@@ -212,8 +212,8 @@ describeIfElasticsearchURL('search v1 middleware', () => {
212
212
sp . set ( 'version' , 'xxxxx' )
213
213
const res = await get ( '/api/search/v1?' + sp )
214
214
expect ( res . statusCode ) . toBe ( 400 )
215
- expect ( JSON . parse ( res . text ) . error ) . toMatch ( "'xxxxx'" )
216
- expect ( JSON . parse ( res . text ) . field ) . toMatch ( 'version' )
215
+ expect ( JSON . parse ( res . body ) . error ) . toMatch ( "'xxxxx'" )
216
+ expect ( JSON . parse ( res . body ) . field ) . toMatch ( 'version' )
217
217
}
218
218
// unrecognized size
219
219
{
@@ -222,7 +222,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
222
222
sp . set ( 'size' , 'not a number' )
223
223
const res = await get ( '/api/search/v1?' + sp )
224
224
expect ( res . statusCode ) . toBe ( 400 )
225
- expect ( JSON . parse ( res . text ) . error ) . toMatch ( 'size' )
225
+ expect ( JSON . parse ( res . body ) . error ) . toMatch ( 'size' )
226
226
}
227
227
// unrecognized sort
228
228
{
@@ -231,7 +231,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
231
231
sp . set ( 'sort' , 'neverheardof' )
232
232
const res = await get ( '/api/search/v1?' + sp )
233
233
expect ( res . statusCode ) . toBe ( 400 )
234
- expect ( JSON . parse ( res . text ) . error ) . toMatch ( 'sort' )
234
+ expect ( JSON . parse ( res . body ) . error ) . toMatch ( 'sort' )
235
235
}
236
236
// unrecognized highlights
237
237
{
@@ -240,7 +240,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
240
240
sp . set ( 'highlights' , 'neverheardof' )
241
241
const res = await get ( '/api/search/v1?' + sp )
242
242
expect ( res . statusCode ) . toBe ( 400 )
243
- expect ( JSON . parse ( res . text ) . error ) . toMatch ( 'neverheardof' )
243
+ expect ( JSON . parse ( res . body ) . error ) . toMatch ( 'neverheardof' )
244
244
}
245
245
} )
246
246
@@ -249,7 +249,7 @@ describeIfElasticsearchURL('search v1 middleware', () => {
249
249
sp . set ( 'query' , 'breadcrumbs' )
250
250
const res = await get ( '/api/search/v1?' + sp )
251
251
expect ( res . statusCode ) . toBe ( 200 )
252
- const results = JSON . parse ( res . text )
252
+ const results = JSON . parse ( res . body )
253
253
// safe because we know exactly the fixtures
254
254
const hit = results . hits [ 0 ]
255
255
expect ( hit . breadcrumbs ) . toBe ( '' )
@@ -264,7 +264,7 @@ describeIfElasticsearchURL("additional fields with 'include'", () => {
264
264
sp . set ( 'query' , 'foo' )
265
265
const res = await get ( '/api/search/v1?' + sp )
266
266
expect ( res . statusCode ) . toBe ( 200 )
267
- const results = JSON . parse ( res . text )
267
+ const results = JSON . parse ( res . body )
268
268
const firstKeys = Object . keys ( results . hits [ 0 ] )
269
269
expect ( firstKeys . includes ( 'intro' ) ) . toBeFalsy ( )
270
270
expect ( firstKeys . includes ( 'headings' ) ) . toBeFalsy ( )
@@ -276,7 +276,7 @@ describeIfElasticsearchURL("additional fields with 'include'", () => {
276
276
sp . set ( 'include' , 'intro' )
277
277
const res = await get ( '/api/search/v1?' + sp )
278
278
expect ( res . statusCode ) . toBe ( 200 )
279
- const results = JSON . parse ( res . text )
279
+ const results = JSON . parse ( res . body )
280
280
const firstKeys = Object . keys ( results . hits [ 0 ] )
281
281
expect ( firstKeys . includes ( 'intro' ) ) . toBeTruthy ( )
282
282
expect ( firstKeys . includes ( 'headings' ) ) . toBeFalsy ( )
@@ -289,7 +289,7 @@ describeIfElasticsearchURL("additional fields with 'include'", () => {
289
289
sp . append ( 'include' , 'headings' )
290
290
const res = await get ( '/api/search/v1?' + sp )
291
291
expect ( res . statusCode ) . toBe ( 200 )
292
- const results = JSON . parse ( res . text )
292
+ const results = JSON . parse ( res . body )
293
293
const firstKeys = Object . keys ( results . hits [ 0 ] )
294
294
expect ( firstKeys . includes ( 'intro' ) ) . toBeTruthy ( )
295
295
expect ( firstKeys . includes ( 'headings' ) ) . toBeTruthy ( )
@@ -301,7 +301,7 @@ describeIfElasticsearchURL("additional fields with 'include'", () => {
301
301
sp . set ( 'include' , 'xxxxx' )
302
302
const res = await get ( '/api/search/v1?' + sp )
303
303
expect ( res . statusCode ) . toBe ( 400 )
304
- const results = JSON . parse ( res . text )
304
+ const results = JSON . parse ( res . body )
305
305
expect ( results . error ) . toMatch ( `Not a valid value (["xxxxx"]) for key 'include'` )
306
306
} )
307
307
} )
0 commit comments