Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ We welcome test contributions! While the project doesn't yet have full test cove
- **Component tests** for complex interactive UI (modals, forms).
- Place test files alongside the code they test, named `*.test.ts` or `*.test.tsx`.

To run the test suite locally:
```bash
npm run test
```

To run tests in watch mode during development:
```bash
npm run test:watch
```

---

## 📬 Submitting a Pull Request
Expand Down
28 changes: 28 additions & 0 deletions app/utils/auth.server.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
import { isSessionValid, formatSessionCookie } from './auth.server';

describe('Auth Utilities', () => {
beforeEach(() => {
vi.useFakeTimers();
vi.setSystemTime(new Date(2026, 0, 1).getTime());
});

afterEach(() => {
vi.useRealTimers();
});

it('validates unexpired session correctly', () => {
const expiresAt = new Date(2026, 0, 2).getTime();
expect(isSessionValid(expiresAt)).toBe(true);
});

it('invalidates expired session correctly', () => {
const expiresAt = new Date(2025, 0, 1).getTime();
expect(isSessionValid(expiresAt)).toBe(false);
});

it('formats session cookie string correctly', () => {
const cookie = formatSessionCookie('abc-123');
expect(cookie).toBe('session_id=abc-123; HttpOnly; Secure; Path=/');
});
});
7 changes: 7 additions & 0 deletions app/utils/auth.server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function isSessionValid(expiresAt: number): boolean {
return Date.now() < expiresAt;
}

export function formatSessionCookie(sessionId: string): string {
return `session_id=${sessionId}; HttpOnly; Secure; Path=/`;
}
Loading
Loading