mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
test(extensions): cast fetch mocks to satisfy tsgo
This commit is contained in:
@@ -16,7 +16,7 @@ function createCfg(): OpenClawConfig {
|
|||||||
|
|
||||||
describe("mattermost reactions", () => {
|
describe("mattermost reactions", () => {
|
||||||
it("adds reactions by calling /users/me then POST /reactions", async () => {
|
it("adds reactions by calling /users/me then POST /reactions", async () => {
|
||||||
const fetchImpl = vi.fn(async (url: any, init?: any) => {
|
const fetchMock = vi.fn(async (url: any, init?: any) => {
|
||||||
if (String(url).endsWith("/api/v4/users/me")) {
|
if (String(url).endsWith("/api/v4/users/me")) {
|
||||||
return new Response(JSON.stringify({ id: "BOT123" }), {
|
return new Response(JSON.stringify({ id: "BOT123" }), {
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -42,15 +42,15 @@ describe("mattermost reactions", () => {
|
|||||||
cfg: createCfg(),
|
cfg: createCfg(),
|
||||||
postId: "POST1",
|
postId: "POST1",
|
||||||
emojiName: "thumbsup",
|
emojiName: "thumbsup",
|
||||||
fetchImpl,
|
fetchImpl: fetchMock as unknown as typeof fetch,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result).toEqual({ ok: true });
|
expect(result).toEqual({ ok: true });
|
||||||
expect(fetchImpl).toHaveBeenCalled();
|
expect(fetchMock).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("returns a Result error when add reaction API call fails", async () => {
|
it("returns a Result error when add reaction API call fails", async () => {
|
||||||
const fetchImpl = vi.fn(async (url: any) => {
|
const fetchMock = vi.fn(async (url: any) => {
|
||||||
if (String(url).endsWith("/api/v4/users/me")) {
|
if (String(url).endsWith("/api/v4/users/me")) {
|
||||||
return new Response(JSON.stringify({ id: "BOT123" }), {
|
return new Response(JSON.stringify({ id: "BOT123" }), {
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -70,7 +70,7 @@ describe("mattermost reactions", () => {
|
|||||||
cfg: createCfg(),
|
cfg: createCfg(),
|
||||||
postId: "POST1",
|
postId: "POST1",
|
||||||
emojiName: "thumbsup",
|
emojiName: "thumbsup",
|
||||||
fetchImpl,
|
fetchImpl: fetchMock as unknown as typeof fetch,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result.ok).toBe(false);
|
expect(result.ok).toBe(false);
|
||||||
@@ -80,7 +80,7 @@ describe("mattermost reactions", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("removes reactions by calling /users/me then DELETE /users/:id/posts/:postId/reactions/:emoji", async () => {
|
it("removes reactions by calling /users/me then DELETE /users/:id/posts/:postId/reactions/:emoji", async () => {
|
||||||
const fetchImpl = vi.fn(async (url: any, init?: any) => {
|
const fetchMock = vi.fn(async (url: any, init?: any) => {
|
||||||
if (String(url).endsWith("/api/v4/users/me")) {
|
if (String(url).endsWith("/api/v4/users/me")) {
|
||||||
return new Response(JSON.stringify({ id: "BOT123" }), {
|
return new Response(JSON.stringify({ id: "BOT123" }), {
|
||||||
status: 200,
|
status: 200,
|
||||||
@@ -101,10 +101,10 @@ describe("mattermost reactions", () => {
|
|||||||
cfg: createCfg(),
|
cfg: createCfg(),
|
||||||
postId: "POST1",
|
postId: "POST1",
|
||||||
emojiName: "thumbsup",
|
emojiName: "thumbsup",
|
||||||
fetchImpl,
|
fetchImpl: fetchMock as unknown as typeof fetch,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(result).toEqual({ ok: true });
|
expect(result).toEqual({ ok: true });
|
||||||
expect(fetchImpl).toHaveBeenCalled();
|
expect(fetchMock).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ describe("thread-ownership plugin", () => {
|
|||||||
process.env.SLACK_BOT_USER_ID = "U999";
|
process.env.SLACK_BOT_USER_ID = "U999";
|
||||||
|
|
||||||
originalFetch = globalThis.fetch;
|
originalFetch = globalThis.fetch;
|
||||||
globalThis.fetch = vi.fn();
|
globalThis.fetch = vi.fn() as unknown as typeof globalThis.fetch;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
|
|||||||
Reference in New Issue
Block a user