Improve test to cover body

This commit is contained in:
Adria Navarro 2025-03-19 16:41:08 +01:00
parent cc042e2093
commit fe8764fef8
1 changed files with 15 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import {
BasicRestAuthConfig,
BearerRestAuthConfig,
BodyType,
OAuth2CredentialsMethod,
RestAuthType,
} from "@budibase/types"
import { Response } from "node-fetch"
@ -276,20 +277,30 @@ describe("REST Integration", () => {
expect(data).toEqual({ foo: "bar" })
})
it("adds OAuth2 auth", async () => {
it("adds OAuth2 auth (via body)", async () => {
const oauth2Url = generator.url()
const secret = generator.hash()
const { config: oauthConfig } = await config.api.oauth2.create({
name: generator.guid(),
url: oauth2Url,
clientId: generator.guid(),
clientSecret: generator.hash(),
clientSecret: secret,
method: OAuth2CredentialsMethod.HEADER,
})
const token = generator.guid()
const url = new URL(oauth2Url)
nock(url.origin)
.post(url.pathname)
nock(url.origin, {
reqheaders: {
"content-Type": "application/x-www-form-urlencoded",
},
})
.post(url.pathname, {
grant_type: "client_credentials",
client_id: oauthConfig.clientId,
client_secret: secret,
})
.reply(200, { token_type: "Bearer", access_token: token })
nock("https://example.com", {