42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { presentActivityItem, resolveRedditUsername } from '../../src/web/reddit-identities.js';
|
|
|
|
const resolver = {
|
|
resolveSenderDisplay(identity: string) {
|
|
return identity.replace(/^@?t2_known(?::reddit\.com)?$/, 'alice');
|
|
},
|
|
};
|
|
|
|
describe('Reddit identity presentation', () => {
|
|
it('resolves internal ids and rejects unresolved ids', () => {
|
|
expect(resolveRedditUsername('@t2_known:reddit.com', resolver)).toBe('alice');
|
|
expect(resolveRedditUsername('t2_missing', resolver)).toBeNull();
|
|
});
|
|
|
|
it('upgrades both the activity recipient and its persisted message text', () => {
|
|
expect(presentActivityItem({
|
|
timestamp: 1,
|
|
type: 'response',
|
|
message: 'Reply from u/t2_known',
|
|
recipient: 't2_known',
|
|
}, resolver)).toEqual({
|
|
timestamp: 1,
|
|
type: 'response',
|
|
message: 'Reply from u/alice',
|
|
recipient: 'alice',
|
|
});
|
|
});
|
|
|
|
it('redacts unresolved ids instead of exposing them', () => {
|
|
const item = presentActivityItem({
|
|
timestamp: 1,
|
|
type: 'response',
|
|
message: 'Reply from @t2_missing:reddit.com',
|
|
recipient: 't2_missing',
|
|
}, resolver);
|
|
|
|
expect(item.message).toBe('Reply from Reddit user');
|
|
expect(item.recipient).toBeUndefined();
|
|
});
|
|
});
|