Fixing view test cases, adding SQS to it and correcting the default sort order.
This commit is contained in:
parent
67c00c9e4c
commit
86d9de5a2d
|
@ -7,6 +7,7 @@ import {
|
||||||
INTERNAL_TABLE_SOURCE_ID,
|
INTERNAL_TABLE_SOURCE_ID,
|
||||||
PermissionLevel,
|
PermissionLevel,
|
||||||
QuotaUsageType,
|
QuotaUsageType,
|
||||||
|
Row,
|
||||||
SaveTableRequest,
|
SaveTableRequest,
|
||||||
SearchFilterOperator,
|
SearchFilterOperator,
|
||||||
SortOrder,
|
SortOrder,
|
||||||
|
@ -17,6 +18,7 @@ import {
|
||||||
UpdateViewRequest,
|
UpdateViewRequest,
|
||||||
ViewUIFieldMetadata,
|
ViewUIFieldMetadata,
|
||||||
ViewV2,
|
ViewV2,
|
||||||
|
SearchResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { generator, mocks } from "@budibase/backend-core/tests"
|
import { generator, mocks } from "@budibase/backend-core/tests"
|
||||||
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
import { DatabaseName, getDatasource } from "../../../integrations/tests/utils"
|
||||||
|
@ -25,17 +27,21 @@ import { quotas } from "@budibase/pro"
|
||||||
import { db, roles } from "@budibase/backend-core"
|
import { db, roles } from "@budibase/backend-core"
|
||||||
|
|
||||||
describe.each([
|
describe.each([
|
||||||
["internal", undefined],
|
["lucene", undefined],
|
||||||
|
["sqs", undefined],
|
||||||
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
|
[DatabaseName.POSTGRES, getDatasource(DatabaseName.POSTGRES)],
|
||||||
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
[DatabaseName.MYSQL, getDatasource(DatabaseName.MYSQL)],
|
||||||
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
[DatabaseName.SQL_SERVER, getDatasource(DatabaseName.SQL_SERVER)],
|
||||||
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
[DatabaseName.MARIADB, getDatasource(DatabaseName.MARIADB)],
|
||||||
])("/v2/views (%s)", (_, dsProvider) => {
|
])("/v2/views (%s)", (name, dsProvider) => {
|
||||||
const config = setup.getConfig()
|
const config = setup.getConfig()
|
||||||
const isInternal = !dsProvider
|
const isSqs = name === "sqs"
|
||||||
|
const isLucene = name === "lucene"
|
||||||
|
const isInternal = isSqs || isLucene
|
||||||
|
|
||||||
let table: Table
|
let table: Table
|
||||||
let datasource: Datasource
|
let datasource: Datasource
|
||||||
|
let envCleanup: (() => void) | undefined
|
||||||
|
|
||||||
function saveTableRequest(
|
function saveTableRequest(
|
||||||
...overrides: Partial<Omit<SaveTableRequest, "name">>[]
|
...overrides: Partial<Omit<SaveTableRequest, "name">>[]
|
||||||
|
@ -82,6 +88,9 @@ describe.each([
|
||||||
}
|
}
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
|
if (isSqs) {
|
||||||
|
envCleanup = config.setEnv({ SQS_SEARCH_ENABLE: "true" })
|
||||||
|
}
|
||||||
await config.init()
|
await config.init()
|
||||||
|
|
||||||
if (dsProvider) {
|
if (dsProvider) {
|
||||||
|
@ -94,6 +103,9 @@ describe.each([
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
setup.afterAll()
|
setup.afterAll()
|
||||||
|
if (envCleanup) {
|
||||||
|
envCleanup()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
@ -1252,12 +1264,13 @@ describe.each([
|
||||||
paginate: true,
|
paginate: true,
|
||||||
limit: 4,
|
limit: 4,
|
||||||
query: {},
|
query: {},
|
||||||
|
countRows: true,
|
||||||
})
|
})
|
||||||
expect(page1).toEqual({
|
expect(page1).toEqual({
|
||||||
rows: expect.arrayContaining(rows.slice(0, 4)),
|
rows: expect.arrayContaining(rows.slice(0, 4)),
|
||||||
totalRows: isInternal ? 10 : undefined,
|
|
||||||
hasNextPage: true,
|
hasNextPage: true,
|
||||||
bookmark: expect.anything(),
|
bookmark: expect.anything(),
|
||||||
|
totalRows: 10,
|
||||||
})
|
})
|
||||||
|
|
||||||
const page2 = await config.api.viewV2.search(view.id, {
|
const page2 = await config.api.viewV2.search(view.id, {
|
||||||
|
@ -1265,12 +1278,13 @@ describe.each([
|
||||||
limit: 4,
|
limit: 4,
|
||||||
bookmark: page1.bookmark,
|
bookmark: page1.bookmark,
|
||||||
query: {},
|
query: {},
|
||||||
|
countRows: true,
|
||||||
})
|
})
|
||||||
expect(page2).toEqual({
|
expect(page2).toEqual({
|
||||||
rows: expect.arrayContaining(rows.slice(4, 8)),
|
rows: expect.arrayContaining(rows.slice(4, 8)),
|
||||||
totalRows: isInternal ? 10 : undefined,
|
|
||||||
hasNextPage: true,
|
hasNextPage: true,
|
||||||
bookmark: expect.anything(),
|
bookmark: expect.anything(),
|
||||||
|
totalRows: 10,
|
||||||
})
|
})
|
||||||
|
|
||||||
const page3 = await config.api.viewV2.search(view.id, {
|
const page3 = await config.api.viewV2.search(view.id, {
|
||||||
|
@ -1278,13 +1292,17 @@ describe.each([
|
||||||
limit: 4,
|
limit: 4,
|
||||||
bookmark: page2.bookmark,
|
bookmark: page2.bookmark,
|
||||||
query: {},
|
query: {},
|
||||||
|
countRows: true,
|
||||||
})
|
})
|
||||||
expect(page3).toEqual({
|
const expectation: SearchResponse<Row> = {
|
||||||
rows: expect.arrayContaining(rows.slice(8)),
|
rows: expect.arrayContaining(rows.slice(8)),
|
||||||
totalRows: isInternal ? 10 : undefined,
|
|
||||||
hasNextPage: false,
|
hasNextPage: false,
|
||||||
bookmark: expect.anything(),
|
totalRows: 10,
|
||||||
})
|
}
|
||||||
|
if (isLucene) {
|
||||||
|
expectation.bookmark = expect.anything()
|
||||||
|
}
|
||||||
|
expect(page3).toEqual(expectation)
|
||||||
})
|
})
|
||||||
|
|
||||||
const sortTestOptions: [
|
const sortTestOptions: [
|
||||||
|
|
|
@ -154,7 +154,7 @@ export async function search(
|
||||||
options: RowSearchParams,
|
options: RowSearchParams,
|
||||||
table: Table
|
table: Table
|
||||||
): Promise<SearchResponse<Row>> {
|
): Promise<SearchResponse<Row>> {
|
||||||
const { paginate, query, ...params } = options
|
let { paginate, query, ...params } = options
|
||||||
|
|
||||||
const allTables = await sdk.tables.getAllInternalTables()
|
const allTables = await sdk.tables.getAllInternalTables()
|
||||||
const allTablesMap = buildTableMap(allTables)
|
const allTablesMap = buildTableMap(allTables)
|
||||||
|
@ -196,7 +196,7 @@ export async function search(
|
||||||
sortField.type === FieldType.NUMBER ? SortType.NUMBER : SortType.STRING
|
sortField.type === FieldType.NUMBER ? SortType.NUMBER : SortType.STRING
|
||||||
request.sort = {
|
request.sort = {
|
||||||
[sortField.name]: {
|
[sortField.name]: {
|
||||||
direction: params.sortOrder || SortOrder.DESCENDING,
|
direction: params.sortOrder || SortOrder.ASCENDING,
|
||||||
type: sortType as SortType,
|
type: sortType as SortType,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -207,7 +207,8 @@ export async function search(
|
||||||
}
|
}
|
||||||
|
|
||||||
const bookmark: number = (params.bookmark as number) || 0
|
const bookmark: number = (params.bookmark as number) || 0
|
||||||
if (paginate && params.limit) {
|
if (params.limit) {
|
||||||
|
paginate = true
|
||||||
request.paginate = {
|
request.paginate = {
|
||||||
limit: params.limit + 1,
|
limit: params.limit + 1,
|
||||||
offset: bookmark * params.limit,
|
offset: bookmark * params.limit,
|
||||||
|
|
Loading…
Reference in New Issue