further tests around default BB AI config
This commit is contained in:
parent
891f736815
commit
6bf4f47110
|
@ -1,6 +1,6 @@
|
||||||
import { TestConfiguration, structures } from "../../../../tests"
|
import { configs } from "@budibase/backend-core"
|
||||||
import { constants, configs } from "@budibase/backend-core"
|
import { UserCtx } from "@budibase/types"
|
||||||
import { AIConfig, UserCtx } from "@budibase/types"
|
import * as pro from "@budibase/pro"
|
||||||
import { find, verifyAIConfig } from "../configs"
|
import { find, verifyAIConfig } from "../configs"
|
||||||
|
|
||||||
jest.mock("@budibase/backend-core", () => ({
|
jest.mock("@budibase/backend-core", () => ({
|
||||||
|
@ -11,7 +11,12 @@ jest.mock("@budibase/backend-core", () => ({
|
||||||
},
|
},
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
|
||||||
describe("Global configs controller", () => {
|
describe("Global configs controller", () => {
|
||||||
|
afterEach(() => {
|
||||||
|
jest.resetAllMocks()
|
||||||
|
})
|
||||||
|
|
||||||
it("Should strip secrets when pulling AI config", async () => {
|
it("Should strip secrets when pulling AI config", async () => {
|
||||||
configs.getConfig.mockResolvedValue({
|
configs.getConfig.mockResolvedValue({
|
||||||
config: {
|
config: {
|
||||||
|
@ -40,6 +45,42 @@ describe("Global configs controller", () => {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("Should return the default BB AI config when the feature is turned on", async () => {
|
||||||
|
pro.features.isBudibaseAIEnabled = jest.fn(() => true)
|
||||||
|
configs.getConfig.mockResolvedValue({
|
||||||
|
config: {
|
||||||
|
ai: {
|
||||||
|
apiKey: "abc123APIKey",
|
||||||
|
baseUrl: "https://api.example.com",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const ctx = {
|
||||||
|
params: {
|
||||||
|
type: "ai"
|
||||||
|
},
|
||||||
|
throw: jest.fn()
|
||||||
|
} as UserCtx
|
||||||
|
|
||||||
|
await find(ctx)
|
||||||
|
|
||||||
|
expect(ctx.body).toEqual({
|
||||||
|
config: {
|
||||||
|
budibase_ai: {
|
||||||
|
provider: "OpenAI",
|
||||||
|
active: true,
|
||||||
|
isDefault: true,
|
||||||
|
defaultModel: undefined,
|
||||||
|
name: "Budibase AI",
|
||||||
|
},
|
||||||
|
ai: {
|
||||||
|
apiKey: "--secret-value--",
|
||||||
|
"baseUrl": "https://api.example.com"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it("Should not update existing secrets when updating an existing AI Config", async () => {
|
it("Should not update existing secrets when updating an existing AI Config", async () => {
|
||||||
const newConfig = {
|
const newConfig = {
|
||||||
type: "ai",
|
type: "ai",
|
||||||
|
|
Loading…
Reference in New Issue