Improve Reddit chat and media reliability
This commit is contained in:
1 parent
a44768c089
commit
345ec99348
14 files changed
+323
-676
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import express from 'express';
|
||||
import type { AddressInfo } from 'node:net';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { MediaResponseSchema } from '../../packages/api-contracts/src/media.js';
|
||||
import type { WebContext } from '../../src/web/context.js';
|
||||
import { createMediaRouter } from '../../src/web/routes/media.js';
|
||||
|
||||
@@ -63,4 +64,35 @@ describe('media route username presentation', () => {
|
||||
expect(JSON.stringify(body)).not.toContain('t2_missing');
|
||||
expect(body[0]).toMatchObject({ chatUsername: null, sender: 'Unknown Reddit user' });
|
||||
});
|
||||
|
||||
it('keeps the internal account ID out of the public media item', async () => {
|
||||
const context = {
|
||||
logger: { error: vi.fn() },
|
||||
services: {
|
||||
media: { getMediaItems: vi.fn().mockResolvedValue([{
|
||||
accountId: 't2_owner', id: 'one', chatUsername: 'alice', chatRoomId: 'room-one', sender: 'alice',
|
||||
timestamp: 1, originalUrl: 'mxc://one', fileName: 'one.jpg', relativePath: 'one.jpg', createdAt: 2,
|
||||
}]) },
|
||||
chat: {
|
||||
getCachedConversations: vi.fn().mockResolvedValue([]),
|
||||
resolveSenderDisplay: vi.fn((identity: string) => identity),
|
||||
},
|
||||
redditAccounts: {
|
||||
get: vi.fn().mockReturnValue({ accountId: 't2_owner', redditUsername: 'owner' }),
|
||||
},
|
||||
},
|
||||
} as unknown as WebContext;
|
||||
const app = express().use('/api', createMediaRouter(context));
|
||||
|
||||
const response = await request(app, '/api/media');
|
||||
const body: unknown = await response.json();
|
||||
|
||||
expect(MediaResponseSchema.parse(body)).toEqual([
|
||||
expect.objectContaining({
|
||||
id: 'one',
|
||||
owner: { accountId: 't2_owner', redditUsername: 'owner' },
|
||||
}),
|
||||
]);
|
||||
expect(body).not.toEqual([expect.objectContaining({ accountId: expect.anything() })]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user