Limit view AI column tests to internal tables.
This commit is contained in:
parent
352e16f347
commit
a18256a9cf
|
@ -936,93 +936,94 @@ if (descriptions.length) {
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("AI fields", () => {
|
isInternal &&
|
||||||
let envCleanup: () => void
|
describe("AI fields", () => {
|
||||||
beforeAll(() => {
|
let envCleanup: () => void
|
||||||
mocks.licenses.useBudibaseAI()
|
beforeAll(() => {
|
||||||
mocks.licenses.useAICustomConfigs()
|
mocks.licenses.useBudibaseAI()
|
||||||
envCleanup = setEnv({
|
mocks.licenses.useAICustomConfigs()
|
||||||
OPENAI_API_KEY: "sk-abcdefghijklmnopqrstuvwxyz1234567890abcd",
|
envCleanup = setEnv({
|
||||||
|
OPENAI_API_KEY: "sk-abcdefghijklmnopqrstuvwxyz1234567890abcd",
|
||||||
|
})
|
||||||
|
|
||||||
|
mockChatGPTResponse(prompt => {
|
||||||
|
if (prompt.includes("elephant")) {
|
||||||
|
return "big"
|
||||||
|
}
|
||||||
|
if (prompt.includes("mouse")) {
|
||||||
|
return "small"
|
||||||
|
}
|
||||||
|
if (prompt.includes("whale")) {
|
||||||
|
return "big"
|
||||||
|
}
|
||||||
|
return "unknown"
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
mockChatGPTResponse(prompt => {
|
afterAll(() => {
|
||||||
if (prompt.includes("elephant")) {
|
nock.cleanAll()
|
||||||
return "big"
|
envCleanup()
|
||||||
}
|
mocks.licenses.useCloudFree()
|
||||||
if (prompt.includes("mouse")) {
|
|
||||||
return "small"
|
|
||||||
}
|
|
||||||
if (prompt.includes("whale")) {
|
|
||||||
return "big"
|
|
||||||
}
|
|
||||||
return "unknown"
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
|
|
||||||
afterAll(() => {
|
it("can use AI fields in view calculations", async () => {
|
||||||
nock.cleanAll()
|
const table = await config.api.table.save(
|
||||||
envCleanup()
|
saveTableRequest({
|
||||||
mocks.licenses.useCloudFree()
|
schema: {
|
||||||
})
|
animal: {
|
||||||
|
name: "animal",
|
||||||
it("can use AI fields in view calculations", async () => {
|
type: FieldType.STRING,
|
||||||
const table = await config.api.table.save(
|
},
|
||||||
saveTableRequest({
|
bigOrSmall: {
|
||||||
schema: {
|
name: "bigOrSmall",
|
||||||
animal: {
|
type: FieldType.AI,
|
||||||
name: "animal",
|
operation: AIOperationEnum.CATEGORISE_TEXT,
|
||||||
type: FieldType.STRING,
|
categories: "big,small",
|
||||||
|
columns: ["animal"],
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
})
|
||||||
|
)
|
||||||
|
|
||||||
|
const view = await config.api.viewV2.create({
|
||||||
|
tableId: table._id!,
|
||||||
|
name: generator.guid(),
|
||||||
|
type: ViewV2Type.CALCULATION,
|
||||||
|
schema: {
|
||||||
bigOrSmall: {
|
bigOrSmall: {
|
||||||
name: "bigOrSmall",
|
visible: true,
|
||||||
type: FieldType.AI,
|
},
|
||||||
operation: AIOperationEnum.CATEGORISE_TEXT,
|
count: {
|
||||||
categories: "big,small",
|
visible: true,
|
||||||
columns: ["animal"],
|
calculationType: CalculationType.COUNT,
|
||||||
|
field: "animal",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
)
|
|
||||||
|
|
||||||
const view = await config.api.viewV2.create({
|
await config.api.row.save(table._id!, {
|
||||||
tableId: table._id!,
|
animal: "elephant",
|
||||||
name: generator.guid(),
|
})
|
||||||
type: ViewV2Type.CALCULATION,
|
|
||||||
schema: {
|
|
||||||
bigOrSmall: {
|
|
||||||
visible: true,
|
|
||||||
},
|
|
||||||
count: {
|
|
||||||
visible: true,
|
|
||||||
calculationType: CalculationType.COUNT,
|
|
||||||
field: "animal",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
await config.api.row.save(table._id!, {
|
await config.api.row.save(table._id!, {
|
||||||
animal: "elephant",
|
animal: "mouse",
|
||||||
})
|
})
|
||||||
|
|
||||||
await config.api.row.save(table._id!, {
|
await config.api.row.save(table._id!, {
|
||||||
animal: "mouse",
|
animal: "whale",
|
||||||
})
|
})
|
||||||
|
|
||||||
await config.api.row.save(table._id!, {
|
const { rows } = await config.api.row.search(view.id, {
|
||||||
animal: "whale",
|
sort: "bigOrSmall",
|
||||||
|
sortOrder: SortOrder.ASCENDING,
|
||||||
|
})
|
||||||
|
expect(rows).toHaveLength(2)
|
||||||
|
expect(rows[0].bigOrSmall).toEqual("big")
|
||||||
|
expect(rows[1].bigOrSmall).toEqual("small")
|
||||||
|
expect(rows[0].count).toEqual(2)
|
||||||
|
expect(rows[1].count).toEqual(1)
|
||||||
})
|
})
|
||||||
|
|
||||||
const { rows } = await config.api.row.search(view.id, {
|
|
||||||
sort: "bigOrSmall",
|
|
||||||
sortOrder: SortOrder.ASCENDING,
|
|
||||||
})
|
|
||||||
expect(rows).toHaveLength(2)
|
|
||||||
expect(rows[0].bigOrSmall).toEqual("big")
|
|
||||||
expect(rows[1].bigOrSmall).toEqual("small")
|
|
||||||
expect(rows[0].count).toEqual(2)
|
|
||||||
expect(rows[1].count).toEqual(1)
|
|
||||||
})
|
})
|
||||||
})
|
|
||||||
})
|
})
|
||||||
|
|
||||||
describe("update", () => {
|
describe("update", () => {
|
||||||
|
|
Loading…
Reference in New Issue