Fix tests

This commit is contained in:
Adria Navarro 2025-03-12 16:26:17 +01:00
parent 154689df32
commit 3a142fe7c8
3 changed files with 19 additions and 3 deletions

View File

@ -1,4 +1,4 @@
import { CreateOAuth2ConfigRequest } from "@budibase/types"
import { CreateOAuth2ConfigRequest, VirtualDocumentType } from "@budibase/types"
import * as setup from "./utilities"
import { generator } from "@budibase/backend-core/tests"
@ -16,6 +16,10 @@ describe("/oauth2", () => {
beforeEach(async () => await config.newTenant())
const expectOAuth2ConfigId = expect.stringMatching(
`^${VirtualDocumentType.ROW_ACTION}_.+$`
)
describe("fetch", () => {
it("returns empty when no oauth are created", async () => {
const response = await config.api.oauth2.fetch()
@ -34,7 +38,9 @@ describe("/oauth2", () => {
expect(response).toEqual({
configs: [
{
id: expectOAuth2ConfigId,
name: oauth2Config.name,
url: oauth2Config.url,
},
],
})
@ -49,12 +55,17 @@ describe("/oauth2", () => {
const response = await config.api.oauth2.fetch()
expect(response.configs).toEqual([
{
id: expectOAuth2ConfigId,
name: oauth2Config.name,
url: oauth2Config.url,
},
{
id: expectOAuth2ConfigId,
name: oauth2Config2.name,
url: oauth2Config2.url,
},
])
expect(response.configs[0].id).not.toEqual(response.configs[1].id)
})
it("cannot create configurations with already existing names", async () => {
@ -72,7 +83,9 @@ describe("/oauth2", () => {
const response = await config.api.oauth2.fetch()
expect(response.configs).toEqual([
{
id: expectOAuth2ConfigId,
name: oauth2Config.name,
url: oauth2Config.url,
},
])
})

View File

@ -4,6 +4,8 @@ import {
DocumentType,
OAuth2Config,
OAuth2Configs,
SEPARATOR,
VirtualDocumentType,
} from "@budibase/types"
async function getDocument(db: Database = context.getAppDB()) {
@ -28,11 +30,11 @@ export async function create(
configs: {},
}
if (doc.configs[config.name]) {
if (Object.values(doc.configs).find(c => c.name === config.name)) {
throw new HTTPError("Name already used", 400)
}
const id = utils.newid()
const id = `${VirtualDocumentType.ROW_ACTION}${SEPARATOR}${utils.newid()}`
doc.configs[id] = {
id,
...config,

View File

@ -82,6 +82,7 @@ export enum InternalTable {
export enum VirtualDocumentType {
VIEW = "view",
ROW_ACTION = "row_action",
OAUTH2_CONFIG = "oauth2",
}
// Because VirtualDocumentTypes can overlap, we need to make sure that we search