feat(prd-6): verify workflow triggers and add assignee_trigger (#13)

This commit is contained in:
Vlad Mocanu committed 2026-02-25 21:43:37 +00:00
1 parent 095c2c2429
commit a129a15f61
5 files changed
+71 -19

No files matched your search

+26 -14
View File
@@ -8,20 +8,28 @@ import {
jest,
setSystemTime,
} from "bun:test";
import fs from "fs/promises";
import { downloadCommentImages } from "../src/github/utils/image-downloader";
import type { CommentWithImages } from "../src/github/utils/image-downloader";
import {
downloadCommentImages,
_fsForTest,
type CommentWithImages,
} from "../src/github/utils/image-downloader";
import type { Octokits } from "../src/github/api/client";
describe("downloadCommentImages", () => {
let consoleLogSpy: any;
let consoleWarnSpy: any;
let consoleErrorSpy: any;
let fsMkdirSpy: any;
let fsWriteFileSpy: any;
let fetchSpy: any;
let savedServerUrl: string | undefined;
// Store originals for restoration
const origMkdir = _fsForTest.mkdir;
const origWriteFile = _fsForTest.writeFile;
// Mock functions for fs operations
const mockMkdir = jest.fn().mockResolvedValue(undefined);
const mockWriteFile = jest.fn().mockResolvedValue(undefined);
beforeEach(() => {
// Pin GITHUB_SERVER_URL so tests pass regardless of runner environment.
// The image-downloader reads process.env directly at call time.
@@ -33,9 +41,11 @@ describe("downloadCommentImages", () => {
consoleWarnSpy = spyOn(console, "warn").mockImplementation(() => {});
consoleErrorSpy = spyOn(console, "error").mockImplementation(() => {});
// Spy on fs methods
fsMkdirSpy = spyOn(fs, "mkdir").mockResolvedValue(undefined);
fsWriteFileSpy = spyOn(fs, "writeFile").mockResolvedValue(undefined);
// Override _fsForTest methods directly — works cross-platform
mockMkdir.mockClear();
mockWriteFile.mockClear();
_fsForTest.mkdir = mockMkdir as any;
_fsForTest.writeFile = mockWriteFile as any;
// Set fake system time for consistent filenames
setSystemTime(new Date("2024-01-01T00:00:00.000Z")); // 1704067200000
@@ -49,11 +59,13 @@ describe("downloadCommentImages", () => {
delete process.env.GITHUB_SERVER_URL;
}
// Restore original fs methods
_fsForTest.mkdir = origMkdir;
_fsForTest.writeFile = origWriteFile;
consoleLogSpy.mockRestore();
consoleWarnSpy.mockRestore();
consoleErrorSpy.mockRestore();
fsMkdirSpy.mockRestore();
fsWriteFileSpy.mockRestore();
if (fetchSpy) fetchSpy.mockRestore();
setSystemTime(); // Reset to real time
});
@@ -80,7 +92,7 @@ describe("downloadCommentImages", () => {
await downloadCommentImages(mockOctokit, "owner", "repo", comments);
expect(fsMkdirSpy).toHaveBeenCalledWith("/tmp/github-images", {
expect(mockMkdir).toHaveBeenCalledWith("/tmp/github-images", {
recursive: true,
});
});
@@ -153,7 +165,7 @@ describe("downloadCommentImages", () => {
});
expect(fetchSpy).toHaveBeenCalledWith(signedUrl);
expect(fsWriteFileSpy).toHaveBeenCalledWith(
expect(mockWriteFile).toHaveBeenCalledWith(
"/tmp/github-images/image-1704067200000-0.png",
Buffer.from(mockArrayBuffer),
);
@@ -628,7 +640,7 @@ describe("downloadCommentImages", () => {
);
// Reset for next iteration
fsWriteFileSpy.mockClear();
mockWriteFile.mockClear();
callIndex++;
}
});
@@ -721,7 +733,7 @@ describe("downloadCommentImages", () => {
});
expect(fetchSpy).toHaveBeenCalledWith(signedUrl);
expect(fsWriteFileSpy).toHaveBeenCalledWith(
expect(mockWriteFile).toHaveBeenCalledWith(
"/tmp/github-images/image-1704067200000-0.png",
Buffer.from(mockArrayBuffer),
);