Bausteine: slugify mit Umlauten, deutsche Zeit, Sperren

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
ClaudeandClaude Opus 5.5 committed 2026-09-30 10:21:34 +00:00
1 parent a3faa1aff1
commit 679f996597
6 files changed
+144

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { berlinDateTime } from '../server/services/berlinTime.js'
test('Sommerzeit', () => assert.deepEqual(berlinDateTime(new Date('2026-09-27T14:46:34Z')), { date: '27.09.2026', time: '1646' }))
test('Winterzeit', () => assert.deepEqual(berlinDateTime(new Date('2026-01-15T10:05:00Z')), { date: '15.01.2026', time: '1105' }))
test('nach Mitternacht UTC', () => assert.deepEqual(berlinDateTime(new Date('2026-09-27T22:30:00Z')), { date: '28.09.2026', time: '0030' }))
+39
View File
@@ -0,0 +1,39 @@
import { test, beforeEach } from 'node:test'
import assert from 'node:assert/strict'
import { withLocks } from '../server/services/keyedLock.js'
const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
let log
beforeEach(() => {
log = []
})
const job = (name, ms) => async () => {
log.push(name + ':start')
await sleep(ms)
log.push(name + ':end')
}
test('gleicher Schlüssel läuft nacheinander', async () => {
await Promise.all([withLocks(['a'], job('1', 50)), withLocks(['a'], job('2', 10))])
assert.deepEqual(log, ['1:start', '1:end', '2:start', '2:end'])
})
test('verschiedene Schlüssel laufen parallel', async () => {
await Promise.all([withLocks(['a'], job('1', 50)), withLocks(['b'], job('2', 10))])
assert.deepEqual(log.slice(0, 2), ['1:start', '2:start'])
})
test('mehrere Schlüssel sperren alle', async () => {
await Promise.all([withLocks(['a', 'b'], job('1', 50)), withLocks(['b'], job('2', 10))])
assert.deepEqual(log, ['1:start', '1:end', '2:start', '2:end'])
})
test('waitMs begrenzt das Warten', async () => {
const t0 = Date.now()
let started
await Promise.all([withLocks(['a'], job('1', 300)), withLocks(['a'], async () => { started = Date.now() - t0 }, { waitMs: 50 })])
assert.ok(started >= 45 && started < 250, `gestartet nach ${started} ms`)
})
test('Fehler geben die Sperre frei', async () => {
await assert.rejects(withLocks(['a'], async () => { throw new Error('x') }))
assert.equal(await withLocks(['a'], async () => 42), 42)
})
+18
View File
@@ -0,0 +1,18 @@
import { test } from 'node:test'
import assert from 'node:assert/strict'
import { slugify } from '../server/services/slug.js'
test('Umlaute', () => {
assert.equal(slugify('Döner Nation'), 'doener-nation')
assert.equal(slugify('Größe Überall Ärger'), 'groesse-ueberall-aerger')
})
test('Apostrophe entfallen', () => {
assert.equal(slugify("Emma's Schatzkiste"), 'emmas-schatzkiste')
assert.equal(slugify('Emma’s'), 'emmas')
})
test('Akzente', () => assert.equal(slugify('Café Élan'), 'cafe-elan'))
test('Sonderzeichen, Ränder, Länge', () => {
assert.equal(slugify('--A&B--'), 'a-b')
assert.equal(slugify('x'.repeat(150)).length, 100)
assert.equal(slugify(null), '')
})