Merge pull request #13948 from Budibase/uncomment-search-test-todos
Solve all remaining TODOs in search.spec.ts.
This commit is contained in:
commit
572bc6fbe1
|
@ -596,6 +596,9 @@ class InternalBuilder {
|
||||||
const offset = page * paginate.limit
|
const offset = page * paginate.limit
|
||||||
foundLimit = paginate.limit
|
foundLimit = paginate.limit
|
||||||
foundOffset = offset
|
foundOffset = offset
|
||||||
|
} else if (paginate && paginate.offset && paginate.limit) {
|
||||||
|
foundLimit = paginate.limit
|
||||||
|
foundOffset = paginate.offset
|
||||||
} else if (paginate && paginate.limit) {
|
} else if (paginate && paginate.limit) {
|
||||||
foundLimit = paginate.limit
|
foundLimit = paginate.limit
|
||||||
}
|
}
|
||||||
|
|
|
@ -512,75 +512,63 @@ describe.each([
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO(samwho): fix for SQS
|
it("should match the session user id in a multi user field", async () => {
|
||||||
!isSqs &&
|
const allUsers = [...globalUsers, config.getUser()].map((user: any) => {
|
||||||
it("should match the session user id in a multi user field", async () => {
|
return { _id: user._id }
|
||||||
const allUsers = [...globalUsers, config.getUser()].map(
|
})
|
||||||
(user: any) => {
|
|
||||||
|
await expectQuery({
|
||||||
|
contains: { multi_user: ["{{ [user]._id }}"] },
|
||||||
|
}).toContainExactly([
|
||||||
|
{
|
||||||
|
name: "multi user with session user",
|
||||||
|
multi_user: allUsers,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should match the session user id in a deprecated multi user field", async () => {
|
||||||
|
const allUsers = [...globalUsers, config.getUser()].map((user: any) => {
|
||||||
|
return { _id: user._id }
|
||||||
|
})
|
||||||
|
|
||||||
|
await expectQuery({
|
||||||
|
contains: { deprecated_multi_user: ["{{ [user]._id }}"] },
|
||||||
|
}).toContainExactly([
|
||||||
|
{
|
||||||
|
name: "deprecated multi user with session user",
|
||||||
|
deprecated_multi_user: allUsers,
|
||||||
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
|
it("should not match the session user id in a multi user field", async () => {
|
||||||
|
await expectQuery({
|
||||||
|
notContains: { multi_user: ["{{ [user]._id }}"] },
|
||||||
|
notEmpty: { multi_user: true },
|
||||||
|
}).toContainExactly([
|
||||||
|
{
|
||||||
|
name: "multi user",
|
||||||
|
multi_user: globalUsers.map((user: any) => {
|
||||||
return { _id: user._id }
|
return { _id: user._id }
|
||||||
}
|
}),
|
||||||
)
|
},
|
||||||
|
])
|
||||||
|
})
|
||||||
|
|
||||||
await expectQuery({
|
it("should not match the session user id in a deprecated multi user field", async () => {
|
||||||
contains: { multi_user: ["{{ [user]._id }}"] },
|
await expectQuery({
|
||||||
}).toContainExactly([
|
notContains: { deprecated_multi_user: ["{{ [user]._id }}"] },
|
||||||
{
|
notEmpty: { deprecated_multi_user: true },
|
||||||
name: "multi user with session user",
|
}).toContainExactly([
|
||||||
multi_user: allUsers,
|
{
|
||||||
},
|
name: "deprecated multi user",
|
||||||
])
|
deprecated_multi_user: globalUsers.map((user: any) => {
|
||||||
})
|
|
||||||
|
|
||||||
// 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) => {
|
|
||||||
return { _id: user._id }
|
return { _id: user._id }
|
||||||
}
|
}),
|
||||||
)
|
},
|
||||||
|
])
|
||||||
await expectQuery({
|
})
|
||||||
contains: { deprecated_multi_user: ["{{ [user]._id }}"] },
|
|
||||||
}).toContainExactly([
|
|
||||||
{
|
|
||||||
name: "deprecated multi user with session user",
|
|
||||||
deprecated_multi_user: allUsers,
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
// 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 }}"] },
|
|
||||||
notEmpty: { multi_user: true },
|
|
||||||
}).toContainExactly([
|
|
||||||
{
|
|
||||||
name: "multi user",
|
|
||||||
multi_user: globalUsers.map((user: any) => {
|
|
||||||
return { _id: user._id }
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
// 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 }}"] },
|
|
||||||
notEmpty: { deprecated_multi_user: true },
|
|
||||||
}).toContainExactly([
|
|
||||||
{
|
|
||||||
name: "deprecated multi user",
|
|
||||||
deprecated_multi_user: globalUsers.map((user: any) => {
|
|
||||||
return { _id: user._id }
|
|
||||||
}),
|
|
||||||
},
|
|
||||||
])
|
|
||||||
})
|
|
||||||
|
|
||||||
it("should match the session user id and a user table row id using helpers, user binding and a static user id.", async () => {
|
it("should match the session user id and a user table row id using helpers, user binding and a static user id.", async () => {
|
||||||
await expectQuery({
|
await expectQuery({
|
||||||
|
@ -1552,38 +1540,34 @@ describe.each([
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO(samwho): fix for SQS
|
describe("pagination", () => {
|
||||||
!isSqs &&
|
it("should paginate through all rows", async () => {
|
||||||
describe("pagination", () => {
|
// @ts-ignore
|
||||||
it("should paginate through all rows", async () => {
|
let bookmark: string | number = undefined
|
||||||
// @ts-ignore
|
let rows: Row[] = []
|
||||||
let bookmark: string | number = undefined
|
|
||||||
let rows: Row[] = []
|
|
||||||
|
|
||||||
// eslint-disable-next-line no-constant-condition
|
// eslint-disable-next-line no-constant-condition
|
||||||
while (true) {
|
while (true) {
|
||||||
const response = await config.api.row.search(table._id!, {
|
const response = await config.api.row.search(table._id!, {
|
||||||
tableId: table._id!,
|
tableId: table._id!,
|
||||||
limit: 3,
|
limit: 3,
|
||||||
query: {},
|
query: {},
|
||||||
bookmark,
|
bookmark,
|
||||||
paginate: true,
|
paginate: true,
|
||||||
})
|
})
|
||||||
|
|
||||||
rows.push(...response.rows)
|
rows.push(...response.rows)
|
||||||
|
|
||||||
if (!response.bookmark || !response.hasNextPage) {
|
if (!response.bookmark || !response.hasNextPage) {
|
||||||
break
|
break
|
||||||
}
|
|
||||||
bookmark = response.bookmark
|
|
||||||
}
|
}
|
||||||
|
bookmark = response.bookmark
|
||||||
|
}
|
||||||
|
|
||||||
expect(rows).toHaveLength(10)
|
const autoValues = rows.map(row => row.auto).sort((a, b) => a - b)
|
||||||
expect(rows.map(row => row.auto)).toEqual(
|
expect(autoValues).toEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
||||||
expect.arrayContaining([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
|
|
||||||
)
|
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("field name 1:name", () => {
|
describe("field name 1:name", () => {
|
||||||
|
|
|
@ -167,13 +167,9 @@ export async function search(
|
||||||
const sortField = table.schema[params.sort]
|
const sortField = table.schema[params.sort]
|
||||||
const sortType =
|
const sortType =
|
||||||
sortField.type === FieldType.NUMBER ? SortType.NUMBER : SortType.STRING
|
sortField.type === FieldType.NUMBER ? SortType.NUMBER : SortType.STRING
|
||||||
const sortDirection =
|
|
||||||
params.sortOrder === SortOrder.ASCENDING
|
|
||||||
? SortOrder.ASCENDING
|
|
||||||
: SortOrder.DESCENDING
|
|
||||||
request.sort = {
|
request.sort = {
|
||||||
[sortField.name]: {
|
[sortField.name]: {
|
||||||
direction: sortDirection,
|
direction: params.sortOrder || SortOrder.DESCENDING,
|
||||||
type: sortType as SortType,
|
type: sortType as SortType,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -182,14 +178,15 @@ export async function search(
|
||||||
if (params.bookmark && typeof params.bookmark !== "number") {
|
if (params.bookmark && typeof params.bookmark !== "number") {
|
||||||
throw new Error("Unable to paginate with string based bookmarks")
|
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) {
|
if (paginate && params.limit) {
|
||||||
request.paginate = {
|
request.paginate = {
|
||||||
limit: params.limit + 1,
|
limit: params.limit + 1,
|
||||||
page: bookmark,
|
offset: bookmark * params.limit,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const rows = await runSqlQuery(request, allTables)
|
const rows = await runSqlQuery(request, allTables)
|
||||||
|
|
||||||
|
@ -221,18 +218,12 @@ export async function search(
|
||||||
}
|
}
|
||||||
|
|
||||||
// check for pagination
|
// check for pagination
|
||||||
if (paginate && limit) {
|
if (paginate) {
|
||||||
const response: SearchResponse<Row> = {
|
const response: SearchResponse<Row> = {
|
||||||
rows: finalRows,
|
rows: finalRows,
|
||||||
}
|
}
|
||||||
const prevLimit = request.paginate!.limit
|
if (nextRow) {
|
||||||
request.paginate = {
|
response.hasNextPage = true
|
||||||
limit: 1,
|
|
||||||
page: bookmark * prevLimit + 1,
|
|
||||||
}
|
|
||||||
const hasNextPage = !!nextRow
|
|
||||||
response.hasNextPage = hasNextPage
|
|
||||||
if (hasNextPage) {
|
|
||||||
response.bookmark = bookmark + 1
|
response.bookmark = bookmark + 1
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
|
|
|
@ -85,6 +85,7 @@ export interface SortJson {
|
||||||
export interface PaginationJson {
|
export interface PaginationJson {
|
||||||
limit: number
|
limit: number
|
||||||
page?: string | number
|
page?: string | number
|
||||||
|
offset?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface RenameColumn {
|
export interface RenameColumn {
|
||||||
|
|
Loading…
Reference in New Issue