(options?: { presetParamNames?: string[] })
| 820 | |
| 821 | // Helper to mock the pre-fetch calls that happen before spawn |
| 822 | function mockPrefetchCalls(options?: { presetParamNames?: string[] }) { |
| 823 | // Mock getDeploymentUrl (coder whoami) |
| 824 | // Mock getActiveTemplateVersionId (coder templates list) |
| 825 | // Mock getPresetParamNames (coder templates presets list) |
| 826 | // Mock getTemplateRichParameters (coder tokens create + fetch) |
| 827 | execFileAsyncSpy?.mockImplementation((file: string, args: string[]) => { |
| 828 | if (isCoderCommand(file, args, ["whoami", "--output=json"])) { |
| 829 | return createMockExecResult( |
| 830 | Promise.resolve({ |
| 831 | stdout: JSON.stringify([ |
| 832 | { url: "https://coder.example.com", username: "coder-user" }, |
| 833 | ]), |
| 834 | stderr: "", |
| 835 | }) |
| 836 | ); |
| 837 | } |
| 838 | if (isCoderCommand(file, args, ["templates", "list", "--output=json"])) { |
| 839 | return createMockExecResult( |
| 840 | Promise.resolve({ |
| 841 | stdout: JSON.stringify([ |
| 842 | { Template: { name: "my-template", active_version_id: "version-123" } }, |
| 843 | { Template: { name: "tmpl", active_version_id: "version-456" } }, |
| 844 | ]), |
| 845 | stderr: "", |
| 846 | }) |
| 847 | ); |
| 848 | } |
| 849 | if ( |
| 850 | file === "coder" && |
| 851 | args[0] === "templates" && |
| 852 | args[1] === "presets" && |
| 853 | args[2] === "list" |
| 854 | ) { |
| 855 | const paramNames = options?.presetParamNames ?? []; |
| 856 | return createMockExecResult( |
| 857 | Promise.resolve({ |
| 858 | stdout: JSON.stringify([ |
| 859 | { |
| 860 | TemplatePreset: { |
| 861 | Name: "preset", |
| 862 | Parameters: paramNames.map((name) => ({ Name: name })), |
| 863 | }, |
| 864 | }, |
| 865 | ]), |
| 866 | stderr: "", |
| 867 | }) |
| 868 | ); |
| 869 | } |
| 870 | if ( |
| 871 | file === "coder" && |
| 872 | args[0] === "tokens" && |
| 873 | args[1] === "create" && |
| 874 | args[2] === "--lifetime" && |
| 875 | args[3] === "5m" && |
| 876 | args[4] === "--name" |
| 877 | ) { |
| 878 | return createMockExecResult(Promise.resolve({ stdout: "fake-token-123", stderr: "" })); |
| 879 | } |
no test coverage detected