mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-19 13:36:48 +00:00
6dda05f672
Eight files in services/ hold no state and touch no database: avatarUrl, conflictResult, demo, passwordPolicy, timezoneService, cookie, and the two crypto helpers. They are imported from 65 places, 62 of them already inside src/nest, so having them live in the legacy layer was pure inertia. They stay plain functions rather than becoming providers. Three importers sit outside the container and would have no way to reach an injectable one: db/migrations.ts runs before the app is built, and middleware/auth.ts and middleware/mfaPolicy.ts run beside it. Wrapping these in DI would buy ceremony and nothing else. mfaCrypto and apiKeyCrypto move together into common/crypto — they read the same ENCRYPTION_KEY, and the directory says so. services/ drops from 44 files to 36, 9,870 lines to 8,493. One trap worth recording: src/app-config and src/nest/app-config both exist. cookie.ts imported '../app-config' from services/, which resolved to the former; after the move the same string silently pointed at the latter, which has no readEnv. It is now explicit about which one it wants. Nothing else changes — no signatures, no behaviour, no tests rewritten beyond their import paths.
26 lines
1014 B
TypeScript
26 lines
1014 B
TypeScript
/**
|
|
* Unit tests for avatarUrl — AVATAR-URL-001 through AVATAR-URL-003.
|
|
* The stored value is either an uploaded file name or an absolute https URL from
|
|
* an OIDC `picture` claim (#1399); the helper resolves both to a renderable src.
|
|
*/
|
|
import { describe, it, expect } from 'vitest';
|
|
import { avatarUrl } from '../../../src/nest/common/avatarUrl';
|
|
|
|
describe('avatarUrl', () => {
|
|
it('AVATAR-URL-001: prefixes an uploaded file name with the avatars path', () => {
|
|
expect(avatarUrl({ avatar: 'abc123.jpg' })).toBe('/uploads/avatars/abc123.jpg');
|
|
});
|
|
|
|
it('AVATAR-URL-002: passes an absolute https URL (OIDC picture) through untouched', () => {
|
|
expect(avatarUrl({ avatar: 'https://idp.example.com/u/pic.png' })).toBe(
|
|
'https://idp.example.com/u/pic.png',
|
|
);
|
|
});
|
|
|
|
it('AVATAR-URL-003: returns null when no avatar is set', () => {
|
|
expect(avatarUrl({ avatar: null })).toBeNull();
|
|
expect(avatarUrl({ avatar: undefined })).toBeNull();
|
|
expect(avatarUrl({})).toBeNull();
|
|
});
|
|
});
|