Add resourceOwner.id related test (#14816)

Co-authored-by: sean-brydon <[email protected]>
Co-authored-by: Joe Au-Yeung <[email protected]>
Co-authored-by: Keith Williams <[email protected]>
This commit is contained in:
authored and GitHub committed 2024-05-06 23:50:59 +00:00
1 parent b2baaea84c
commit c87b8b43f9
1 file changed
+63
@@ -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`", () => {