MCPcopy
hub / github.com/pocketbase/pocketbase / TestProviderExecNonEmptyQuery

Function TestProviderExecNonEmptyQuery

tools/search/provider_test.go:272–472  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

270}
271
272func TestProviderExecNonEmptyQuery(t *testing.T) {
273 testDB, err := createTestDB()
274 if err != nil {
275 t.Fatal(err)
276 }
277 defer testDB.Close()
278
279 query := testDB.Select("*").
280 From("test").
281 Where(dbx.Not(dbx.HashExp{"test1": nil})).
282 OrderBy("test1 ASC")
283
284 scenarios := []struct {
285 name string
286 page int
287 perPage int
288 sort []SortField
289 filter []FilterData
290 skipTotal bool
291 expectError bool
292 expectResult string
293 expectQueries []string
294 }{
295 {
296 "page normalization",
297 -1,
298 10,
299 []SortField{},
300 []FilterData{},
301 false,
302 false,
303 `{"items":[{"test1":1,"test2":"test2.1","test3":""},{"test1":2,"test2":"test2.2","test3":""}],"page":1,"perPage":10,"totalItems":2,"totalPages":1}`,
304 []string{
305 "SELECT COUNT(DISTINCT [[test.id]]) FROM `test` WHERE NOT (`test1` IS NULL)",
306 "SELECT * FROM `test` WHERE NOT (`test1` IS NULL) ORDER BY `test1` ASC LIMIT 10",
307 },
308 },
309 {
310 "perPage normalization",
311 10,
312 0, // fallback to default
313 []SortField{},
314 []FilterData{},
315 false,
316 false,
317 `{"items":[],"page":10,"perPage":30,"totalItems":2,"totalPages":1}`,
318 []string{
319 "SELECT COUNT(DISTINCT [[test.id]]) FROM `test` WHERE NOT (`test1` IS NULL)",
320 "SELECT * FROM `test` WHERE NOT (`test1` IS NULL) ORDER BY `test1` ASC LIMIT 30 OFFSET 270",
321 },
322 },
323 {
324 "invalid sort field",
325 1,
326 10,
327 []SortField{{"unknown", SortAsc}},
328 []FilterData{},
329 false,

Callers

nothing calls this directly

Calls 13

ExistInSliceWithRegexFunction · 0.92
createTestDBFunction · 0.85
NewProviderFunction · 0.85
SelectMethod · 0.80
FilterMethod · 0.80
SkipTotalMethod · 0.80
SortMethod · 0.80
PerPageMethod · 0.80
PageMethod · 0.80
QueryMethod · 0.80
ExecMethod · 0.80
CloseMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…