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 <keithwillcode@gmail.com>
This commit is contained in:
Hariom Balhara
2024-05-06 23:50:59 +00:00
committed by GitHub
co-authored by sean-brydon Joe Au-Yeung Keith Williams
parent b2baaea84c
commit c87b8b43f9
@@ -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`", () => {