Ratatoskr/src/app/components/ServerConfigsLoader.test.ts
Void 0351f1f6e8
All checks were successful
Build pull request / Build pull request (pull_request) Successful in 3m30s
Skip auth-metadata validation when the homeserver returned none
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 18:26:01 +00:00

32 lines
1.2 KiB
TypeScript

import { afterEach, describe, expect, it, vi } from 'vitest';
import { loadServerConfigs } from './ServerConfigsLoader';
const server = (authMetadata: () => Promise<unknown>) =>
({
getCapabilities: async () => ({}),
getMediaConfig: async () => ({ 'm.upload.size': 1 }),
getAuthMetadata: authMetadata,
} as unknown as Parameters<typeof loadServerConfigs>[0]);
describe('loadServerConfigs', () => {
afterEach(() => vi.restoreAllMocks());
it('logs nothing when the homeserver has no OIDC (no auth metadata came back)', async () => {
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
const configs = await loadServerConfigs(
server(async () => {
throw new Error('M_UNRECOGNIZED');
})
);
expect(error).not.toHaveBeenCalled();
expect(configs.authMetadata).toBeUndefined();
expect(configs.mediaConfig).toEqual({ 'm.upload.size': 1 });
});
it('still logs and drops auth metadata that came back malformed', async () => {
const error = vi.spyOn(console, 'error').mockImplementation(() => {});
const configs = await loadServerConfigs(server(async () => ({ issuer: 'https://x' })));
expect(error).toHaveBeenCalled();
expect(configs.authMetadata).toBeUndefined();
});
});