Merge origin/test in feature/terminplaner-tp2 (Projekte: Anlegen, Archiv, Vorlage)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-10-05 07:12:04 +00:00
commit 4c3f67eadc
13 files changed
+424 -122

No files matched your search

+34
View File
@@ -0,0 +1,34 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { loadModule } from './load.mjs'
const { throttleRuns } = await loadModule('src/lib/throttleRuns.js')
test('Repo-Import hoechstens einmal pro Minute, laufender Abgleich wird geteilt', async () => {
let runs = 0
let release
const throttled = throttleRuns(() => { runs += 1; return new Promise((r) => { release = r }) }, 60000)
const a = throttled()
const b = throttled()
assert.equal(a, b)
await new Promise((r) => setTimeout(r, 0))
release({ created: 0 })
await a
assert.equal(runs, 1)
assert.equal(await throttled(), null)
assert.equal(runs, 1)
const later = throttled({ now: Date.now() + 61000 })
await new Promise((r) => setTimeout(r, 0))
release({ created: 1 })
assert.deepEqual(await later, { created: 1 })
assert.equal(runs, 2)
})
test('Fehler wird weitergereicht, danach darf sofort neu versucht werden', async () => {
let runs = 0
const throttled = throttleRuns(async () => { runs += 1; if (runs === 1) throw new Error('weg'); return { ok: true } }, 60000)
await assert.rejects(throttled(), /weg/)
assert.deepEqual(await throttled(), { ok: true })
assert.equal(runs, 2)
assert.equal(await throttled(), null)
})
+30 -3
View File
@@ -2,7 +2,7 @@ import test from 'node:test'
import assert from 'node:assert/strict'
import { loadModule } from './load.mjs'
const { isOutsideOrg, needsPreviewButton, assignSummary, assignSequentially } = await loadModule(
const { isOutsideOrg, needsPreviewButton, assignSummary, assignSequentially, assignableProjects, ticketIdForCustomer } = await loadModule(
'src/lib/projectAssign.js'
)
@@ -17,9 +17,36 @@ test('isOutsideOrg', () => {
})
test('needsPreviewButton', () => {
assert.equal(needsPreviewButton({ previewUrl: 'https://x', status: 'deployed' }), false)
assert.equal(needsPreviewButton({ subdomain: 'x', previewUrl: 'https://x', status: 'deployed' }), false)
assert.equal(needsPreviewButton({ previewUrl: '', status: 'synced' }), true)
assert.equal(needsPreviewButton({ previewUrl: 'https://x', status: 'pending' }), true)
// gerade angelegt, der Runner baut noch (status noch synced/pending): kein "Preview einschalten"
assert.equal(needsPreviewButton({ subdomain: 'x', previewUrl: 'https://x', status: 'synced' }), false)
assert.equal(needsPreviewButton({ subdomain: 'x', previewUrl: 'https://x', status: 'pending' }), false)
// archiviert: erst reaktivieren
assert.equal(needsPreviewButton({ archived: true, status: 'archived' }), false)
})
test('assignableProjects: Flag archived zaehlt, nicht status', () => {
const all = [
{ $id: 'a', repoFullName: 'WEBklar/a', status: 'archived', archived: false }, // reaktiviert, alter status
{ $id: 'b', repoFullName: 'JUSN/b', status: 'synced', archived: true }, // in Gitea archiviert
{ $id: 'c', repoFullName: 'WEBklar/c', customerId: 'k2' }, // anderer Kunde
{ $id: 'd', repoFullName: 'WEBklar/d', customerId: 'k1' },
{ $id: 'e', repoFullName: 'WEBklar/e', isTemplate: true },
{ $id: 'f', projectName: 'ohne Repo' },
{ $id: 'g', repoFullName: 'WEBklar/g' },
]
const ids = assignableProjects(all, { customerId: 'k1' }, new Set(['g'])).map((p) => p.$id)
assert.deepEqual(ids, ['a', 'd'])
})
test('ticketIdForCustomer: altes Ticket nur beim gleichen Kunden', () => {
const p = { customerId: 'A', ticketId: 'tA' }
const wo = { tA: { customerId: 'A' }, tB: { customerId: 'B' } }
assert.equal(ticketIdForCustomer(p, 'A', wo), 'tA')
assert.equal(ticketIdForCustomer(p, 'B', wo), '')
assert.equal(ticketIdForCustomer({ customerId: 'A', ticketId: 'tB' }, 'B', wo), 'tB')
assert.equal(ticketIdForCustomer({ customerId: '', ticketId: '' }, 'B', wo), '')
})
test('assignSummary', () => {
+78
View File
@@ -0,0 +1,78 @@
import test from 'node:test'
import assert from 'node:assert/strict'
import { loadModule } from './load.mjs'
const { projectCounts, projectsInView, viewShowing, matchesSearch, hiddenMatches } = await loadModule('src/lib/projectList.js')
const P = [
{ $id: 'a' },
{ $id: 'b', customerId: 'k' },
{ $id: 'c', archived: true },
{ $id: 'd', isTemplate: true },
{ $id: 'e', isTemplate: true, archived: true },
]
const ids = (list) => list.map((p) => p.$id)
test('Aktive Projekte ohne Archiv und Vorlagen', () => {
assert.deepEqual(ids(projectsInView(P, 'all')), ['a', 'b'])
assert.deepEqual(ids(projectsInView(P, 'unassigned')), ['a'])
assert.deepEqual(ids(projectsInView(P, 'assigned')), ['b'])
})
test('Alle inkl. Archiv: wirklich alles (Vorlagen nur fuer Admins)', () => {
assert.deepEqual(ids(projectsInView(P, 'everything')), ['a', 'b', 'c'])
assert.deepEqual(ids(projectsInView(P, 'everything', { isAdmin: true })), ['a', 'b', 'c', 'd', 'e'])
})
test('Archiviert und Vorlagen', () => {
assert.deepEqual(ids(projectsInView(P, 'archived')), ['c'])
assert.deepEqual(ids(projectsInView(P, 'archived', { isAdmin: true })), ['c', 'e'])
assert.deepEqual(ids(projectsInView(P, 'templates')), ['d'])
})
test('Zaehler passen zu den Ansichten', () => {
assert.deepEqual(projectCounts(P), { all: 2, unassigned: 1, assigned: 1, archived: 1, templates: 1, everything: 3 })
assert.deepEqual(projectCounts(P, { isAdmin: true }).everything, 5)
})
// 04.10.2026: SHK-vorlage zur Vorlage gemacht -> verschwand kommentarlos aus "Aktive Projekte"
test('viewShowing: bleibt in der aktuellen Ansicht, wenn das Projekt dort steht', () => {
assert.equal(viewShowing(P[0], 'all', { isAdmin: true }), 'all')
assert.equal(viewShowing(P[1], 'assigned'), 'assigned')
assert.equal(viewShowing(P[3], 'everything', { isAdmin: true }), 'everything')
})
test('viewShowing: zur Vorlage gemacht -> Vorlagen, zurueck -> Aktive Projekte', () => {
assert.equal(viewShowing({ $id: 'x', isTemplate: true }, 'all', { isAdmin: true }), 'templates')
assert.equal(viewShowing({ $id: 'x', isTemplate: true }, 'unassigned', { isAdmin: true }), 'templates')
assert.equal(viewShowing({ $id: 'x' }, 'templates', { isAdmin: true }), 'all')
assert.equal(viewShowing({ $id: 'x', archived: true }, 'all'), 'archived')
})
test('viewShowing: ohne Admin keine Vorlagen-Ansicht, dann bleibt die Ansicht', () => {
assert.equal(viewShowing({ $id: 'x', isTemplate: true }, 'all'), 'all')
assert.equal(viewShowing(null, 'assigned'), 'assigned')
})
test('matchesSearch: Titel, Subdomain, Repo; leer passt immer', () => {
const p = { projectName: 'SHK-vorlage', subdomain: 'shk-vorlage', repoFullName: 'knso/SHK-vorlage', giteaRepoName: 'SHK-vorlage' }
assert.equal(matchesSearch(p, ''), true)
assert.equal(matchesSearch(p, ' shk '), true)
assert.equal(matchesSearch(p, 'knso/'), true)
assert.equal(matchesSearch(p, 'olzinger'), false)
})
test('hiddenMatches: Treffer, die die aktuelle Ansicht ausblendet', () => {
const list = [
{ $id: 'a', projectName: 'SHK Kunde' },
{ $id: 't', projectName: 'SHK-vorlage', isTemplate: true },
{ $id: 'r', projectName: 'SHK alt', archived: true },
{ $id: 'o', projectName: 'Olzinger' },
]
const shk = (p) => matchesSearch(p, 'shk')
assert.deepEqual(hiddenMatches(list, 'all', shk, { isAdmin: true }), [{ view: 'templates', count: 1 }, { view: 'archived', count: 1 }])
assert.deepEqual(hiddenMatches(list, 'all', shk), [{ view: 'archived', count: 1 }], 'Vorlagen nur fuer Admins')
assert.deepEqual(hiddenMatches(list, 'templates', shk, { isAdmin: true }), [{ view: 'archived', count: 1 }])
assert.deepEqual(hiddenMatches(list, 'everything', shk, { isAdmin: true }), [], 'zeigt schon alles')
assert.deepEqual(hiddenMatches(list, 'all', (p) => matchesSearch(p, 'olz'), { isAdmin: true }), [])
})
+8 -1
View File
@@ -2,7 +2,14 @@ import test from 'node:test'
import assert from 'node:assert/strict'
import { loadModule } from './load.mjs'
const { suggestSubdomain } = await loadModule('src/lib/subdomain.js')
const { suggestSubdomain, slugify } = await loadModule('src/lib/subdomain.js')
test('slugify schreibt Umlaute aus wie das Portal', () => {
assert.equal(slugify('Müller & Söhne'), 'mueller-soehne')
assert.equal(slugify(' ZZ Test Ablauf '), 'zz-test-ablauf')
assert.equal(slugify('x'.repeat(70)), 'x'.repeat(63))
assert.equal(slugify(null), '')
})
test('Kundenname vor Projektname', () => {
assert.equal(suggestSubdomain('Döner Nation', 'D-ner-Nation'), 'doener-nation')