Fixing view test cases, adding SQS to it and correcting the default sort order.

This commit is contained in:
mike12345567 2024-06-19 18:57:37 +01:00
parent 67c00c9e4c
commit 86d9de5a2d
2 changed files with 31 additions and 12 deletions

View File

@ -7,6 +7,7 @@ import {
INTERNAL_TABLE_SOURCE_ID,
PermissionLevel,
QuotaUsageType,
Row,
SaveTableRequest,
SearchFilterOperator,
SortOrder,
@ -17,6 +18,7 @@ import {
UpdateViewRequest,
ViewUIFieldMetadata,
ViewV2,
SearchResponse,
} from "@budibase/types"
import { generator, mocks } from "@budibase/backend-core/tests"
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
@ -25,17 +27,21 @@ import { quotas } from "@budibase/pro"
import { db, roles } from "@budibase/backend-core"
describe.each([
["internal", undefined],
["lucene", undefined],
["sqs", undefined],
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
])("/v2/views (%s)", (_, dsProvider) => {
])("/v2/views (%s)", (name, dsProvider) => {
const config = setup.getConfig()
const isInternal = !dsProvider
const isSqs = name === "sqs"
const isLucene = name === "lucene"
const isInternal = isSqs || isLucene
let table: Table
let datasource: Datasource
let envCleanup: (() => void) | undefined
function saveTableRequest(
...overrides: Partial<Omit<SaveTableRequest, "name">>[]
@ -82,6 +88,9 @@ describe.each([
}
beforeAll(async () => {
if (isSqs) {
envCleanup = config.setEnv({ SQS_SEARCH_ENABLE: "true" })
}
await config.init()
if (dsProvider) {
@ -94,6 +103,9 @@ describe.each([
afterAll(async () => {
setup.afterAll()
if (envCleanup) {
envCleanup()
}
})
beforeEach(() => {
@ -1252,12 +1264,13 @@ describe.each([
paginate: true,
limit: 4,
query: {},
countRows: true,
})
expect(page1).toEqual({
rows: expect.arrayContaining(rows.slice(0, 4)),
totalRows: isInternal ? 10 : undefined,
hasNextPage: true,
bookmark: expect.anything(),
totalRows: 10,
})
const page2 = await config.api.viewV2.search(view.id, {
@ -1265,12 +1278,13 @@ describe.each([
limit: 4,
bookmark: page1.bookmark,
query: {},
countRows: true,
})
expect(page2).toEqual({
rows: expect.arrayContaining(rows.slice(4, 8)),
totalRows: isInternal ? 10 : undefined,
hasNextPage: true,
bookmark: expect.anything(),
totalRows: 10,
})
const page3 = await config.api.viewV2.search(view.id, {
@ -1278,13 +1292,17 @@ describe.each([
limit: 4,
bookmark: page2.bookmark,
query: {},
countRows: true,
})
expect(page3).toEqual({
const expectation: SearchResponse<Row> = {
rows: expect.arrayContaining(rows.slice(8)),
totalRows: isInternal ? 10 : undefined,
hasNextPage: false,
bookmark: expect.anything(),
})
totalRows: 10,
}
if (isLucene) {
expectation.bookmark = expect.anything()
}
expect(page3).toEqual(expectation)
})
const sortTestOptions: [

View File

@ -154,7 +154,7 @@ export async function search(
options: RowSearchParams,
table: Table
): Promise<SearchResponse<Row>> {
const { paginate, query, ...params } = options
let { paginate, query, ...params } = options
const allTables = await sdk.tables.getAllInternalTables()
const allTablesMap = buildTableMap(allTables)
@ -196,7 +196,7 @@ export async function search(
sortField.type === FieldType.NUMBER ? SortType.NUMBER : SortType.STRING
request.sort = {
[sortField.name]: {
direction: params.sortOrder || SortOrder.DESCENDING,
direction: params.sortOrder || SortOrder.ASCENDING,
type: sortType as SortType,
},
}
@ -207,7 +207,8 @@ export async function search(
}
const bookmark: number = (params.bookmark as number) || 0
if (paginate && params.limit) {
if (params.limit) {
paginate = true
request.paginate = {
limit: params.limit + 1,
offset: bookmark * params.limit,