diff --git a/packages/server/src/utils/federationOutbox.systemType.test.ts b/packages/server/src/utils/federationOutbox.systemType.test.ts new file mode 100644 index 00000000..4add98c5 --- /dev/null +++ b/packages/server/src/utils/federationOutbox.systemType.test.ts @@ -0,0 +1,38 @@ +import { describe, it, expect, vi } from 'vitest'; + +vi.mock('../utils/federationAuth.js', () => ({ + getOurOrigin: () => 'https://test.example', + buildFederationHeaders: () => ({}), + generateHmacSecret: () => 'secret', +})); + +describe('buildRelayPayload — type field', () => { + const user = { id: 'u1', homeUserId: 'u1', homeInstance: 'https://x.example' }; + + it('omits type for user messages (backward-compat with old peers)', async () => { + const { buildRelayPayload } = await import('./federationOutbox.js'); + const payload = buildRelayPayload( + { id: 'm1', type: 'user', content: 'hi', createdAt: 1 }, + user, + ); + expect((payload as any).type).toBeUndefined(); + }); + + it('omits type when not set (defaults to user)', async () => { + const { buildRelayPayload } = await import('./federationOutbox.js'); + const payload = buildRelayPayload( + { id: 'm1', content: 'hi', createdAt: 1 }, + user, + ); + expect((payload as any).type).toBeUndefined(); + }); + + it('emits type for system messages', async () => { + const { buildRelayPayload } = await import('./federationOutbox.js'); + const payload = buildRelayPayload( + { id: 'm1', type: 'system', content: '{"event":"space_invite"}', createdAt: 1 }, + user, + ); + expect((payload as any).type).toBe('system'); + }); +});