Files
API/test/feedback/events.admin.service.test.ts
Paddy 3ea9e630ed Migrate the API to native ESM and vitest; pin Node 26
Prep PR for the admin auth module (docs/plan-admin-auth.md step 1).
better-auth 1.7 ships ESM only, so the API moves off CommonJS:

- "type": "module", module nodenext, target ES2024, .js suffixes on all
  relative imports, require('mariadb'|'cors') replaced by imports, and
  export= packages (winston, app-root-path, bcrypt) consumed via default
  imports. The logger now uses appRoot.path explicitly.
- TypeScript 5.9, @types/node 26, tslint removed. Node 26 pinned via
  engines and .nvmrc (Plesk runs 26).
- Jest 28 + ts-jest replaced by vitest 5. Eight test files depend on
  hoisted module mocks with static imports and resetModules + require,
  which Jest's ESM mode does not support; vitest keeps them nearly
  verbatim. Coverage via @vitest/coverage-v8 (lcov), Sonar generic report
  via vitest-sonar-reporter, so sonar-project.properties is unchanged.
  vitest.config.ts sets FEEDBACK_IP_SALT so the suite passes without a
  local .env.
- dotenv 8 -> 16 and axios 0.24 -> 1.x: their old typings are not
  resolvable under nodenext.
- autoCommit: false dropped from the pool configs; it is not a mariadb
  connector option and was silently ignored.

tsc clean, 96/96 tests green, compiled app boots and serves /, /docs and
CORS under Node ESM.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-05 16:02:26 +02:00

61 lines
2.1 KiB
TypeScript

import {describe, it, expect} from 'vitest';
import {computeDefaultDeadline, slugBase, slugifyName} from '../../src/models/feedback/admin/events.admin.service.js';
describe('slugifyName', () => {
it('lowercases and hyphenates', () => {
expect(slugifyName('Sommerkonzert 2026')).toBe('sommerkonzert-2026');
});
it('transliterates umlauts', () => {
expect(slugifyName('Frühlingskonzert')).toBe('fruehlingskonzert');
expect(slugifyName('Weihnachtsgrüße')).toBe('weihnachtsgruesse');
});
it('strips punctuation and collapses separators', () => {
expect(slugifyName('Konzert: "Klänge & Farben"!')).toBe('konzert-klaenge-farben');
});
it('trims leading and trailing hyphens', () => {
expect(slugifyName(' -- Herbstkonzert -- ')).toBe('herbstkonzert');
});
});
describe('slugBase', () => {
it('appends the concert year when the name does not already carry it', () => {
expect(slugBase('Sommerkonzert', '2026-08-01')).toBe('sommerkonzert-2026');
});
it('does not double up the year when the name already ends with it', () => {
expect(slugBase('Adventskonzert 2026', '2026-12-06')).toBe('adventskonzert-2026');
});
it('still appends the year when the name contains a different year', () => {
expect(slugBase('Jubiläum 2020', '2026-08-01')).toBe('jubilaeum-2020-2026');
});
});
describe('computeDefaultDeadline', () => {
it('is 14 days after the event date, at 23:59:59', () => {
const deadline = computeDefaultDeadline('2026-08-01');
expect(deadline.getFullYear()).toBe(2026);
expect(deadline.getMonth()).toBe(7); // August = index 7
expect(deadline.getDate()).toBe(15);
expect(deadline.getHours()).toBe(23);
expect(deadline.getMinutes()).toBe(59);
expect(deadline.getSeconds()).toBe(59);
});
it('rolls over the month correctly', () => {
const deadline = computeDefaultDeadline('2026-08-25');
expect(deadline.getMonth()).toBe(8); // September
expect(deadline.getDate()).toBe(8);
});
it('rolls over the year correctly', () => {
const deadline = computeDefaultDeadline('2026-12-25');
expect(deadline.getFullYear()).toBe(2027);
expect(deadline.getMonth()).toBe(0); // January
expect(deadline.getDate()).toBe(8);
});
});