Add unit tests for channel utilities and configure testing environment
- Created a new test file `channels.test.ts` to cover utilities related to channel configurations and targets. - Implemented tests for normalizing and grouping selected channels by type, as well as building channel targets from account data and cron history. - Mocked necessary dependencies to isolate tests and ensure accurate results. - Updated `vite.config.ts` to set up the testing environment with jsdom and enable global variables for tests.
This commit is contained in:
40
electron/gateway/diagnostics.ts
Normal file
40
electron/gateway/diagnostics.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
import type { ChannelAccountCatalogGroup, ChannelConnectionStatus } from '@src/lib/channel-types';
|
||||
import { buildChannelStatusSummary, type ChannelStatusSummary } from '@electron/utils/channel-status';
|
||||
|
||||
export interface GatewayHealthSnapshot {
|
||||
ok: boolean;
|
||||
status: 'connected' | 'disconnected' | 'reconnecting';
|
||||
initialized: boolean;
|
||||
mode: 'in-process';
|
||||
}
|
||||
|
||||
export interface GatewayDiagnosticsSummary {
|
||||
status: ChannelConnectionStatus;
|
||||
gateway: GatewayHealthSnapshot;
|
||||
channels: ChannelStatusSummary;
|
||||
}
|
||||
|
||||
function normalizeGatewayStatus(status: GatewayHealthSnapshot['status']): ChannelConnectionStatus {
|
||||
if (status === 'reconnecting') return 'connecting';
|
||||
return status;
|
||||
}
|
||||
|
||||
export function buildGatewayDiagnosticsSummary(
|
||||
health: GatewayHealthSnapshot,
|
||||
channelGroups: readonly ChannelAccountCatalogGroup[],
|
||||
): GatewayDiagnosticsSummary {
|
||||
const channels = buildChannelStatusSummary(channelGroups);
|
||||
const gatewayStatus = normalizeGatewayStatus(health.status);
|
||||
|
||||
return {
|
||||
status: health.ok
|
||||
? (channels.status === 'connected'
|
||||
? 'connected'
|
||||
: channels.status === 'disconnected'
|
||||
? 'degraded'
|
||||
: channels.status)
|
||||
: gatewayStatus,
|
||||
gateway: health,
|
||||
channels,
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user