Improve test to cover body
This commit is contained in:
parent
cc042e2093
commit
fe8764fef8
|
@ -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", {
|
||||
|
|
Loading…
Reference in New Issue