From c87b8b43f98ac2dbfdc5f98fe339d7663fd8f9d3 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Tue, 7 May 2024 05:20:59 +0530 Subject: [PATCH] Add resourceOwner.id related test (#14816) Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: Keith Williams --- .../_utils/oauth/OAuthManager.test.ts | 63 +++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/packages/app-store/_utils/oauth/OAuthManager.test.ts b/packages/app-store/_utils/oauth/OAuthManager.test.ts index e8e8b3dbd5..b0056504fc 100644 --- a/packages/app-store/_utils/oauth/OAuthManager.test.ts +++ b/packages/app-store/_utils/oauth/OAuthManager.test.ts @@ -828,6 +828,38 @@ describe("Credential Sync Disabled", () => { ); }); }); + + // Credentials might have no userId attached in production. They could instead have teamId + test("OAuthManager without resourceOwner.id is okay", async () => { + const userId = null; + const invalidateTokenObject = vi.fn(); + const expireAccessToken = vi.fn(); + const updateTokenObject = vi.fn(); + const fetchNewTokenObject = vi.fn().mockResolvedValue(successResponse({ json: getDummyTokenObject() })); + + expect( + () => + new OAuthManager({ + credentialSyncVariables: useCredentialSyncVariables, + resourceOwner: { + type: "user", + id: userId, + }, + appSlug: "demo-app", + currentTokenObject: getDummyTokenObject(), + fetchNewTokenObject, + isTokenObjectUnusable: async () => { + return null; + }, + isAccessTokenUnusable: async () => { + return null; + }, + invalidateTokenObject: invalidateTokenObject, + updateTokenObject: updateTokenObject, + expireAccessToken: expireAccessToken, + }) + ).not.toThrowError(); + }); }); describe("Credential Sync Enabled", () => { @@ -962,6 +994,37 @@ describe("Credential Sync Enabled", () => { expect(fetchNewTokenObject).not.toHaveBeenCalled(); }); }); + + test("OAuthManager without resourceOwner.id should throw error as it is a requirement", async () => { + const userId = null; + const invalidateTokenObject = vi.fn(); + const expireAccessToken = vi.fn(); + const updateTokenObject = vi.fn(); + const fetchNewTokenObject = vi.fn().mockResolvedValue(successResponse({ json: getDummyTokenObject() })); + + expect( + () => + new OAuthManager({ + credentialSyncVariables: useCredentialSyncVariables, + resourceOwner: { + type: "user", + id: userId, + }, + appSlug: "demo-app", + currentTokenObject: getDummyTokenObject(), + fetchNewTokenObject, + isTokenObjectUnusable: async () => { + return null; + }, + isAccessTokenUnusable: async () => { + return null; + }, + invalidateTokenObject: invalidateTokenObject, + updateTokenObject: updateTokenObject, + expireAccessToken: expireAccessToken, + }) + ).toThrowError("resourceOwner should have id set"); + }); }); describe("API: `request`", () => {