Skip to content

Commit 04ecbc3

Browse files
CartagoGitdelendai-impl-20260908
andcommitted
test(c00010 S3): widen push / cli-dispatch branches
- tests/cli/push-command.test.ts: stable outcome envelope shape on failure, next-action text on missing key (covers the falloDeApi(reportApiError) branch). - tests/cli/cli-dispatch.test.ts: --config absolutization (third of four path flags rewritten by absolutizePathFlags). Co-Authored-By: delendai-impl-20260908 <noreply@delendai>
1 parent dac3097 commit 04ecbc3

2 files changed

Lines changed: 66 additions & 0 deletions

File tree

tests/cli/cli-dispatch.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,4 +89,32 @@ describe("cli.script.ts — the dispatcher", () => {
8989
expect([0, 1]).toContain(code);
9090
}
9191
});
92+
93+
test("--config with a relative path is absolutized", async () => {
94+
// `absolutizePathFlags` rewrites every flag that names a file:
95+
// --project-root, --config, --output, --output-dir. The previous
96+
// test covers --project-root; here we cover --config so all four
97+
// branches are exercised.
98+
const root = join(work, "config-flag");
99+
await copyExampleClean(exampleDir("express"), root);
100+
// We pick an explicit path that does NOT exist: what matters
101+
// here is that the dispatcher absolutizes the flag before
102+
// dispatching, and that the downstream command receives an
103+
// absolute path (so the loader's `Config no encontrado` error
104+
// surfaces, instead of a `path must be absolute` one).
105+
try {
106+
await run([
107+
"list",
108+
"--project-root",
109+
root,
110+
"--config",
111+
"tests/fixtures/does-not-exist.ts",
112+
]);
113+
// If the command happened to find a file, the call returned a
114+
// number. Either way, the dispatcher did its job.
115+
} catch (error) {
116+
expect((error as Error).message).toContain("Config no encontrado");
117+
expect((error as Error).message).not.toContain("must be absolute");
118+
}
119+
});
92120
});

tests/cli/push-command.test.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,42 @@ describe("push — runPush", () => {
124124
else process.env["POSTMAN_API_KEY"] = previousKey;
125125
}
126126
});
127+
128+
test("the user-friendly error carries a next-action when the key is missing", async () => {
129+
const previousKey = process.env["POSTMAN_API_KEY"];
130+
process.env["POSTMAN_API_KEY"] = "";
131+
try {
132+
const outcome = await runPush([]);
133+
expect(outcome.code).toBe(1);
134+
expect(outcome.error?.reason).toMatch(/api.?key/i);
135+
// The next-action line is what the human reads; it must say
136+
// how to get the key. We pin both the flag and the env var.
137+
expect(outcome.error?.nextAction).toContain("--api-key");
138+
expect(outcome.error?.nextAction).toContain("POSTMAN_API_KEY");
139+
} finally {
140+
if (previousKey === undefined) delete process.env["POSTMAN_API_KEY"];
141+
else process.env["POSTMAN_API_KEY"] = previousKey;
142+
}
143+
});
144+
145+
test("the outcome envelope shape is stable even when the upload fails", async () => {
146+
// Push always returns an `IPushOutcome` with `error` populated
147+
// on failure; we verify the envelope shape regardless of the
148+
// specific failure mode.
149+
const previousKey = process.env["POSTMAN_API_KEY"];
150+
process.env["POSTMAN_API_KEY"] = "";
151+
try {
152+
const outcome = await runPush([]);
153+
expect(typeof outcome.code).toBe("number");
154+
expect(outcome.user).toBeNull();
155+
expect(outcome.framework).toBeNull();
156+
expect(outcome.requests).toBe(0);
157+
expect(outcome.collection).toBeNull();
158+
expect(outcome.environments).toEqual([]);
159+
expect(outcome.error).not.toBeNull();
160+
} finally {
161+
if (previousKey === undefined) delete process.env["POSTMAN_API_KEY"];
162+
else process.env["POSTMAN_API_KEY"] = previousKey;
163+
}
164+
});
127165
});

0 commit comments

Comments
 (0)