@@ -44,7 +44,7 @@ describe('createSearchQuery', () => {
44
44
expect ( query ) . toMatchInlineSnapshot (
45
45
`
46
46
"// findability-mvi:5
47
- *[_type in $__types && !(_id in path("versions.**")) ] | score(boost(_type in ["basic-schema-test"] && title match text::query($__query), 10), [@, _id] match text::query($__query)) | order(_score desc) [_score > 0] [0...$__limit] {_score, _type, _id, _originalId}"
47
+ *[_type in $__types] | score(boost(_type in ["basic-schema-test"] && title match text::query($__query), 10), [@, _id] match text::query($__query)) | order(_score desc) [_score > 0] [0...$__limit] {_score, _type, _id, _originalId}"
48
48
` ,
49
49
)
50
50
@@ -58,19 +58,20 @@ describe('createSearchQuery', () => {
58
58
59
59
describe ( 'searchOptions' , ( ) => {
60
60
it ( 'should include drafts by default' , ( ) => {
61
- const { options} = createSearchQuery (
61
+ const { query , options} = createSearchQuery (
62
62
{
63
63
query : 'term0' ,
64
64
types : [ testType ] ,
65
65
} ,
66
66
'' ,
67
67
)
68
68
69
- expect ( options . perspective ) . toBe ( 'previewDrafts' )
69
+ expect ( query ) . not . toMatch ( `!(_id in path('drafts.**'))` )
70
+ expect ( options . perspective ) . toBe ( 'raw' )
70
71
} )
71
72
72
73
it ( 'should exclude drafts when configured' , ( ) => {
73
- const { options} = createSearchQuery (
74
+ const { query , options} = createSearchQuery (
74
75
{
75
76
query : 'term0' ,
76
77
types : [ testType ] ,
@@ -79,50 +80,33 @@ describe('createSearchQuery', () => {
79
80
{ includeDrafts : false } ,
80
81
)
81
82
82
- expect ( options . perspective ) . toBe ( 'published' )
83
+ expect ( query ) . toMatch ( `!(_id in path('drafts.**'))` )
84
+ expect ( options . perspective ) . toBe ( 'raw' )
83
85
} )
84
86
85
- it ( 'should give `perspective` precedence over `includeDrafts`' , ( ) => {
86
- const { options : optionsIncludeDrafts } = createSearchQuery (
87
- {
88
- query : 'term0' ,
89
- types : [ testType ] ,
90
- } ,
91
- '' ,
92
- {
93
- includeDrafts : true ,
94
- perspective : 'published' ,
95
- } ,
96
- )
97
-
98
- expect ( optionsIncludeDrafts . perspective ) . toBe ( 'published' )
99
-
100
- const { options : optionsExcludeDrafts } = createSearchQuery (
87
+ it ( 'should use `raw` perspective when no perspective provided' , ( ) => {
88
+ const { options} = createSearchQuery (
101
89
{
102
90
query : 'term0' ,
103
91
types : [ testType ] ,
104
92
} ,
105
93
'' ,
106
- {
107
- includeDrafts : false ,
108
- perspective : 'drafts' ,
109
- } ,
110
94
)
111
95
112
- expect ( optionsExcludeDrafts . perspective ) . toBe ( 'drafts ' )
96
+ expect ( options . perspective ) . toBe ( 'raw ' )
113
97
} )
114
98
115
- it ( 'should add no perspective parameter when `raw` perspective provided' , ( ) => {
99
+ it ( 'should use `raw` perspective when empty perspective array provided' , ( ) => {
116
100
const { options} = createSearchQuery (
117
101
{
118
102
query : 'term0' ,
119
103
types : [ testType ] ,
120
104
} ,
121
105
'' ,
122
- { perspective : 'raw' } ,
106
+ { perspective : [ ] } ,
123
107
)
124
108
125
- expect ( options . perspective ) . toBeUndefined ( )
109
+ expect ( options . perspective ) . toBe ( 'raw' )
126
110
} )
127
111
128
112
it ( 'should use provided limit (plus one to determine existence of next page)' , ( ) => {
@@ -150,9 +134,7 @@ describe('createSearchQuery', () => {
150
134
{ filter : 'randomCondition == $customParam' , params : { customParam : 'custom' } } ,
151
135
)
152
136
153
- expect ( query ) . toContain (
154
- '*[_type in $__types && (randomCondition == $customParam) && !(_id in path("versions.**"))]' ,
155
- )
137
+ expect ( query ) . toContain ( '*[_type in $__types && (randomCondition == $customParam)]' )
156
138
expect ( params . customParam ) . toEqual ( 'custom' )
157
139
} )
158
140
@@ -188,7 +170,7 @@ describe('createSearchQuery', () => {
188
170
189
171
expect ( query ) . toMatchInlineSnapshot ( `
190
172
"// findability-mvi:5
191
- *[_type in $__types && [@, _id] match text::query($__query) && !(_id in path("versions.**")) ] | order(exampleField desc) [0...$__limit] {exampleField, _type, _id, _originalId}"
173
+ *[_type in $__types && [@, _id] match text::query($__query)] | order(exampleField desc) [0...$__limit] {exampleField, _type, _id, _originalId}"
192
174
` )
193
175
194
176
expect ( query ) . toContain ( '| order(exampleField desc)' )
@@ -222,7 +204,7 @@ describe('createSearchQuery', () => {
222
204
223
205
expect ( query ) . toMatchInlineSnapshot ( `
224
206
"// findability-mvi:5
225
- *[_type in $__types && [@, _id] match text::query($__query) && !(_id in path("versions.**")) ] | order(exampleField desc,anotherExampleField asc,lower(mapWithField) asc) [0...$__limit] {exampleField, anotherExampleField, mapWithField, _type, _id, _originalId}"
207
+ *[_type in $__types && [@, _id] match text::query($__query)] | order(exampleField desc,anotherExampleField asc,lower(mapWithField) asc) [0...$__limit] {exampleField, anotherExampleField, mapWithField, _type, _id, _originalId}"
226
208
` )
227
209
228
210
expect ( query ) . toContain (
@@ -241,7 +223,7 @@ describe('createSearchQuery', () => {
241
223
242
224
expect ( query ) . toMatchInlineSnapshot ( `
243
225
"// findability-mvi:5
244
- *[_type in $__types && !(_id in path("versions.**")) ] | score(boost(_type in ["basic-schema-test"] && title match text::query($__query), 10), [@, _id] match text::query($__query)) | order(_score desc) [_score > 0] [0...$__limit] {_score, _type, _id, _originalId}"
226
+ *[_type in $__types] | score(boost(_type in ["basic-schema-test"] && title match text::query($__query), 10), [@, _id] match text::query($__query)) | order(_score desc) [_score > 0] [0...$__limit] {_score, _type, _id, _originalId}"
245
227
` )
246
228
247
229
expect ( query ) . toContain ( '| order(_score desc)' )
@@ -319,7 +301,7 @@ describe('createSearchQuery', () => {
319
301
320
302
expect ( query ) . toMatchInlineSnapshot ( `
321
303
"// findability-mvi:5
322
- *[_type in $__types && !(_id in path("versions.**")) ] | score(boost(_type in ["numbers-in-path"] && cover[].cards[].title match text::query($__query), 5), [@, _id] match text::query($__query)) | order(_score desc) [_score > 0] [0...$__limit] {_score, _type, _id, _originalId}"
304
+ *[_type in $__types] | score(boost(_type in ["numbers-in-path"] && cover[].cards[].title match text::query($__query), 5), [@, _id] match text::query($__query)) | order(_score desc) [_score > 0] [0...$__limit] {_score, _type, _id, _originalId}"
323
305
` )
324
306
325
307
expect ( query ) . toContain ( 'cover[].cards[].title match text::query($__query), 5)' )
0 commit comments