From fe8764fef8c4496134f11a92e0c870ac0b5a0c25 Mon Sep 17 00:00:00 2001 From: Adria Navarro Date: Wed, 19 Mar 2025 16:41:08 +0100 Subject: [PATCH] Improve test to cover body --- .../src/integrations/tests/rest.spec.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/packages/server/src/integrations/tests/rest.spec.ts b/packages/server/src/integrations/tests/rest.spec.ts index 055ddde9ae..919849b616 100644 --- a/packages/server/src/integrations/tests/rest.spec.ts +++ b/packages/server/src/integrations/tests/rest.spec.ts @@ -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", {