test: tighten messaging helper assertions

This commit is contained in:
Peter Steinberger
2026-05-08 20:55:16 +01:00
parent b758abd3ad
commit 45ef4815df
8 changed files with 6 additions and 14 deletions

View File

@@ -71,7 +71,6 @@ describe("mattermost setup contract", () => {
expectedAccountId: "default",
assertPatchedConfig: (cfg) => {
const mattermostConfig = cfg.channels?.mattermost;
expect(mattermostConfig).toBeDefined();
if (!mattermostConfig) {
throw new Error("expected Mattermost config patch");
}

View File

@@ -31,15 +31,18 @@ describe("mattermost doctor", () => {
});
const mattermostConfig = result.config.channels?.mattermost;
expect(mattermostConfig).toBeDefined();
if (!mattermostConfig) {
throw new Error("expected normalized Mattermost config");
}
expect(mattermostConfig.network).toEqual({
dangerouslyAllowPrivateNetwork: true,
});
const workAccount = mattermostConfig.accounts?.work as { network?: Record<string, unknown> };
expect(workAccount).toBeDefined();
const workAccount = mattermostConfig.accounts?.work as
| { network?: Record<string, unknown> }
| undefined;
if (!workAccount) {
throw new Error("expected Mattermost work account config");
}
expect(workAccount.network).toEqual({
dangerouslyAllowPrivateNetwork: false,
});

View File

@@ -277,12 +277,10 @@ describe("updateMattermostPost", () => {
const { calls } = await updatePostAndCapture({ message: "Updated" });
const firstCall = calls[0];
expect(firstCall).toBeDefined();
if (!firstCall) {
throw new Error("expected Mattermost update post request");
}
expect(firstCall.url).toContain("/posts/post1");
expect(firstCall.init).toBeDefined();
if (!firstCall.init) {
throw new Error("expected Mattermost update post request init");
}

View File

@@ -60,12 +60,10 @@ describe("Mattermost model picker", () => {
expect(view.text).toContain("Browse keeps the current runtime");
expect(view.text).toContain("/oc_model <provider/model> --runtime <runtime>");
const firstRow = view.buttons[0];
expect(firstRow).toBeDefined();
if (!firstRow) {
throw new Error("expected Mattermost model picker button row");
}
const browseButton = firstRow[0];
expect(browseButton).toBeDefined();
if (!browseButton) {
throw new Error("expected Mattermost browse providers button");
}

View File

@@ -131,7 +131,6 @@ describe("slash-commands", () => {
expect(result).toHaveLength(1);
const firstCommand = result[0];
expect(firstCommand).toBeDefined();
if (!firstCommand) {
throw new Error("expected Mattermost slash command result");
}

View File

@@ -392,7 +392,6 @@ describe("mattermost setup", () => {
);
expect(textMessages).toEqual(["Enter Mattermost bot token", "Enter Mattermost base URL"]);
const mattermostConfig = result.cfg.channels?.mattermost;
expect(mattermostConfig).toBeDefined();
if (!mattermostConfig) {
throw new Error("expected Mattermost config");
}

View File

@@ -122,7 +122,6 @@ describe("Synology Chat TLS verification defaults", () => {
await settleTimers(invoke());
const httpsRequest = vi.mocked(https.request);
const firstCall = httpsRequest.mock.calls[0];
expect(firstCall).toBeDefined();
if (!firstCall) {
throw new Error("expected Synology Chat HTTPS request");
}
@@ -159,7 +158,6 @@ describe("sendMessage", () => {
await settleTimers(sendMessage("https://nas.example.com/incoming", "Hello", undefined, true));
const httpsRequest = vi.mocked(https.request);
const firstCall = httpsRequest.mock.calls[0];
expect(firstCall).toBeDefined();
if (!firstCall) {
throw new Error("expected Synology Chat HTTPS request");
}
@@ -387,7 +385,6 @@ describe("fetchChatUsers", () => {
const httpsGet = vi.mocked(https.get);
const firstCall = httpsGet.mock.calls[0];
expect(firstCall).toBeDefined();
if (!firstCall) {
throw new Error("expected Synology Chat HTTPS get");
}

View File

@@ -9,7 +9,6 @@ import {
describe("vitest process group helpers", () => {
function getListenerSet(listeners: Map<string, Set<() => void>>, event: string) {
const set = listeners.get(event);
expect(set).toBeDefined();
if (!set) {
throw new Error(`expected ${event} listener set`);
}