Fix endpoints

This commit is contained in:
Adria Navarro 2025-03-13 10:32:47 +01:00
parent 615e8fec07
commit 4d18558d45
4 changed files with 21 additions and 9 deletions

View File

@ -24,9 +24,12 @@ export async function fetch(ctx: Ctx<void, FetchOAuth2ConfigsResponse>) {
export async function create(
ctx: Ctx<CreateOAuth2ConfigRequest, CreateOAuth2ConfigResponse>
) {
const { body } = ctx.request
const newConfig: RequiredKeys<Omit<OAuth2Config, "id">> = {
name: ctx.request.body.name,
url: ctx.request.body.url,
name: body.name,
url: body.url,
clientId: ctx.clientId,
clientSecret: ctx.clientSecret,
}
const config = await sdk.oauth2.create(newConfig)

View File

@ -9,6 +9,8 @@ describe("/oauth2", () => {
return {
name: generator.guid(),
url: generator.url(),
clientId: generator.guid(),
clientSecret: generator.hash(),
}
}

View File

@ -277,14 +277,17 @@ describe("REST Integration", () => {
})
it("adds oAuth2 auth", async () => {
const oauth2Url = generator.url()
const { config: oauthConfig } = await config.api.oauth2.create({
name: generator.guid(),
url: generator.url(),
url: oauth2Url,
clientId: generator.guid(),
clientSecret: generator.hash(),
})
const token = generator.guid()
const url = new URL(oauthConfig.url)
const url = new URL(oauth2Url)
nock(url.origin)
.post(url.pathname)
.reply(200, { token_type: "Bearer", access_token: token })

View File

@ -1,15 +1,19 @@
interface OAuth2Config {
interface OAuth2ConfigResponse {
id: string
name: string
url: string
}
export interface FetchOAuth2ConfigsResponse {
configs: OAuth2Config[]
configs: OAuth2ConfigResponse[]
}
export interface CreateOAuth2ConfigRequest extends Omit<OAuth2Config, "id"> {}
export interface CreateOAuth2ConfigRequest {
name: string
url: string
clientId: string
clientSecret: string
}
export interface CreateOAuth2ConfigResponse {
config: OAuth2Config
config: OAuth2ConfigResponse
}