mirror of
https://github.com/yusufipk/OpenFrame.git
synced 2026-09-11 17:46:06 +00:00
test: add unit, API, component and end-to-end test suites
The repo had no automated tests. Every change was verified by hand. Adds four layers, 2023 tests in total, runnable with one command: - 1191 unit tests over the pure logic in lib/, including the full computeProjectAccess permission matrix and the billing gate - 167 component and hook tests in jsdom, covering the hooks that hold real logic rather than presentational wrappers - 647 API integration tests against a real Postgres, with only auth() mocked, including a data-driven sweep asserting that none of the 60 route modules answers 2xx to an unauthenticated caller - 18 Playwright specs driving a real browser against a real build Infrastructure: vitest.config.ts with three projects, a disposable Postgres and MinIO in docker-compose.test.yml, factories and helpers under tests/, scripts/test.sh as the single entry point, a pre-push hook running bun run verify, and CI split into check, test and e2e jobs. The test database is built with prisma db push plus a replay of the hand-written SQL, because prisma migrate deploy cannot build this schema from empty: the migration history has no captured baseline. This mirrors what scripts/docker-db-bootstrap.ts already does in production, and tests/setup/db-global.ts carries a drift guard so a new migration fails the run until someone reviews it. Production code is unchanged apart from one pure-function extraction out of use-video-player.ts, which was too large to test in jsdom. Several tests pin behaviour that looks wrong, each marked KNOWN BUG in place. TESTING.md section 12 records where the plan turned out to be wrong, and AGENTS.md now states which layer a change needs a test in.
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isValidEmailAddress, normalizeEmail } from '@/lib/email-validation';
|
||||
|
||||
describe('normalizeEmail', () => {
|
||||
it.each([
|
||||
[' [email protected] ', '[email protected]'],
|
||||
['[email protected]', '[email protected]'],
|
||||
['\[email protected]\n', '[email protected]'],
|
||||
['[email protected]', '[email protected]'],
|
||||
])('normalises %s to %s', (input, expected) => {
|
||||
expect(normalizeEmail(input)).toBe(expected);
|
||||
});
|
||||
|
||||
it('does not strip internal whitespace', () => {
|
||||
expect(normalizeEmail('a [email protected]')).toBe('a [email protected]');
|
||||
});
|
||||
});
|
||||
|
||||
describe('isValidEmailAddress', () => {
|
||||
it.each([
|
||||
'[email protected]',
|
||||
'[email protected]',
|
||||
'[email protected]',
|
||||
'[email protected]',
|
||||
"o'[email protected]",
|
||||
'[email protected]',
|
||||
'[email protected]',
|
||||
])('accepts %s', (email) => {
|
||||
expect(isValidEmailAddress(email)).toBe(true);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['an empty string', ''],
|
||||
['a two character string', 'a@'],
|
||||
['no at sign', 'userexample.com'],
|
||||
['a leading at sign', '@example.com'],
|
||||
['two at signs', 'user@[email protected]'],
|
||||
['a domain with no dot', 'user@example'],
|
||||
['a domain that is only a dot', 'user@.'],
|
||||
['an empty domain label', '[email protected]'],
|
||||
['a trailing dot', '[email protected].'],
|
||||
['a leading dot in the domain', '[email protected]'],
|
||||
['an internal space', 'user [email protected]'],
|
||||
['a leading space', ' [email protected]'],
|
||||
['a tab', 'user\[email protected]'],
|
||||
['a newline', '[email protected]\n'],
|
||||
['a carriage return', 'user\[email protected]'],
|
||||
['a null byte', 'user\[email protected]'],
|
||||
['a delete character', 'user\[email protected]'],
|
||||
['an empty local part', '@b.co'],
|
||||
])('rejects %s', (_label, email) => {
|
||||
expect(isValidEmailAddress(email)).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts a local part of exactly 64 characters', () => {
|
||||
expect(isValidEmailAddress(`${'a'.repeat(64)}@example.com`)).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects a local part of 65 characters', () => {
|
||||
expect(isValidEmailAddress(`${'a'.repeat(65)}@example.com`)).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts a domain label of exactly 63 characters', () => {
|
||||
expect(isValidEmailAddress(`user@${'a'.repeat(63)}.com`)).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects a domain label of 64 characters', () => {
|
||||
expect(isValidEmailAddress(`user@${'a'.repeat(64)}.com`)).toBe(false);
|
||||
});
|
||||
|
||||
it('accepts an address of exactly 254 characters', () => {
|
||||
const local = 'a'.repeat(64);
|
||||
const domain = `${'b'.repeat(63)}.${'c'.repeat(63)}.${'d'.repeat(61)}`;
|
||||
const email = `${local}@${domain}`;
|
||||
|
||||
expect(email).toHaveLength(254);
|
||||
expect(isValidEmailAddress(email)).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects an address of 255 characters', () => {
|
||||
const local = 'a'.repeat(64);
|
||||
const domain = `${'b'.repeat(63)}.${'c'.repeat(63)}.${'d'.repeat(62)}`;
|
||||
const email = `${local}@${domain}`;
|
||||
|
||||
expect(email).toHaveLength(255);
|
||||
expect(isValidEmailAddress(email)).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects a three character address because the domain cannot hold a dot', () => {
|
||||
// The length floor is 3, so this documents that the domain rule, not the
|
||||
// length rule, is what rejects the shortest inputs.
|
||||
expect(isValidEmailAddress('a@b')).toBe(false);
|
||||
expect(isValidEmailAddress('ab')).toBe(false);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user