Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 7 additions & 34 deletions packages/federation-sdk/src/repositories/event.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,54 +55,27 @@ export class EventRepository {

let queries: { query: Record<string, unknown> }[] = [];
switch (eventType) {
case 'm.room.name':
queries = [
baseQueries.create,
baseQueries.powerLevels,
baseQueries.membership,
];
case 'm.room.create':
queries = [baseQueries.create];
break;

case 'm.room.message':
queries = [
baseQueries.create,
baseQueries.powerLevels,
baseQueries.membership,
];
case 'm.room.redaction':
queries = [baseQueries.create, baseQueries.powerLevels];
break;

case 'm.reaction':
queries = [
baseQueries.create,
baseQueries.powerLevels,
baseQueries.membership,
];
break;

case 'm.room.name':
case 'm.room.message':
case 'm.room.member':
queries = [
baseQueries.create,
baseQueries.powerLevels,
baseQueries.membership,
];
break;

case 'm.room.create':
queries = [baseQueries.create];
break;

case 'm.room.power_levels':
case 'm.room.topic':
queries = [
baseQueries.create,
baseQueries.powerLevels,
baseQueries.membership,
];
break;

case 'm.room.redaction':
queries = [baseQueries.create, baseQueries.powerLevels];
break;

default:
throw new Error(`Unsupported event type: ${eventType}`);
}
Comment on lines 57 to 81
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion | 🟠 Major

Add test coverage for the new m.room.topic support.

The Codecov report indicates 0% patch coverage with 7 lines missing coverage in this file. Since this change adds support for a new event type and modifies auth event behavior for existing types, comprehensive test coverage is essential to prevent regressions.

Consider adding tests that:

  1. Verify m.room.topic returns the correct auth events (create, powerLevels, membership)
  2. Validate the refactored auth event queries for m.room.create and m.room.redaction
  3. Ensure the default case throws an error for truly unsupported event types

Would you like me to generate test cases for the findAuthEvents method covering the new m.room.topic support?

🤖 Prompt for AI Agents
In packages/federation-sdk/src/repositories/event.repository.ts around lines 57
to 81, tests are missing for the newly-added m.room.topic branch and modified
auth-event behavior; add unit tests for findAuthEvents that (1) assert
m.room.topic returns [create, powerLevels, membership] auth event queries, (2)
verify m.room.create and m.room.redaction return their expected query sets
(create only and create+powerLevels respectively), and (3) confirm the default
branch throws for unsupported event types; mock any dependencies or baseQueries
inputs and assert that the method selects the correct query array for each
eventType.

Expand Down
3 changes: 2 additions & 1 deletion packages/federation-sdk/src/services/event.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -559,13 +559,14 @@ export class EventService {
if (
type &&
[
'm.reaction',
'm.room.create',
'm.room.member',
'm.room.message',
'm.room.redaction',
'm.reaction',
'm.room.name',
'm.room.power_levels',
'm.room.topic',
].includes(type)
) {
authEvents.push(storeEvent);
Expand Down