fix(dashboard): ensure file/import API calls are project-scoped in tests

Update 4 test files to pass projectId="project-1" to hooks/components
and assert it flows through to the API layer:
- useFileBrowser: fetchFileList receives (taskId, path, projectId)
- useFileEditor: fetchFileContent/saveFileContent receive projectId
- FileBrowser: deleteFile/renameFile/copyFile/moveFile receive projectId
- GitHubImportModal: apiImportGitHubIssue/Pull receive projectId

All 6653 tests pass across 242 test files.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
gsxdsm
2026-04-12 21:40:34 -07:00
parent e5b1bb1abe
commit a10dfe5f21
4 changed files with 20 additions and 19 deletions

View File

@@ -66,6 +66,7 @@ const defaultProps = {
onNavigate: vi.fn(),
workspace: "test-ws",
onRefresh: vi.fn(),
projectId: "project-1",
};
function renderFileBrowser(overrides: Partial<typeof defaultProps> = {}) {
@@ -433,7 +434,7 @@ describe("FileBrowser", () => {
expect(dangerBtn).not.toBeNull();
fireEvent.click(dangerBtn!);
await waitFor(() => {
expect(mockDeleteFile).toHaveBeenCalledWith("test-ws", "readme.md");
expect(mockDeleteFile).toHaveBeenCalledWith("test-ws", "readme.md", "project-1");
expect(onRefresh).toHaveBeenCalled();
});
});
@@ -501,7 +502,7 @@ describe("FileBrowser", () => {
);
fireEvent.click(dialogRename!.closest("button")!);
await waitFor(() => {
expect(mockRenameFile).toHaveBeenCalledWith("test-ws", "readme.md", "new-readme.md");
expect(mockRenameFile).toHaveBeenCalledWith("test-ws", "readme.md", "new-readme.md", "project-1");
expect(onRefresh).toHaveBeenCalled();
});
});
@@ -543,7 +544,7 @@ describe("FileBrowser", () => {
);
fireEvent.click(dialogCopy!.closest("button")!);
await waitFor(() => {
expect(mockCopyFile).toHaveBeenCalledWith("test-ws", "readme.md", "backup/readme.md");
expect(mockCopyFile).toHaveBeenCalledWith("test-ws", "readme.md", "backup/readme.md", "project-1");
expect(onRefresh).toHaveBeenCalled();
});
});
@@ -576,7 +577,7 @@ describe("FileBrowser", () => {
);
fireEvent.click(dialogMove!.closest("button")!);
await waitFor(() => {
expect(mockMoveFile).toHaveBeenCalledWith("test-ws", "readme.md", "docs/readme.md");
expect(mockMoveFile).toHaveBeenCalledWith("test-ws", "readme.md", "docs/readme.md", "project-1");
expect(onRefresh).toHaveBeenCalled();
});
});

View File

@@ -383,7 +383,7 @@ describe("GitHubImportModal", () => {
]);
vi.mocked(apiImportGitHubIssue).mockResolvedValueOnce(mockTask);
render(<GitHubImportModal isOpen={true} onClose={onClose} onImport={onImport} tasks={[]} />);
render(<GitHubImportModal isOpen={true} onClose={onClose} onImport={onImport} tasks={[]} projectId="project-1" />);
await waitFor(() => {
expect(screen.getByText("First Issue")).toBeTruthy();
@@ -393,7 +393,7 @@ describe("GitHubImportModal", () => {
fireEvent.click(screen.getByRole("button", { name: /Import$/i }));
await waitFor(() => {
expect(apiImportGitHubIssue).toHaveBeenCalledWith("dustinbyrne", "kb", 1);
expect(apiImportGitHubIssue).toHaveBeenCalledWith("dustinbyrne", "kb", 1, "project-1");
expect(onImport).toHaveBeenCalledWith(mockTask);
expect(onClose).toHaveBeenCalled();
});
@@ -745,7 +745,7 @@ describe("GitHubImportModal", () => {
vi.mocked(apiFetchGitHubPulls).mockResolvedValueOnce(mockPulls);
vi.mocked(apiImportGitHubPull).mockResolvedValueOnce(mockPRTask);
render(<GitHubImportModal isOpen={true} onClose={onClose} onImport={onImport} tasks={[]} />);
render(<GitHubImportModal isOpen={true} onClose={onClose} onImport={onImport} tasks={[]} projectId="project-1" />);
// Switch to Pull Requests tab
fireEvent.click(screen.getByRole("tab", { name: /Pull Requests/i }));
@@ -761,7 +761,7 @@ describe("GitHubImportModal", () => {
fireEvent.click(screen.getByRole("button", { name: /Import$/i }));
await waitFor(() => {
expect(apiImportGitHubPull).toHaveBeenCalledWith("dustinbyrne", "kb", 1);
expect(apiImportGitHubPull).toHaveBeenCalledWith("dustinbyrne", "kb", 1, "project-1");
expect(onImport).toHaveBeenCalledWith(mockPRTask);
expect(onClose).toHaveBeenCalled();
});

View File

@@ -94,7 +94,7 @@ describe("useFileBrowser", () => {
.mockRejectedValueOnce(new Error("boom"))
.mockResolvedValueOnce(response("src", ["index.ts"]));
const { result } = renderHook(() => useFileBrowser("FN-001", true));
const { result } = renderHook(() => useFileBrowser("FN-001", true, "project-1"));
await waitFor(() => {
expect(result.current.error).toBe("boom");
@@ -108,16 +108,16 @@ describe("useFileBrowser", () => {
expect(result.current.error).toBeNull();
await waitFor(() => {
expect(mockFetchFileList).toHaveBeenLastCalledWith("FN-001", "src");
expect(mockFetchFileList).toHaveBeenLastCalledWith("FN-001", "src", "project-1");
expect(result.current.entries.map((entry) => entry.name)).toEqual(["index.ts"]);
});
});
it("normalizes '.' path to undefined when calling fetchFileList", async () => {
const { result } = renderHook(() => useFileBrowser("FN-001", true));
const { result } = renderHook(() => useFileBrowser("FN-001", true, "project-1"));
await waitFor(() => {
expect(mockFetchFileList).toHaveBeenCalledWith("FN-001", undefined);
expect(mockFetchFileList).toHaveBeenCalledWith("FN-001", undefined, "project-1");
});
act(() => {
@@ -125,12 +125,12 @@ describe("useFileBrowser", () => {
});
await waitFor(() => {
expect(mockFetchFileList).toHaveBeenLastCalledWith("FN-001", undefined);
expect(mockFetchFileList).toHaveBeenLastCalledWith("FN-001", undefined, "project-1");
});
});
it("passes non-dot paths directly to fetchFileList", async () => {
const { result } = renderHook(() => useFileBrowser("FN-001", true));
const { result } = renderHook(() => useFileBrowser("FN-001", true, "project-1"));
await waitFor(() => {
expect(mockFetchFileList).toHaveBeenCalled();
@@ -141,7 +141,7 @@ describe("useFileBrowser", () => {
});
await waitFor(() => {
expect(mockFetchFileList).toHaveBeenLastCalledWith("FN-001", "subdir");
expect(mockFetchFileList).toHaveBeenLastCalledWith("FN-001", "subdir", "project-1");
});
});

View File

@@ -67,7 +67,7 @@ describe("useFileEditor", () => {
it("fetches file content when enabled and filePath is set", async () => {
mockFetchFileContent.mockResolvedValueOnce(contentResponse("file body"));
const { result } = renderHook(() => useFileEditor("FN-001", "README.md", true));
const { result } = renderHook(() => useFileEditor("FN-001", "README.md", true, "project-1"));
await waitFor(() => {
expect(result.current.loading).toBe(true);
@@ -78,7 +78,7 @@ describe("useFileEditor", () => {
expect(result.current.content).toBe("file body");
});
expect(mockFetchFileContent).toHaveBeenCalledWith("FN-001", "README.md");
expect(mockFetchFileContent).toHaveBeenCalledWith("FN-001", "README.md", "project-1");
});
it("sets content and originalContent from fetch response", async () => {
@@ -164,7 +164,7 @@ describe("useFileEditor", () => {
mockFetchFileContent.mockResolvedValueOnce(contentResponse("original"));
mockSaveFileContent.mockResolvedValueOnce(saveResponse());
const { result } = renderHook(() => useFileEditor("FN-001", "file.txt", true));
const { result } = renderHook(() => useFileEditor("FN-001", "file.txt", true, "project-1"));
await waitFor(() => {
expect(result.current.loading).toBe(false);
@@ -178,7 +178,7 @@ describe("useFileEditor", () => {
await result.current.save();
});
expect(mockSaveFileContent).toHaveBeenCalledWith("FN-001", "file.txt", "updated");
expect(mockSaveFileContent).toHaveBeenCalledWith("FN-001", "file.txt", "updated", "project-1");
});
it("save updates originalContent and mtime after success", async () => {