Fix create tests
This commit is contained in:
parent
d3e4604d96
commit
47f8ce025f
|
@ -4,7 +4,6 @@ import {
|
||||||
Ctx,
|
Ctx,
|
||||||
FetchOAuth2ConfigsResponse,
|
FetchOAuth2ConfigsResponse,
|
||||||
OAuth2Config,
|
OAuth2Config,
|
||||||
RequiredKeys,
|
|
||||||
OAuth2ConfigResponse,
|
OAuth2ConfigResponse,
|
||||||
PASSWORD_REPLACEMENT,
|
PASSWORD_REPLACEMENT,
|
||||||
ValidateConfigResponse,
|
ValidateConfigResponse,
|
||||||
|
@ -16,7 +15,7 @@ function toFetchOAuth2ConfigsResponse(
|
||||||
config: OAuth2Config
|
config: OAuth2Config
|
||||||
): OAuth2ConfigResponse {
|
): OAuth2ConfigResponse {
|
||||||
return {
|
return {
|
||||||
id: config.id,
|
id: config._id!,
|
||||||
name: config.name,
|
name: config.name,
|
||||||
url: config.url,
|
url: config.url,
|
||||||
clientId: config.clientId,
|
clientId: config.clientId,
|
||||||
|
@ -38,7 +37,7 @@ export async function create(
|
||||||
ctx: Ctx<UpsertOAuth2ConfigRequest, UpsertOAuth2ConfigResponse>
|
ctx: Ctx<UpsertOAuth2ConfigRequest, UpsertOAuth2ConfigResponse>
|
||||||
) {
|
) {
|
||||||
const { body } = ctx.request
|
const { body } = ctx.request
|
||||||
const newConfig: RequiredKeys<Omit<OAuth2Config, "id">> = {
|
const newConfig = {
|
||||||
name: body.name,
|
name: body.name,
|
||||||
url: body.url,
|
url: body.url,
|
||||||
clientId: body.clientId,
|
clientId: body.clientId,
|
||||||
|
@ -57,8 +56,8 @@ export async function edit(
|
||||||
ctx: Ctx<UpsertOAuth2ConfigRequest, UpsertOAuth2ConfigResponse>
|
ctx: Ctx<UpsertOAuth2ConfigRequest, UpsertOAuth2ConfigResponse>
|
||||||
) {
|
) {
|
||||||
const { body } = ctx.request
|
const { body } = ctx.request
|
||||||
const toUpdate: RequiredKeys<OAuth2Config> = {
|
const toUpdate = {
|
||||||
id: ctx.params.id,
|
_id: body._id,
|
||||||
name: body.name,
|
name: body.name,
|
||||||
url: body.url,
|
url: body.url,
|
||||||
clientId: body.clientId,
|
clientId: body.clientId,
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import {
|
import {
|
||||||
|
DocumentType,
|
||||||
OAuth2Config,
|
OAuth2Config,
|
||||||
OAuth2CredentialsMethod,
|
OAuth2CredentialsMethod,
|
||||||
PASSWORD_REPLACEMENT,
|
PASSWORD_REPLACEMENT,
|
||||||
UpsertOAuth2ConfigRequest,
|
UpsertOAuth2ConfigRequest,
|
||||||
VirtualDocumentType,
|
|
||||||
} from "@budibase/types"
|
} 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"
|
||||||
|
@ -27,7 +27,7 @@ describe("/oauth2", () => {
|
||||||
beforeEach(async () => await config.newTenant())
|
beforeEach(async () => await config.newTenant())
|
||||||
|
|
||||||
const expectOAuth2ConfigId = expect.stringMatching(
|
const expectOAuth2ConfigId = expect.stringMatching(
|
||||||
`^${VirtualDocumentType.OAUTH2_CONFIG}_.+$`
|
`^${DocumentType.OAUTH2_CONFIG}_.+$`
|
||||||
)
|
)
|
||||||
|
|
||||||
describe("fetch", () => {
|
describe("fetch", () => {
|
||||||
|
@ -90,24 +90,26 @@ describe("/oauth2", () => {
|
||||||
await config.api.oauth2.create(oauth2Config2, { status: 201 })
|
await config.api.oauth2.create(oauth2Config2, { status: 201 })
|
||||||
|
|
||||||
const response = await config.api.oauth2.fetch()
|
const response = await config.api.oauth2.fetch()
|
||||||
expect(response.configs).toEqual([
|
expect(response.configs).toEqual(
|
||||||
{
|
expect.arrayContaining([
|
||||||
id: expectOAuth2ConfigId,
|
{
|
||||||
name: oauth2Config.name,
|
id: expectOAuth2ConfigId,
|
||||||
url: oauth2Config.url,
|
name: oauth2Config.name,
|
||||||
clientId: oauth2Config.clientId,
|
url: oauth2Config.url,
|
||||||
clientSecret: PASSWORD_REPLACEMENT,
|
clientId: oauth2Config.clientId,
|
||||||
method: oauth2Config.method,
|
clientSecret: PASSWORD_REPLACEMENT,
|
||||||
},
|
method: oauth2Config.method,
|
||||||
{
|
},
|
||||||
id: expectOAuth2ConfigId,
|
{
|
||||||
name: oauth2Config2.name,
|
id: expectOAuth2ConfigId,
|
||||||
url: oauth2Config2.url,
|
name: oauth2Config2.name,
|
||||||
clientId: oauth2Config2.clientId,
|
url: oauth2Config2.url,
|
||||||
clientSecret: PASSWORD_REPLACEMENT,
|
clientId: oauth2Config2.clientId,
|
||||||
method: oauth2Config2.method,
|
clientSecret: PASSWORD_REPLACEMENT,
|
||||||
},
|
method: oauth2Config2.method,
|
||||||
])
|
},
|
||||||
|
])
|
||||||
|
)
|
||||||
expect(response.configs[0].id).not.toEqual(response.configs[1].id)
|
expect(response.configs[0].id).not.toEqual(response.configs[1].id)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -118,7 +120,7 @@ describe("/oauth2", () => {
|
||||||
await config.api.oauth2.create(oauth2Config2, {
|
await config.api.oauth2.create(oauth2Config2, {
|
||||||
status: 400,
|
status: 400,
|
||||||
body: {
|
body: {
|
||||||
message: "Name already used",
|
message: `OAuth2 config with name '${oauth2Config.name}' is already taken.`,
|
||||||
status: 400,
|
status: 400,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
|
@ -28,7 +28,7 @@ export async function fetch(): Promise<OAuth2Config[]> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function create(
|
export async function create(
|
||||||
config: Omit<OAuth2Config, "id">
|
config: Omit<OAuth2Config, "_id" | "_rev" | "createdAt" | "updatedAt">
|
||||||
): Promise<OAuth2Config> {
|
): Promise<OAuth2Config> {
|
||||||
const db = context.getAppDB()
|
const db = context.getAppDB()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue