Skip to content
This repository has been archived by the owner on Dec 23, 2023. It is now read-only.

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
DiD3n committed Apr 13, 2022
1 parent de58206 commit 4816067
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
5 changes: 4 additions & 1 deletion src/components/containers/LectureCard/EventCard.tsx
Expand Up @@ -25,7 +25,7 @@ export const EventCard: React.FC<EventCardProps> = ({
}) => {

const cardStyle: React.CSSProperties = {
backgroundColor: color || "#080736" //space dark
backgroundColor: color
}

return (
Expand All @@ -52,4 +52,7 @@ export const EventCard: React.FC<EventCardProps> = ({
</div>
</div>
)
}
EventCard.defaultProps = {
color: "#080736"
}
15 changes: 7 additions & 8 deletions src/contexts/auth/AuthContext.tsx
Expand Up @@ -9,23 +9,22 @@ import Providers from "../../api/rest/auth/oauth/Provider";
import { User } from "../../common/models/User";

export interface AuthContextInterface {
auth(provider: string, code: string, state?: string): Promise<User>;
logout(): void;
user: User | null; // undefined == not authorized
refreshSession(): void;
axios: AxiosInstance,
auth(provider: string, code: string, state?: string): Promise<User>
logout(): void
user?: User
refreshSession(): void
axios: AxiosInstance
}

export const AuthContext = createContext<AuthContextInterface>({
user: null,
auth: async () => { throw new Error("AuthContext not initialized") },
logout: () => { throw new Error("AuthContext not initialized") },
refreshSession: () => { throw new Error("AuthContext not initialized") },
axios: axios.create({baseURL: __RESTAPI_URI__})
});

export const AuthContextProvider: React.FC = ({ children }) => {
const [user, setUser] = useState<User | null>(null);
const [user, setUser] = useState<User|undefined>(undefined);

const [axiosClient, setAxiosClient] = useState<AxiosInstance>(() => createAxiosClient());
const [apolloClient, setApolloClient] = useState<ApolloClient<NormalizedCacheObject>>(() => createApolloClient());
Expand Down Expand Up @@ -67,7 +66,7 @@ export const AuthContextProvider: React.FC = ({ children }) => {
setApolloClient(() => createApolloClient());
setAxiosClient(() => createAxiosClient());

setUser(() => null);
setUser(() => undefined);
localStorage.setItem("refresh_token", "");
}

Expand Down
8 changes: 4 additions & 4 deletions src/contexts/auth/__test__/BasicAuthorization.test.tsx
Expand Up @@ -67,7 +67,7 @@ describe('Authorization Context', () => {
})

it('should login', async () => {
expect(testContext?.user).toBe(null);
expect(testContext?.user).toBe(undefined);

act(() => {
userEvent.click(screen.getByTestId('login'), { button: 0 })
Expand All @@ -82,7 +82,7 @@ describe('Authorization Context', () => {
})

it('should login & logout', async () => {
expect(testContext?.user).toBe(null);
expect(testContext?.user).toBe(undefined);

act(() => {
userEvent.click(screen.getByTestId('login'), { button: 0 })
Expand All @@ -91,13 +91,13 @@ describe('Authorization Context', () => {

await waitFor(() => screen.getByTestId('id'));

expect(testContext?.user).not.toBe(null);
expect(testContext?.user).toBeDefined();
expect(testContext?.user?.nickname).toBe(authRes.username);

act(() => {
userEvent.click(screen.getByTestId('logout'), { button: 0 });
})

expect(testContext?.user).toBe(null);
expect(testContext?.user).toBe(undefined);
})
})

0 comments on commit 4816067

Please sign in to comment.