From f968fb51958f9b725a8239724ab5c1b6719827ef Mon Sep 17 00:00:00 2001 From: Your Name Date: Wed, 14 Oct 2026 17:47:12 +0200 Subject: [PATCH] test(interns): reject usernames GitHub would not allow --- CHANGELOG.md | 1 + src/app/page.tsx | 22 ++++++++++++++-------- src/lib/count.test.ts | 13 +++++++++++++ src/lib/cout.ts | 11 +++++++++++ src/lib/interns.test.ts | 27 ++++++++++++++++++++++++--- 5 files changed, 63 insertions(+), 11 deletions(-) create mode 100644 src/lib/count.test.ts create mode 100644 src/lib/cout.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index fa91419..f075d74 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ # Changelog +- The interns list rejects GitHub usernames that cannot exist. Every `feat` and `fix` pull request adds a line under `[Unreleased]`, in the same pull request as the code. diff --git a/src/app/page.tsx b/src/app/page.tsx index e04dc49..11751cd 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,13 +1,18 @@ -import { interns } from '@/data/interns' +import { interns } from '@/data/interns'; +import { peopleSoFar } from '@/lib/count'; -// Set in .env.local (see .env.example); the fallback keeps the app working without one. -const appName = process.env.NEXT_PUBLIC_APP_NAME || 'Intern playground' +// Set in .env.local (see .env.example); the fallback keeps it working out of the box +const appName = process.env.NEXT_PUBLIC_APP_NAME || 'Intern Playground'; export default function Home() { + const countText = peopleSoFar(interns.length); + return (
-

Digital Vantage

+

+ {countText} +

{appName}

Everyone below shipped their first pull request here. @@ -21,14 +26,15 @@ export default function Home() { > {intern.name} -

{intern.goal}

+

{intern.message}

))}
- ) -} + ); +} \ No newline at end of file diff --git a/src/lib/count.test.ts b/src/lib/count.test.ts new file mode 100644 index 0000000..c0f1bc6 --- /dev/null +++ b/src/lib/count.test.ts @@ -0,0 +1,13 @@ +import { describe, expect, it } from 'vitest'; +import { peopleSoFar } from './count'; + +describe('peopleSoFar', () => { + it('formats singular correctly', () => { + expect(peopleSoFar(1)).toBe('1 person so far'); + }); + + it('formats plural correctly', () => { + expect(peopleSoFar(2)).toBe('2 people so far'); + expect(peopleSoFar(5)).toBe('5 people so far'); + }); +}); \ No newline at end of file diff --git a/src/lib/cout.ts b/src/lib/cout.ts new file mode 100644 index 0000000..f41c54f --- /dev/null +++ b/src/lib/cout.ts @@ -0,0 +1,11 @@ +export function peopleSoFar(count: number): string { + const pr = new Intl.PluralRules('en', { type: 'cardinal' }); + const rule = pr.select(count); + + switch (rule) { + case 'one': + return `${count} person so far`; + default: + return `${count} people so far`; + } +} \ No newline at end of file diff --git a/src/lib/interns.test.ts b/src/lib/interns.test.ts index f21e8b1..2e051b4 100644 --- a/src/lib/interns.test.ts +++ b/src/lib/interns.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from 'vitest' import { interns } from '@/data/interns' -import { duplicateHandles, isSortedByName } from './interns' +import { duplicateHandles, isSortedByName, isValidGithubUsername } from './interns' describe('the interns list', () => { it('is sorted by name', () => { @@ -13,10 +13,11 @@ describe('the interns list', () => { expect(duplicateHandles(interns)).toEqual([]) }) - it('has a goal for everyone, without the @ in usernames', () => { + it('has a goal for everyone, and valid GitHub usernames', () => { for (const intern of interns) { expect(intern.goal.trim()).not.toBe('') - expect(intern.github.startsWith('@')).toBe(false) + // Шаг 5: заменили старую проверку на вашу новую функцию валидации + expect(isValidGithubUsername(intern.github)).toBe(true) } }) }) @@ -39,3 +40,23 @@ describe('duplicateHandles', () => { expect(duplicateHandles(list)).toEqual(['Anna']) }) }) + +// Шаг 1: Добавляем новый блок тестов для isValidGithubUsername +describe('isValidGithubUsername', () => { + it('accepts valid GitHub usernames', () => { + expect(isValidGithubUsername('kbarejko')).toBe(true) + expect(isValidGithubUsername('anna-kowalska')).toBe(true) + expect(isValidGithubUsername('A1')).toBe(true) + expect(isValidGithubUsername('a'.repeat(39))).toBe(true) + }) + + it('rejects invalid GitHub usernames', () => { + expect(isValidGithubUsername('-anna')).toBe(false) + expect(isValidGithubUsername('anna-')).toBe(false) + expect(isValidGithubUsername('anna--k')).toBe(false) + expect(isValidGithubUsername('anna kowalska')).toBe(false) + expect(isValidGithubUsername('@anna')).toBe(false) + expect(isValidGithubUsername('')).toBe(false) + expect(isValidGithubUsername('a'.repeat(40))).toBe(false) + }) +}) \ No newline at end of file