|
|
@ -183,21 +183,28 @@ describe("/api/workflow route", () => { |
|
|
expect(data.error).toBe("Path is not a directory"); |
|
|
expect(data.error).toBe("Path is not a directory"); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it("should reject non-existent directory", async () => { |
|
|
it("should create non-existent directory and continue saving", async () => { |
|
|
mockStat.mockRejectedValue(new Error("ENOENT")); |
|
|
const mockWorkflow = { nodes: [], edges: [] }; |
|
|
|
|
|
mockStat.mockRejectedValue(Object.assign(new Error("ENOENT"), { code: "ENOENT" })); |
|
|
|
|
|
mockMkdir.mockResolvedValue(undefined); |
|
|
|
|
|
mockWriteFile.mockResolvedValue(undefined); |
|
|
|
|
|
|
|
|
const request = createMockPostRequest({ |
|
|
const request = createMockPostRequest({ |
|
|
directoryPath: "/nonexistent/dir", |
|
|
directoryPath: "/nonexistent/dir", |
|
|
filename: "workflow", |
|
|
filename: "workflow", |
|
|
workflow: { nodes: [], edges: [] }, |
|
|
workflow: mockWorkflow, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
const response = await POST(request); |
|
|
const response = await POST(request); |
|
|
const data = await response.json(); |
|
|
const data = await response.json(); |
|
|
|
|
|
|
|
|
expect(response.status).toBe(400); |
|
|
expect(data.success).toBe(true); |
|
|
expect(data.success).toBe(false); |
|
|
expect(mockMkdir).toHaveBeenCalledWith("/nonexistent/dir", { recursive: true }); |
|
|
expect(data.error).toBe("Directory does not exist"); |
|
|
expect(mockWriteFile).toHaveBeenCalledWith( |
|
|
|
|
|
"/nonexistent/dir/workflow.json", |
|
|
|
|
|
JSON.stringify(mockWorkflow, null, 2), |
|
|
|
|
|
"utf-8" |
|
|
|
|
|
); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
it("should continue saving even if subfolder creation fails", async () => { |
|
|
it("should continue saving even if subfolder creation fails", async () => { |
|
|
|