UNPKG

@railway/mcp-server

Version:
116 lines (114 loc) 4.29 kB
import "../error-handling-mxVa5oOu.js"; import { checkRailwayCliStatus, runRailwayCommand } from "../core-BMlc7cvF.js"; import { getLinkedProjectInfo } from "../projects-ENU6yIz7.js"; import "../services-BXZqOgoN.js"; import { getCliFeatureSupport, getRailwayVersion } from "../version-BriONvFH.js"; import { listDeployments } from "../deployment-DXcNTO8k.js"; import { afterEach, beforeEach, describe, globalExpect, it, vi } from "../vi.bdSIJ99Y-CjNqA1ej.js"; //#region src/cli/deployment.test.ts vi.mock("./core"); vi.mock("./error-handling"); vi.mock("./projects"); vi.mock("./version"); describe("listDeployments", () => { const mockWorkspacePath = "/test/workspace"; const mockProject = { id: "test-project-id", name: "test-project", createdAt: "2024-01-01T00:00:00Z", updatedAt: "2024-01-01T00:00:00Z" }; beforeEach(() => { vi.clearAllMocks(); const mockOutput = "Deployment 1\nDeployment 2\nDeployment 3"; vi.mocked(runRailwayCommand).mockResolvedValue({ output: mockOutput, stderr: "", stdout: mockOutput }); vi.mocked(checkRailwayCliStatus).mockResolvedValue(); vi.mocked(getLinkedProjectInfo).mockResolvedValue({ success: true, project: mockProject }); vi.mocked(getCliFeatureSupport).mockResolvedValue({ logs: { args: { lines: true, filter: true } }, deployment: { list: true } }); vi.mocked(getRailwayVersion).mockResolvedValue("4.10.0"); }); afterEach(() => { vi.restoreAllMocks(); }); describe("successful cases", () => { it("should list deployments with default options", async () => { const result = await listDeployments({ workspacePath: mockWorkspacePath }); globalExpect(result.success).toBe(true); globalExpect(runRailwayCommand).toHaveBeenCalledWith("railway deployment list --limit 20", mockWorkspacePath); }); it("should list deployments with JSON output", async () => { const result = await listDeployments({ workspacePath: mockWorkspacePath, json: true }); globalExpect(result.success).toBe(true); globalExpect(runRailwayCommand).toHaveBeenCalledWith("railway deployment list --limit 20 --json", mockWorkspacePath); }); it("should list deployments with service filter", async () => { const result = await listDeployments({ workspacePath: mockWorkspacePath, service: "my-api-service" }); globalExpect(result.success).toBe(true); globalExpect(runRailwayCommand).toHaveBeenCalledWith("railway deployment list --service my-api-service --limit 20", mockWorkspacePath); }); it("should list deployments with environment filter", async () => { const mockOutput = "Environment deployment output"; vi.mocked(runRailwayCommand).mockResolvedValue({ output: mockOutput, stderr: "", stdout: mockOutput }); const result = await listDeployments({ workspacePath: mockWorkspacePath, environment: "staging" }); globalExpect(result.success).toBe(true); globalExpect(runRailwayCommand).toHaveBeenCalledWith("railway deployment list --environment staging --limit 20", mockWorkspacePath); }); it("should list deployments with custom limit", async () => { const mockOutput = "Limited deployment output"; vi.mocked(runRailwayCommand).mockResolvedValue({ output: mockOutput, stderr: "", stdout: mockOutput }); const result = await listDeployments({ workspacePath: mockWorkspacePath, limit: 50 }); globalExpect(result.success).toBe(true); globalExpect(runRailwayCommand).toHaveBeenCalledWith("railway deployment list --limit 50", mockWorkspacePath); }); }); it("should return error when CLI version does not support deployment list", async () => { vi.mocked(getCliFeatureSupport).mockResolvedValue({ logs: { args: { lines: false, filter: false } }, deployment: { list: false } }); vi.mocked(getRailwayVersion).mockResolvedValue("4.9.0"); const result = await listDeployments({ workspacePath: mockWorkspacePath }); globalExpect(result.success).toBe(false); if (result.success) throw new Error("Expected error"); globalExpect(result.error).toBe("Railway CLI version 4.9.0 does not support 'deployment list' command. Please upgrade to version 4.10.0 or later."); }); }); //#endregion export { }; //# sourceMappingURL=deployment.test.js.map