Fix create tests

This commit is contained in:
Adria Navarro 2025-03-20 16:59:31 +01:00
parent d3e4604d96
commit 47f8ce025f
3 changed files with 28 additions and 27 deletions

View File

@ -4,7 +4,6 @@ import {
Ctx,
FetchOAuth2ConfigsResponse,
OAuth2Config,
RequiredKeys,
OAuth2ConfigResponse,
PASSWORD_REPLACEMENT,
ValidateConfigResponse,
@ -16,7 +15,7 @@ function toFetchOAuth2ConfigsResponse(
config: OAuth2Config
): OAuth2ConfigResponse {
return {
id: config.id,
id: config._id!,
name: config.name,
url: config.url,
clientId: config.clientId,
@ -38,7 +37,7 @@ export async function create(
ctx: Ctx<UpsertOAuth2ConfigRequest, UpsertOAuth2ConfigResponse>
) {
const { body } = ctx.request
const newConfig: RequiredKeys<Omit<OAuth2Config, "id">> = {
const newConfig = {
name: body.name,
url: body.url,
clientId: body.clientId,
@ -57,8 +56,8 @@ export async function edit(
ctx: Ctx<UpsertOAuth2ConfigRequest, UpsertOAuth2ConfigResponse>
) {
const { body } = ctx.request
const toUpdate: RequiredKeys<OAuth2Config> = {
id: ctx.params.id,
const toUpdate = {
_id: body._id,
name: body.name,
url: body.url,
clientId: body.clientId,

View File

@ -1,9 +1,9 @@
import {
DocumentType,
OAuth2Config,
OAuth2CredentialsMethod,
PASSWORD_REPLACEMENT,
UpsertOAuth2ConfigRequest,
VirtualDocumentType,
} from "@budibase/types"
import * as setup from "./utilities"
import { generator } from "@budibase/backend-core/tests"
@ -27,7 +27,7 @@ describe("/oauth2", () => {
beforeEach(async () => await config.newTenant())
const expectOAuth2ConfigId = expect.stringMatching(
`^${VirtualDocumentType.OAUTH2_CONFIG}_.+$`
`^${DocumentType.OAUTH2_CONFIG}_.+$`
)
describe("fetch", () => {
@ -90,24 +90,26 @@ describe("/oauth2", () => {
await config.api.oauth2.create(oauth2Config2, { status: 201 })
const response = await config.api.oauth2.fetch()
expect(response.configs).toEqual([
{
id: expectOAuth2ConfigId,
name: oauth2Config.name,
url: oauth2Config.url,
clientId: oauth2Config.clientId,
clientSecret: PASSWORD_REPLACEMENT,
method: oauth2Config.method,
},
{
id: expectOAuth2ConfigId,
name: oauth2Config2.name,
url: oauth2Config2.url,
clientId: oauth2Config2.clientId,
clientSecret: PASSWORD_REPLACEMENT,
method: oauth2Config2.method,
},
])
expect(response.configs).toEqual(
expect.arrayContaining([
{
id: expectOAuth2ConfigId,
name: oauth2Config.name,
url: oauth2Config.url,
clientId: oauth2Config.clientId,
clientSecret: PASSWORD_REPLACEMENT,
method: oauth2Config.method,
},
{
id: expectOAuth2ConfigId,
name: oauth2Config2.name,
url: oauth2Config2.url,
clientId: oauth2Config2.clientId,
clientSecret: PASSWORD_REPLACEMENT,
method: oauth2Config2.method,
},
])
)
expect(response.configs[0].id).not.toEqual(response.configs[1].id)
})
@ -118,7 +120,7 @@ describe("/oauth2", () => {
await config.api.oauth2.create(oauth2Config2, {
status: 400,
body: {
message: "Name already used",
message: `OAuth2 config with name '${oauth2Config.name}' is already taken.`,
status: 400,
},
})

View File

@ -28,7 +28,7 @@ export async function fetch(): Promise<OAuth2Config[]> {
}
export async function create(
config: Omit<OAuth2Config, "id">
config: Omit<OAuth2Config, "_id" | "_rev" | "createdAt" | "updatedAt">
): Promise<OAuth2Config> {
const db = context.getAppDB()