mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-10-20 14:06:27 +00:00
bfc857d246
When a user signs in via OIDC and hasn't uploaded a custom avatar, their `picture` claim is now used as their avatar. The users.avatar column holds either an uploaded file name or an absolute https URL from the claim, and a single resolver on each side (server avatarUrl, client avatarSrc) renders both. An uploaded avatar always wins and is never overwritten; the picture refreshes on each login otherwise. Only https URLs are stored, matching the image CSP. All the scattered /uploads/avatars/ builders now go through the resolvers, which also fixes collection member avatars that were rendering a bare file name. Discussion #1399
26 lines
1011 B
TypeScript
26 lines
1011 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/services/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();
|
|
});
|
|
});
|