@propelauth/react
Advanced tools
Comparing version 1.2.2 to 1.2.3
@@ -8,3 +8,3 @@ { | ||
}, | ||
"version": "1.2.2", | ||
"version": "1.2.3", | ||
"license": "MIT", | ||
@@ -11,0 +11,0 @@ "keywords": [ |
@@ -9,2 +9,3 @@ /** | ||
import { AuthProvider } from "./AuthContext" | ||
import { useAuthInfo } from "./useAuthInfo" | ||
import { useLogoutFunction } from "./useLogoutFunction" | ||
@@ -94,2 +95,41 @@ import { useRedirectFunctions } from "./useRedirectFunctions" | ||
it("useAuthInfo passes values correctly", async () => { | ||
const accessToken = randomString() | ||
const orgA = createOrg() | ||
const orgB = createOrg() | ||
const user = createUser() | ||
const authenticationInfo = { | ||
accessToken, | ||
expiresAtSeconds: INITIAL_TIME_SECONDS + 30 * 60, | ||
orgIdToOrgMemberInfo: { | ||
[orgA.orgId]: orgA, | ||
[orgB.orgId]: orgB, | ||
}, | ||
user, | ||
} | ||
mockClient.getAuthenticationInfoOrNull.mockReturnValue(authenticationInfo) | ||
const Component = () => { | ||
const authInfo = useAuthInfo() | ||
if (authInfo.loading) { | ||
return <div>Loading...</div> | ||
} else { | ||
expect(authInfo.accessToken).toBe(accessToken) | ||
expect(authInfo.user).toStrictEqual(user) | ||
expect(authInfo.isLoggedIn).toBe(true) | ||
expect(authInfo.orgHelper.getOrgs().sort()).toEqual([orgA, orgB].sort()) | ||
return <div>Finished</div> | ||
} | ||
} | ||
render( | ||
<AuthProvider authUrl={AUTH_URL}> | ||
<Component /> | ||
</AuthProvider> | ||
) | ||
await waitFor(() => screen.getByText("Finished")) | ||
expectCreateClientWasCalledCorrectly() | ||
}) | ||
it("withAuthInfo passes logged out values from client as props", async () => { | ||
@@ -117,2 +157,28 @@ mockClient.getAuthenticationInfoOrNull.mockReturnValue(null) | ||
it("useAuthInfo passes logged out values from client as props", async () => { | ||
mockClient.getAuthenticationInfoOrNull.mockReturnValue(null) | ||
const Component = () => { | ||
const authInfo = useAuthInfo() | ||
if (authInfo.loading) { | ||
return <div>Loading...</div> | ||
} else { | ||
expect(authInfo.accessToken).toBe(null) | ||
expect(authInfo.user).toBe(null) | ||
expect(authInfo.isLoggedIn).toBe(false) | ||
expect(authInfo.orgHelper).toBe(null) | ||
return <div>Finished</div> | ||
} | ||
} | ||
render( | ||
<AuthProvider authUrl={AUTH_URL}> | ||
<Component /> | ||
</AuthProvider> | ||
) | ||
await waitFor(() => screen.getByText("Finished")) | ||
expectCreateClientWasCalledCorrectly() | ||
}) | ||
it("redirectToLoginPage calls into the client", async () => { | ||
@@ -119,0 +185,0 @@ const Component = () => { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
253103
29
2797