fix: show media from stopped accounts
This commit is contained in:
1 parent
b573b88b08
commit
f34129666e
6 files changed
+84
-6
No files matched your search
@@ -20,6 +20,55 @@ afterEach(async () => {
|
||||
});
|
||||
|
||||
describe('media route username presentation', () => {
|
||||
it('lists persisted received media for accounts whose runtimes are stopped', async () => {
|
||||
const storedItem = (accountId: string, mediaId: string, sender: string) => ({
|
||||
accountId, mediaId, chatUsername: 'alice', chatRoomId: `room-${accountId}`, sender,
|
||||
timestamp: 1, originalUrl: `mxc://${mediaId}`, fileName: `${mediaId}.jpg`, relativePath: `${mediaId}.jpg`, createdAt: 2,
|
||||
});
|
||||
const accounts = [
|
||||
{ accountId: 't2_running', redditUsername: 'running-owner' },
|
||||
{ accountId: 't2_stopped', redditUsername: 'stopped-owner' },
|
||||
];
|
||||
const listMedia = vi.fn((accountId: string) => accountId === 't2_running'
|
||||
? [storedItem(accountId, 'running-received', 'alice')]
|
||||
: [
|
||||
storedItem(accountId, 'stopped-received', 'bob'),
|
||||
storedItem(accountId, 'stopped-sent', '@t2_stopped:reddit.com'),
|
||||
]);
|
||||
const context = {
|
||||
logger: { error: vi.fn() },
|
||||
repos: { accountContent: { listMedia } },
|
||||
services: {
|
||||
media: { getMediaItems: vi.fn().mockResolvedValue([]) },
|
||||
chat: {
|
||||
getCachedConversations: vi.fn().mockResolvedValue([]),
|
||||
resolveSenderDisplay: vi.fn((identity: string) => identity),
|
||||
},
|
||||
redditAccounts: {
|
||||
list: vi.fn().mockReturnValue(accounts),
|
||||
get: vi.fn((accountId: string) => accounts.find((account) => account.accountId === accountId) ?? null),
|
||||
},
|
||||
accountRuntimes: {
|
||||
list: vi.fn().mockReturnValue([{ accountId: 't2_running', state: 'running' }]),
|
||||
get: vi.fn().mockReturnValue({ resources: {
|
||||
mediaService: { getMediaItems: vi.fn().mockResolvedValue([]) },
|
||||
chatService: { getCachedConversations: vi.fn().mockResolvedValue([]) },
|
||||
} }),
|
||||
},
|
||||
},
|
||||
} as unknown as WebContext;
|
||||
const app = express().use('/api', createMediaRouter(context));
|
||||
|
||||
const response = await request(app, '/api/media');
|
||||
const body = await response.json();
|
||||
|
||||
expect(listMedia).toHaveBeenCalledTimes(2);
|
||||
expect(body).toEqual([
|
||||
expect.objectContaining({ id: 'running-received', owner: accounts[0] }),
|
||||
expect.objectContaining({ id: 'stopped-received', owner: accounts[1] }),
|
||||
]);
|
||||
});
|
||||
|
||||
it('lists received media while excluding items sent by the owning account', async () => {
|
||||
const mediaItem = (id: string, sender: string) => ({
|
||||
accountId: 't2_owner', id, chatUsername: 'alice', chatRoomId: 'room-one', sender,
|
||||
@@ -39,6 +88,7 @@ describe('media route username presentation', () => {
|
||||
resolveSenderDisplay: vi.fn((identity: string) => identity),
|
||||
},
|
||||
redditAccounts: {
|
||||
list: vi.fn().mockReturnValue([]),
|
||||
get: vi.fn().mockReturnValue({ accountId: 't2_owner', redditUsername: 'owner' }),
|
||||
},
|
||||
},
|
||||
@@ -111,6 +161,7 @@ describe('media route username presentation', () => {
|
||||
resolveSenderDisplay: vi.fn((identity: string) => identity),
|
||||
},
|
||||
redditAccounts: {
|
||||
list: vi.fn().mockReturnValue([]),
|
||||
get: vi.fn().mockReturnValue({ accountId: 't2_owner', redditUsername: 'owner' }),
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user