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