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:
@@ -1,6 +1,19 @@
|
||||
import type { HostApiContext } from '../context';
|
||||
import type { NormalizedHostApiRequest } from '../route-utils';
|
||||
import { fail, ok } from '../route-utils';
|
||||
import { buildGatewayDiagnosticsSummary } from '../../gateway/diagnostics';
|
||||
import { listAgentsSnapshot } from '../../utils/agent-config';
|
||||
import { listSelectedChannelAccountGroups } from '../../utils/channels';
|
||||
|
||||
function buildChannelGroups(ctx: HostApiContext) {
|
||||
const accounts = ctx.providerApiService
|
||||
.getAccounts()
|
||||
.filter((account) => account.enabled !== false);
|
||||
const defaultAccountId = ctx.providerApiService.getDefault().accountId;
|
||||
const snapshot = listAgentsSnapshot(accounts, defaultAccountId);
|
||||
|
||||
return listSelectedChannelAccountGroups(snapshot);
|
||||
}
|
||||
|
||||
export async function handleGatewayRoutes(
|
||||
request: NormalizedHostApiRequest,
|
||||
@@ -9,21 +22,31 @@ export async function handleGatewayRoutes(
|
||||
const { pathname, method } = request;
|
||||
|
||||
if (pathname === '/api/app/gateway-info' && method === 'GET') {
|
||||
const status = ctx.gatewayManager.getStatus();
|
||||
const health = await ctx.gatewayManager.checkHealth();
|
||||
const summary = buildGatewayDiagnosticsSummary(health, buildChannelGroups(ctx));
|
||||
return ok({
|
||||
transport: 'ipc-bridge',
|
||||
rpcChannel: 'gateway:rpc',
|
||||
eventChannel: 'gateway:event',
|
||||
...status,
|
||||
...health,
|
||||
summary,
|
||||
});
|
||||
}
|
||||
|
||||
if (pathname === '/api/gateway/status' && method === 'GET') {
|
||||
return ok(ctx.gatewayManager.getStatus());
|
||||
const status = await ctx.gatewayManager.checkHealth();
|
||||
return ok({
|
||||
...status,
|
||||
summary: buildGatewayDiagnosticsSummary(status, buildChannelGroups(ctx)),
|
||||
});
|
||||
}
|
||||
|
||||
if (pathname === '/api/gateway/health' && method === 'GET') {
|
||||
return ok(await ctx.gatewayManager.checkHealth());
|
||||
const health = await ctx.gatewayManager.checkHealth();
|
||||
return ok({
|
||||
...health,
|
||||
summary: buildGatewayDiagnosticsSummary(health, buildChannelGroups(ctx)),
|
||||
});
|
||||
}
|
||||
|
||||
if (pathname === '/api/gateway/start' && method === 'POST') {
|
||||
|
||||
Reference in New Issue
Block a user