























@@ -43,22 +43,19 @@ describe("probeMattermost", () => {
43434444const result = await probeMattermost("https://mm.example.com/api/v4/", "bot-token");
454546-expect(mockFetchGuard).toHaveBeenCalledWith({
47-url: "https://mm.example.com/api/v4/users/me",
48-init: expect.objectContaining({
49-headers: { Authorization: "Bearer bot-token" },
50-}),
51-auditContext: "mattermost-probe",
52-policy: undefined,
46+const [fetchCall] = mockFetchGuard.mock.calls[0] ?? [];
47+expect(fetchCall?.url).toBe("https://mm.example.com/api/v4/users/me");
48+expect(fetchCall?.init?.headers).toStrictEqual({ Authorization: "Bearer bot-token" });
49+expect(fetchCall?.init?.signal).toBeInstanceOf(AbortSignal);
50+expect(fetchCall?.auditContext).toBe("mattermost-probe");
51+expect(fetchCall?.policy).toBeUndefined();
52+const { elapsedMs, ...stableResult } = result;
53+expect(stableResult).toStrictEqual({
54+ok: true,
55+status: 200,
56+bot: { id: "bot-1", username: "clawbot" },
5357});
54-expect(result).toEqual(
55-expect.objectContaining({
56-ok: true,
57-status: 200,
58-bot: { id: "bot-1", username: "clawbot" },
59-}),
60-);
61-expect(result.elapsedMs).toBeGreaterThanOrEqual(0);
58+expect(elapsedMs).toBeGreaterThanOrEqual(0);
6259expect(mockRelease).toHaveBeenCalledTimes(1);
6360});
6461@@ -73,11 +70,8 @@ describe("probeMattermost", () => {
73707471await probeMattermost("https://mm.example.com", "bot-token", 2500, true);
757276-expect(mockFetchGuard).toHaveBeenCalledWith(
77-expect.objectContaining({
78-policy: { allowPrivateNetwork: true },
79-}),
80-);
73+const [fetchCall] = mockFetchGuard.mock.calls[0] ?? [];
74+expect(fetchCall?.policy).toStrictEqual({ allowPrivateNetwork: true });
8175});
82768377it("returns API error details from JSON response", async () => {
@@ -90,13 +84,14 @@ describe("probeMattermost", () => {
9084release: mockRelease,
9185});
928693-await expect(probeMattermost("https://mm.example.com", "bad-token")).resolves.toEqual(
94-expect.objectContaining({
95-ok: false,
96-status: 401,
97-error: "invalid auth token",
98-}),
99-);
87+const result = await probeMattermost("https://mm.example.com", "bad-token");
88+const { elapsedMs, ...stableResult } = result;
89+expect(stableResult).toStrictEqual({
90+ok: false,
91+status: 401,
92+error: "invalid auth token",
93+});
94+expect(elapsedMs).toBeGreaterThanOrEqual(0);
10095expect(mockRelease).toHaveBeenCalledTimes(1);
10196});
10297@@ -110,25 +105,27 @@ describe("probeMattermost", () => {
110105release: mockRelease,
111106});
112107113-await expect(probeMattermost("https://mm.example.com", "token")).resolves.toEqual(
114-expect.objectContaining({
115-ok: false,
116-status: 403,
117-error: "Forbidden",
118-}),
119-);
108+const result = await probeMattermost("https://mm.example.com", "token");
109+const { elapsedMs, ...stableResult } = result;
110+expect(stableResult).toStrictEqual({
111+ok: false,
112+status: 403,
113+error: "Forbidden",
114+});
115+expect(elapsedMs).toBeGreaterThanOrEqual(0);
120116expect(mockRelease).toHaveBeenCalledTimes(1);
121117});
122118123119it("returns fetch error when request throws", async () => {
124120mockFetchGuard.mockRejectedValueOnce(new Error("network down"));
125121126-await expect(probeMattermost("https://mm.example.com", "token")).resolves.toEqual(
127-expect.objectContaining({
128-ok: false,
129-status: null,
130-error: "network down",
131-}),
132-);
122+const result = await probeMattermost("https://mm.example.com", "token");
123+const { elapsedMs, ...stableResult } = result;
124+expect(stableResult).toStrictEqual({
125+ok: false,
126+status: null,
127+error: "network down",
128+});
129+expect(elapsedMs).toBeGreaterThanOrEqual(0);
133130});
134131});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。