test: require channel lifecycle starters

This commit is contained in:
Peter Steinberger
2026-05-08 18:36:55 +01:00
parent 9a83706da4
commit a7b359d319
2 changed files with 24 additions and 3 deletions

View File

@@ -17,6 +17,16 @@ vi.mock("./monitor-runtime.js", () => ({
const { nextcloudTalkGatewayAdapter } = await import("./gateway.js");
type NextcloudTalkStartAccount = NonNullable<typeof nextcloudTalkGatewayAdapter.startAccount>;
function requireStartAccount(): NextcloudTalkStartAccount {
const startAccount = nextcloudTalkGatewayAdapter.startAccount;
if (!startAccount) {
throw new Error("Expected Nextcloud Talk gateway startAccount");
}
return startAccount;
}
function buildAccount(): ResolvedNextcloudTalkAccount {
return {
accountId: "default",
@@ -40,7 +50,7 @@ function mockStartedMonitor() {
}
function startNextcloudAccount(abortSignal?: AbortSignal) {
return nextcloudTalkGatewayAdapter.startAccount!(
return requireStartAccount()(
createStartAccountContext({
account: buildAccount(),
abortSignal,
@@ -56,7 +66,7 @@ describe("nextcloud-talk startAccount lifecycle", () => {
it("keeps startAccount pending until abort, then stops the monitor", async () => {
const stop = mockStartedMonitor();
const { abort, task, isSettled } = startAccountAndTrackLifecycle({
startAccount: nextcloudTalkGatewayAdapter.startAccount!,
startAccount: requireStartAccount(),
account: buildAccount(),
});
await expectStopPendingUntilAbort({

View File

@@ -48,6 +48,17 @@ vi.mock("./channel.runtime.js", () => ({
import { zaloPlugin } from "./channel.js";
type ZaloGateway = NonNullable<typeof zaloPlugin.gateway>;
type ZaloStartAccount = NonNullable<ZaloGateway["startAccount"]>;
function requireStartAccount(): ZaloStartAccount {
const startAccount = zaloPlugin.gateway?.startAccount;
if (!startAccount) {
throw new Error("Expected Zalo gateway startAccount");
}
return startAccount;
}
function buildAccount(): ResolvedZaloAccount {
return {
accountId: "default",
@@ -76,7 +87,7 @@ describe("zaloPlugin gateway.startAccount", () => {
);
const { abort, patches, task, isSettled } = startAccountAndTrackLifecycle({
startAccount: zaloPlugin.gateway!.startAccount!,
startAccount: requireStartAccount(),
account: buildAccount(),
});