Fix tests
This commit is contained in:
parent
154689df32
commit
3a142fe7c8
|
@ -1,4 +1,4 @@
|
||||||
import { CreateOAuth2ConfigRequest } from "@budibase/types"
|
import { CreateOAuth2ConfigRequest, VirtualDocumentType } from "@budibase/types"
|
||||||
import * as setup from "./utilities"
|
import * as setup from "./utilities"
|
||||||
import { generator } from "@budibase/backend-core/tests"
|
import { generator } from "@budibase/backend-core/tests"
|
||||||
|
|
||||||
|
@ -16,6 +16,10 @@ describe("/oauth2", () => {
|
||||||
|
|
||||||
beforeEach(async () => await config.newTenant())
|
beforeEach(async () => await config.newTenant())
|
||||||
|
|
||||||
|
const expectOAuth2ConfigId = expect.stringMatching(
|
||||||
|
`^${VirtualDocumentType.ROW_ACTION}_.+$`
|
||||||
|
)
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
it("returns empty when no oauth are created", async () => {
|
it("returns empty when no oauth are created", async () => {
|
||||||
const response = await config.api.oauth2.fetch()
|
const response = await config.api.oauth2.fetch()
|
||||||
|
@ -34,7 +38,9 @@ describe("/oauth2", () => {
|
||||||
expect(response).toEqual({
|
expect(response).toEqual({
|
||||||
configs: [
|
configs: [
|
||||||
{
|
{
|
||||||
|
id: expectOAuth2ConfigId,
|
||||||
name: oauth2Config.name,
|
name: oauth2Config.name,
|
||||||
|
url: oauth2Config.url,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
@ -49,12 +55,17 @@ describe("/oauth2", () => {
|
||||||
const response = await config.api.oauth2.fetch()
|
const response = await config.api.oauth2.fetch()
|
||||||
expect(response.configs).toEqual([
|
expect(response.configs).toEqual([
|
||||||
{
|
{
|
||||||
|
id: expectOAuth2ConfigId,
|
||||||
name: oauth2Config.name,
|
name: oauth2Config.name,
|
||||||
|
url: oauth2Config.url,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
id: expectOAuth2ConfigId,
|
||||||
name: oauth2Config2.name,
|
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 () => {
|
it("cannot create configurations with already existing names", async () => {
|
||||||
|
@ -72,7 +83,9 @@ describe("/oauth2", () => {
|
||||||
const response = await config.api.oauth2.fetch()
|
const response = await config.api.oauth2.fetch()
|
||||||
expect(response.configs).toEqual([
|
expect(response.configs).toEqual([
|
||||||
{
|
{
|
||||||
|
id: expectOAuth2ConfigId,
|
||||||
name: oauth2Config.name,
|
name: oauth2Config.name,
|
||||||
|
url: oauth2Config.url,
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
})
|
})
|
||||||
|
|
|
@ -4,6 +4,8 @@ import {
|
||||||
DocumentType,
|
DocumentType,
|
||||||
OAuth2Config,
|
OAuth2Config,
|
||||||
OAuth2Configs,
|
OAuth2Configs,
|
||||||
|
SEPARATOR,
|
||||||
|
VirtualDocumentType,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
async function getDocument(db: Database = context.getAppDB()) {
|
async function getDocument(db: Database = context.getAppDB()) {
|
||||||
|
@ -28,11 +30,11 @@ export async function create(
|
||||||
configs: {},
|
configs: {},
|
||||||
}
|
}
|
||||||
|
|
||||||
if (doc.configs[config.name]) {
|
if (Object.values(doc.configs).find(c => c.name === config.name)) {
|
||||||
throw new HTTPError("Name already used", 400)
|
throw new HTTPError("Name already used", 400)
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = utils.newid()
|
const id = `${VirtualDocumentType.ROW_ACTION}${SEPARATOR}${utils.newid()}`
|
||||||
doc.configs[id] = {
|
doc.configs[id] = {
|
||||||
id,
|
id,
|
||||||
...config,
|
...config,
|
||||||
|
|
|
@ -82,6 +82,7 @@ export enum InternalTable {
|
||||||
export enum VirtualDocumentType {
|
export enum VirtualDocumentType {
|
||||||
VIEW = "view",
|
VIEW = "view",
|
||||||
ROW_ACTION = "row_action",
|
ROW_ACTION = "row_action",
|
||||||
|
OAUTH2_CONFIG = "oauth2",
|
||||||
}
|
}
|
||||||
|
|
||||||
// Because VirtualDocumentTypes can overlap, we need to make sure that we search
|
// Because VirtualDocumentTypes can overlap, we need to make sure that we search
|
||||||
|
|
Loading…
Reference in New Issue