Add comprehensive tests for profile-redirect and auth features
19 new tests across 5 test files covering the protected layout redirect, account page load, registration action (documenting the redirect bug), and login/register component rendering. Includes shared test utilities. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
b8d1ba11e7
commit
10fd06887f
@@ -0,0 +1,56 @@
|
||||
/**
|
||||
* Shared mock data factories for tests.
|
||||
*
|
||||
* NOTE: `vi.mock()` calls must live in each test file (hoisting requirement).
|
||||
* These helpers only build data objects — no mocking side-effects.
|
||||
*/
|
||||
|
||||
/** Build a minimal `App.Locals` object. Pass a user to simulate an authenticated request. */
|
||||
export function createLocals(user?: { id: string; name: string; email: string }): App.Locals {
|
||||
return {
|
||||
session: user
|
||||
? ({
|
||||
id: 'session-1',
|
||||
userId: user.id,
|
||||
expiresAt: new Date(Date.now() + 86_400_000)
|
||||
} as App.Locals['session'])
|
||||
: (undefined as unknown as App.Locals['session']),
|
||||
user: user as unknown as App.Locals['user']
|
||||
};
|
||||
}
|
||||
|
||||
/** Build a `Request` whose `.formData()` resolves to the given key/value pairs. */
|
||||
export function createFormRequest(fields: Record<string, string>): Request {
|
||||
const fd = new FormData();
|
||||
for (const [k, v] of Object.entries(fields)) fd.append(k, v);
|
||||
return new Request('http://localhost', { method: 'POST', body: fd });
|
||||
}
|
||||
|
||||
/** Minimal user object with sensible defaults. */
|
||||
export function mockUser(overrides?: Record<string, unknown>) {
|
||||
return {
|
||||
id: 'user-1',
|
||||
name: 'Jane Doe',
|
||||
email: 'jane@example.com',
|
||||
emailVerified: true,
|
||||
image: null,
|
||||
createdAt: new Date(),
|
||||
updatedAt: new Date(),
|
||||
roleId: null,
|
||||
...overrides
|
||||
};
|
||||
}
|
||||
|
||||
/** User that also has a profile (and optionally a role). */
|
||||
export function mockUserWithProfile(overrides?: Record<string, unknown>) {
|
||||
return mockUser({
|
||||
profile: {
|
||||
id: 'profile-1',
|
||||
userId: 'user-1',
|
||||
firstName: 'Jane',
|
||||
lastName: 'Doe',
|
||||
phoneNumber: '555-0100'
|
||||
},
|
||||
...overrides
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user