|
| 1 | +/** |
| 2 | + * E2E tests for `argos builds` commands. |
| 3 | + * Requires ARGOS_TOKEN env var. |
| 4 | + * Optional: ARGOS_API_BASE_URL env var. |
| 5 | + * |
| 6 | + * Usage: |
| 7 | + * ARGOS_TOKEN=xxx node e2e/builds.js |
| 8 | + * ARGOS_TOKEN=xxx ARGOS_API_BASE_URL=https://api.argos-ci.dev:4001/v2 NODE_OPTIONS=--use-system-ca pnpm -C packages/cli exec node e2e/builds.js |
| 9 | + */ |
| 10 | + |
| 11 | +import { assert, run } from "./utils.js"; |
| 12 | + |
| 13 | +const token = process.env.ARGOS_TOKEN; |
| 14 | +const apiBaseURL = process.env.ARGOS_API_BASE_URL; |
| 15 | + |
| 16 | +if (!token) { |
| 17 | + console.error( |
| 18 | + "Usage: ARGOS_TOKEN=xxx [ARGOS_API_BASE_URL=<url>] node e2e/builds.js", |
| 19 | + ); |
| 20 | + process.exit(1); |
| 21 | +} |
| 22 | + |
| 23 | +function envWith(overrides = {}) { |
| 24 | + return { ...process.env, ...overrides }; |
| 25 | +} |
| 26 | + |
| 27 | +const baseEnv = apiBaseURL |
| 28 | + ? envWith({ ARGOS_API_BASE_URL: apiBaseURL }) |
| 29 | + : process.env; |
| 30 | + |
| 31 | +// --- builds get: authentication tests --- |
| 32 | + |
| 33 | +console.log("\nTest failing build commands (builds get):"); |
| 34 | + |
| 35 | +// No token → error + exit 1 |
| 36 | +try { |
| 37 | + run(["builds", "get", "1"], { ...baseEnv, ARGOS_TOKEN: "" }); |
| 38 | + assert(false, "Missing token should exit with code 1"); |
| 39 | +} catch (err) { |
| 40 | + assert(err.status !== 0, "Exit code 1 when no token"); |
| 41 | + assert( |
| 42 | + err.stderr.includes("No Argos token found"), |
| 43 | + "Error message includes 'No Argos token found'", |
| 44 | + ); |
| 45 | +} |
| 46 | + |
| 47 | +try { |
| 48 | + run( |
| 49 | + [ |
| 50 | + "builds", |
| 51 | + "get", |
| 52 | + "https://app.argos-ci.com/argos-ci/argos-javascript/builds/1", |
| 53 | + ], |
| 54 | + { ...baseEnv, ARGOS_TOKEN: "" }, |
| 55 | + ); |
| 56 | + assert(false, "Missing token should exit with code 1"); |
| 57 | +} catch (err) { |
| 58 | + assert(err.status !== 0, "Exit code 1 when no token"); |
| 59 | + assert( |
| 60 | + err.stderr.includes("No Argos token found"), |
| 61 | + "Error message includes 'No Argos token found'", |
| 62 | + ); |
| 63 | +} |
| 64 | + |
| 65 | +// Unknown build number |
| 66 | +try { |
| 67 | + run(["builds", "get", "999999"], { |
| 68 | + ...baseEnv, |
| 69 | + ARGOS_TOKEN: token, |
| 70 | + }); |
| 71 | + assert(false, "Unknown build number should exit with code 1"); |
| 72 | +} catch (err) { |
| 73 | + assert(err.status !== 0, "Unknown build number: exit code 1"); |
| 74 | + assert( |
| 75 | + err.stderr.includes("Error:"), |
| 76 | + "Unknown build number: human-readable error message", |
| 77 | + ); |
| 78 | +} |
| 79 | + |
| 80 | +// Invalid build number format |
| 81 | +try { |
| 82 | + run(["builds", "get", "not-a-number"], { |
| 83 | + ...baseEnv, |
| 84 | + ARGOS_TOKEN: token, |
| 85 | + }); |
| 86 | + assert(false, "Invalid build number should exit with code 1"); |
| 87 | +} catch (err) { |
| 88 | + assert(err.status !== 0, "Invalid build number: exit code 1"); |
| 89 | + assert( |
| 90 | + err.stderr.includes("valid build number or Argos build URL"), |
| 91 | + "Invalid build reference: human-readable error message", |
| 92 | + ); |
| 93 | +} |
| 94 | + |
| 95 | +// --- builds snapshots: authentication tests --- |
| 96 | + |
| 97 | +console.log("\nTest failing build commands (builds snapshots):"); |
| 98 | + |
| 99 | +// No token → error + exit 1 |
| 100 | +try { |
| 101 | + run(["builds", "snapshots", "1"], { ...baseEnv, ARGOS_TOKEN: "" }); |
| 102 | + assert(false, "Missing token should exit with code 1"); |
| 103 | +} catch (err) { |
| 104 | + assert(err.status !== 0, "Exit code 1 when no token"); |
| 105 | + assert( |
| 106 | + err.stderr.includes("No Argos token found"), |
| 107 | + "Error message includes 'No Argos token found'", |
| 108 | + ); |
| 109 | +} |
0 commit comments