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