1
0
Fork 0
mirror of synced 2024-08-05 05:11:43 +12:00

Solve all remaining TODOs in search.spec.ts.

This commit is contained in:
Sam Rose 2024-06-14 14:57:31 +01:00
parent c6a7bf6ed1
commit a54048e308
No known key found for this signature in database
4 changed files with 88 additions and 109 deletions

View file

@ -596,6 +596,9 @@ class InternalBuilder {
const offset = page * paginate.limit
foundLimit = paginate.limit
foundOffset = offset
} else if (paginate && paginate.offset && paginate.limit) {
foundLimit = paginate.limit
foundOffset = paginate.offset
} else if (paginate && paginate.limit) {
foundLimit = paginate.limit
}

View file

@ -512,14 +512,10 @@ describe.each([
])
})
// TODO(samwho): fix for SQS
!isSqs &&
it("should match the session user id in a multi user field", async () => {
const allUsers = [...globalUsers, config.getUser()].map(
(user: any) => {
const allUsers = [...globalUsers, config.getUser()].map((user: any) => {
return { _id: user._id }
}
)
})
await expectQuery({
contains: { multi_user: ["{{ [user]._id }}"] },
@ -531,14 +527,10 @@ describe.each([
])
})
// TODO(samwho): fix for SQS
!isSqs &&
it("should match the session user id in a deprecated multi user field", async () => {
const allUsers = [...globalUsers, config.getUser()].map(
(user: any) => {
const allUsers = [...globalUsers, config.getUser()].map((user: any) => {
return { _id: user._id }
}
)
})
await expectQuery({
contains: { deprecated_multi_user: ["{{ [user]._id }}"] },
@ -550,8 +542,6 @@ describe.each([
])
})
// TODO(samwho): fix for SQS
!isSqs &&
it("should not match the session user id in a multi user field", async () => {
await expectQuery({
notContains: { multi_user: ["{{ [user]._id }}"] },
@ -566,8 +556,6 @@ describe.each([
])
})
// TODO(samwho): fix for SQS
!isSqs &&
it("should not match the session user id in a deprecated multi user field", async () => {
await expectQuery({
notContains: { deprecated_multi_user: ["{{ [user]._id }}"] },
@ -1552,8 +1540,6 @@ describe.each([
})
})
// TODO(samwho): fix for SQS
!isSqs &&
describe("pagination", () => {
it("should paginate through all rows", async () => {
// @ts-ignore
@ -1578,10 +1564,8 @@ describe.each([
bookmark = response.bookmark
}
expect(rows).toHaveLength(10)
expect(rows.map(row => row.auto)).toEqual(
expect.arrayContaining([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
)
const autoValues = rows.map(row => row.auto).sort((a, b) => a - b)
expect(autoValues).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
})
})
})

View file

@ -167,13 +167,9 @@ export async function search(
const sortField = table.schema[params.sort]
const sortType =
sortField.type === FieldType.NUMBER ? SortType.NUMBER : SortType.STRING
const sortDirection =
params.sortOrder === SortOrder.ASCENDING
? SortOrder.ASCENDING
: SortOrder.DESCENDING
request.sort = {
[sortField.name]: {
direction: sortDirection,
direction: params.sortOrder || SortOrder.DESCENDING,
type: sortType as SortType,
},
}
@ -182,14 +178,15 @@ export async function search(
if (params.bookmark && typeof params.bookmark !== "number") {
throw new Error("Unable to paginate with string based bookmarks")
}
const bookmark: number = (params.bookmark as number) || 1
const limit = params.limit
const bookmark: number = (params.bookmark as number) || 0
if (paginate && params.limit) {
request.paginate = {
limit: params.limit + 1,
page: bookmark,
offset: bookmark * params.limit,
}
}
try {
const rows = await runSqlQuery(request, allTables)
@ -221,18 +218,12 @@ export async function search(
}
// check for pagination
if (paginate && limit) {
if (paginate) {
const response: SearchResponse<Row> = {
rows: finalRows,
}
const prevLimit = request.paginate!.limit
request.paginate = {
limit: 1,
page: bookmark * prevLimit + 1,
}
const hasNextPage = !!nextRow
response.hasNextPage = hasNextPage
if (hasNextPage) {
if (nextRow) {
response.hasNextPage = true
response.bookmark = bookmark + 1
}
return response

View file

@ -85,6 +85,7 @@ export interface SortJson {
export interface PaginationJson {
limit: number
page?: string | number
offset?: number
}
export interface RenameColumn {