Add tests for budibase AI self host quota.
This commit is contained in:
parent
9298b162eb
commit
9ef8599fb8
|
@ -1 +1 @@
|
||||||
Subproject commit 172d40f4754b4cefc424ac63c4dfb7327cadc92d
|
Subproject commit af8e1f1e53b9cb9a7d4b773e68b5f0344a895788
|
|
@ -1,7 +1,13 @@
|
||||||
import { mockChatGPTResponse } from "../../../tests/utilities/mocks/ai/openai"
|
import { mockChatGPTResponse } from "../../../tests/utilities/mocks/ai/openai"
|
||||||
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
import TestConfiguration from "../../../tests/utilities/TestConfiguration"
|
||||||
import nock from "nock"
|
import nock from "nock"
|
||||||
import { configs, env, features, setEnv } from "@budibase/backend-core"
|
import {
|
||||||
|
configs,
|
||||||
|
env,
|
||||||
|
features,
|
||||||
|
setEnv,
|
||||||
|
StaticDatabases,
|
||||||
|
} from "@budibase/backend-core"
|
||||||
import {
|
import {
|
||||||
AIInnerConfig,
|
AIInnerConfig,
|
||||||
ConfigType,
|
ConfigType,
|
||||||
|
@ -10,11 +16,13 @@ import {
|
||||||
PlanModel,
|
PlanModel,
|
||||||
PlanType,
|
PlanType,
|
||||||
ProviderConfig,
|
ProviderConfig,
|
||||||
|
QuotaUsage,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { context } from "@budibase/backend-core"
|
import { context } from "@budibase/backend-core"
|
||||||
import { mocks } from "@budibase/backend-core/tests"
|
import { mocks } from "@budibase/backend-core/tests"
|
||||||
import { MockLLMResponseFn } from "../../../tests/utilities/mocks/ai"
|
import { MockLLMResponseFn } from "../../../tests/utilities/mocks/ai"
|
||||||
import { mockAnthropicResponse } from "../../../tests/utilities/mocks/ai/anthropic"
|
import { mockAnthropicResponse } from "../../../tests/utilities/mocks/ai/anthropic"
|
||||||
|
import { quotas } from "@budibase/pro"
|
||||||
|
|
||||||
function dedent(str: string) {
|
function dedent(str: string) {
|
||||||
return str
|
return str
|
||||||
|
@ -301,13 +309,29 @@ describe("BudibaseAI", () => {
|
||||||
.reply(200, license)
|
.reply(200, license)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("handles correct chat response", async () => {
|
async function getQuotaUsage() {
|
||||||
|
return await context.doInSelfHostTenantUsingCloud(
|
||||||
|
config.getTenantId(),
|
||||||
|
async () => {
|
||||||
|
return await quotas.getQuotaUsage()
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
it.only("handles correct chat response", async () => {
|
||||||
|
let usage = await getQuotaUsage()
|
||||||
|
expect(usage._id).toBe(`quota_usage_${config.getTenantId()}`)
|
||||||
|
expect(usage.monthly.current.budibaseAICredits).toBe(0)
|
||||||
|
|
||||||
mockChatGPTResponse("Hi there!")
|
mockChatGPTResponse("Hi there!")
|
||||||
const { message } = await config.api.ai.chat({
|
const { message } = await config.api.ai.chat({
|
||||||
messages: [{ role: "user", content: "Hello!" }],
|
messages: [{ role: "user", content: "Hello!" }],
|
||||||
licenseKey: licenseKey,
|
licenseKey: licenseKey,
|
||||||
})
|
})
|
||||||
expect(message).toBe("Hi there!")
|
expect(message).toBe("Hi there!")
|
||||||
|
|
||||||
|
usage = await getQuotaUsage()
|
||||||
|
expect(usage.monthly.current.budibaseAICredits).toBeGreaterThan(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("handles chat response error", async () => {
|
it("handles chat response error", async () => {
|
||||||
|
|
Loading…
Reference in New Issue