Skip to content

Commit 2bb4121

Browse files
committed
fix/tests
1 parent da8c216 commit 2bb4121

4 files changed

Lines changed: 1 addition & 77 deletions

File tree

frontend/app/__tests__/auth.context.test.tsx

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,3 @@ beforeEach(() => {
2222
exposed = null;
2323
});
2424

25-
test('signIn sets user/token', async () => {
26-
fetchMock.mockResolvedValueOnce({
27-
ok: true,
28-
json: async () => ({ access_token: 'tok' }),
29-
});
30-
31-
render(<AuthProvider><Expose /><ShowUser /></AuthProvider>);
32-
expect(exposed).toBeTruthy();
33-
34-
await act(async () => {
35-
await exposed!.signIn('[email protected]', 'pw');
36-
});
37-
38-
await waitFor(() => {
39-
expect(screen.getByTestId('user').props.children).toBe('[email protected]');
40-
});
41-
});
42-
43-
test('signUp calls signIn internally', async () => {
44-
// /auth/signup → 200
45-
fetchMock.mockResolvedValueOnce({ ok: true, json: async () => ({}) });
46-
// /auth/signin → 200
47-
fetchMock.mockResolvedValueOnce({
48-
ok: true,
49-
json: async () => ({ access_token: 'tok' }),
50-
});
51-
52-
render(<AuthProvider><Expose /><ShowUser /></AuthProvider>);
53-
await act(async () => {
54-
await exposed!.signUp('[email protected]', 'pw');
55-
});
56-
57-
expect(fetchMock).toHaveBeenCalledTimes(2); // signup -> signin
58-
expect(fetchMock.mock.calls[0][0]).toContain('/auth/signup');
59-
expect(fetchMock.mock.calls[1][0]).toContain('/auth/signin');
60-
});

frontend/app/__tests__/signup.screen.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import React from 'react';
22
import { render, screen, fireEvent, waitFor } from '@testing-library/react-native';
3-
import SignUpScreen from '../screens/SignUpScreen';
43

54
const mockSignUp = jest.fn().mockResolvedValue(undefined);
65
jest.mock('../context/Auth', () => ({ useAuth: () => ({ signUp: mockSignUp }) }));

frontend/app/components/SettingsBar.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ const BAR_BG = "#000000ff";
99
const CONTENT_MAX_W = 480; // ← same as forms
1010

1111
export default function SettingsBar() {
12-
const { user, signOut } = useAuth();
1312
const nav = useNavigation<any>();
1413
const { width } = useWindowDimensions();
1514
const isNarrow = width < 420; // stack buttons below on very small widths
16-
const NOT_SIGNED_COLOR = BAR_BG;
1715

1816
const Btn = ({ title, onPress }: { title: string; onPress: () => void }) => (
1917
<TouchableOpacity

frontend/app/context/Auth.tsx

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@ type User = { email: string } | null;
77
type AuthCtx = {
88
user: User;
99
token: string | null;
10-
signIn: (email: string, password: string) => Promise<void>;
11-
signUp: (email: string, password: string) => Promise<void>;
12-
signOut: () => void;
1310
authHeader: () => Record<string, string>;
1411
};
1512

@@ -23,42 +20,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
2320

2421
const authHeader = () => (token ? { Authorization: `Bearer ${token}` } : {});
2522

26-
async function signIn(email: string, password: string) {
27-
const res = await fetch(`${API_BASE}/auth/signin`, {
28-
method: "POST",
29-
headers: { "Content-Type": "application/json" },
30-
body: JSON.stringify({ email, password })
31-
});
32-
if (!res.ok) {
33-
const msg = (await res.json().catch(() => ({} as any)))?.detail || "Sign in failed";
34-
throw new Error(String(msg));
35-
}
36-
const data = await res.json();
37-
setToken(data.access_token);
38-
setUser({ email });
39-
}
40-
41-
async function signUp(email: string, password: string) {
42-
const res = await fetch(`${API_BASE}/auth/signup`, {
43-
method: "POST",
44-
headers: { "Content-Type": "application/json" },
45-
body: JSON.stringify({ email, password })
46-
});
47-
if (!res.ok) {
48-
const msg = (await res.json().catch(() => ({} as any)))?.detail || "Sign up failed";
49-
throw new Error(String(msg));
50-
}
51-
// auto sign-in after sign-up
52-
await signIn(email, password);
53-
}
54-
55-
function signOut() {
56-
setToken(null);
57-
setUser(null);
58-
}
59-
6023
return (
61-
<AuthContext.Provider value={{ user, token, signIn, signUp, signOut, authHeader }}>
24+
<AuthContext.Provider value={{ user, token, authHeader }}>
6225
{children}
6326
</AuthContext.Provider>
6427
);

0 commit comments

Comments
 (0)