From e0447b682a0c432ac1d52d2798264fc1cd34937b Mon Sep 17 00:00:00 2001 From: "hivecommons-hive[bot]" Date: Sun, 27 Sep 2026 10:15:16 -0400 Subject: [PATCH] test(meow): cover the missing-issue-number throw and the response-body cancel fallback Closes #205 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: hivecommons-hive[bot] --- __tests__/issueCommentTest/meow.test.ts | 42 ++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/__tests__/issueCommentTest/meow.test.ts b/__tests__/issueCommentTest/meow.test.ts index a87aeb6b..eec62e7f 100644 --- a/__tests__/issueCommentTest/meow.test.ts +++ b/__tests__/issueCommentTest/meow.test.ts @@ -5,7 +5,7 @@ import { setupServer } from 'msw/node' import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' import { handleIssueComment } from '../../src/issueComment/handleIssueComment' -import { meowConfig } from '../../src/issueComment/meow' +import { meow, meowConfig } from '../../src/issueComment/meow' import * as comments from '../../src/utils/comments' import issueCommentEvent from '../fixtures/issues/issueCommentEvent.json' import * as utils from '../testUtils' @@ -492,4 +492,44 @@ describe('/meow', () => { expect(cancelled).toBe(true) }) + + it('throws when the payload has no issue number', async () => { + const fetchSpy = vi.spyOn(globalThis, 'fetch') + const context = contextFor('/meow') + delete (context.payload as { issue?: unknown }).issue + + await expect(meow(context)).rejects.toThrow( + 'github context payload missing issue number', + ) + + expect(fetchSpy).not.toHaveBeenCalled() + expect(createComment).not.toHaveBeenCalled() + }) + + it('still retries when cancelling the response body fails', async () => { + const stream = new ReadableStream({ + cancel() { + throw new Error('cancel failed') + }, + }) + vi + .spyOn(globalThis, 'fetch') + .mockResolvedValueOnce(new Response(stream, { status: 503 })) + .mockResolvedValueOnce( + Response.json([{ url: 'https://cdn2.thecatapi.com/images/cat.jpg' }]), + ) + const debug = vi.spyOn(core, 'debug').mockImplementation(() => {}) + + await handleIssueComment(contextFor('/meow')) + + expect(debug).toHaveBeenCalledWith( + expect.stringContaining('could not cancel cat api response body'), + ) + expect(createComment).toHaveBeenCalledWith( + expect.anything(), + expect.anything(), + 1, + '![cat]()', + ) + }) })