Skip to content

Commit

Permalink
Merge pull request #1393 from authts/improve-unit-tests
Browse files Browse the repository at this point in the history
Improve unit tests
  • Loading branch information
pamapa authored Feb 8, 2024
2 parents af51b5b + 85ae19d commit b155e21
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea

# build artifacts
*.tsbuildinfo
Expand Down
36 changes: 35 additions & 1 deletion src/UserManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.

import { once } from "events";
import { RedirectNavigator, type PopupWindow, PopupNavigator, IFrameNavigator } from "./navigators";
import {
RedirectNavigator,
type PopupWindow,
PopupNavigator,
IFrameNavigator,
type NavigateResponse,
} from "./navigators";
import type { SigninResponse } from "./SigninResponse";
import type { SignoutResponse } from "./SignoutResponse";
import { UserManager, type SigninPopupArgs, type SigninRedirectArgs, type SigninSilentArgs, type SignoutSilentArgs } from "./UserManager";
Expand Down Expand Up @@ -33,6 +39,7 @@ describe("UserManager", () => {
userStore: userStoreMock,
metadata: {
authorization_endpoint: "http://sts/oidc/authorize",
end_session_endpoint: "http://sts/oidc/logout",
token_endpoint: "http://sts/oidc/token",
revocation_endpoint: "http://sts/oidc/revoke",
},
Expand Down Expand Up @@ -838,6 +845,33 @@ describe("UserManager", () => {
});
});

describe("signoutRedirect", () => {
it("must remove the user before requesting the logout", async () => {
// arrange
const navigateMock = jest.fn().mockReturnValue(Promise.resolve({
url: "http://localhost:8080",
} as NavigateResponse));
jest.spyOn(subject["_redirectNavigator"], "prepare").mockReturnValue(Promise.resolve({
navigate: navigateMock,
close: () => {},
}));
const user = new User({
access_token: "access_token",
token_type: "token_type",
profile: {} as UserProfile,
});
await subject.storeUser(user);

// act
await subject.signoutRedirect();

// assert
expect(navigateMock).toHaveBeenCalledTimes(1);
const storageString = await subject.settings.userStore.get(subject["_userStoreKey"]);
expect(storageString).toBeNull();
});
});

describe("storeUser", () => {
it("should add user to store", async () => {
// arrange
Expand Down

0 comments on commit b155e21

Please sign in to comment.