feat(spotify): implement milestone M1 scaffold
This commit is contained in:
85
skills/spotify/tests/cli.test.ts
Normal file
85
skills/spotify/tests/cli.test.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { test } from "node:test";
|
||||
|
||||
import { runCli } from "../src/cli.js";
|
||||
|
||||
function createBuffer() {
|
||||
let output = "";
|
||||
return {
|
||||
stream: {
|
||||
write(chunk: string) {
|
||||
output += chunk;
|
||||
return true;
|
||||
}
|
||||
},
|
||||
output: () => output
|
||||
};
|
||||
}
|
||||
|
||||
test("prints usage", async () => {
|
||||
const stdout = createBuffer();
|
||||
const stderr = createBuffer();
|
||||
const code = await runCli(["--help"], { stdout: stdout.stream, stderr: stderr.stream });
|
||||
|
||||
assert.equal(code, 0);
|
||||
assert.match(stdout.output(), /Commands:/);
|
||||
assert.equal(stderr.output(), "");
|
||||
});
|
||||
|
||||
test("prints usage for bare invocation", async () => {
|
||||
const stdout = createBuffer();
|
||||
const stderr = createBuffer();
|
||||
const code = await runCli([], { stdout: stdout.stream, stderr: stderr.stream });
|
||||
|
||||
assert.equal(code, 0);
|
||||
assert.match(stdout.output(), /Commands:/);
|
||||
assert.equal(stderr.output(), "");
|
||||
});
|
||||
|
||||
test("rejects unknown command", async () => {
|
||||
const stdout = createBuffer();
|
||||
const stderr = createBuffer();
|
||||
const code = await runCli(["bogus"], { stdout: stdout.stream, stderr: stderr.stream });
|
||||
|
||||
assert.equal(code, 1);
|
||||
assert.equal(stdout.output(), "");
|
||||
assert.match(stderr.output(), /Unknown command: bogus/);
|
||||
});
|
||||
|
||||
test("dispatches known command with json flag", async () => {
|
||||
const stdout = createBuffer();
|
||||
const stderr = createBuffer();
|
||||
const code = await runCli(
|
||||
["search", "Karma Police", "--limit", "3", "--json"],
|
||||
{ stdout: stdout.stream, stderr: stderr.stream },
|
||||
{
|
||||
search(args, deps) {
|
||||
deps.stdout.write(JSON.stringify(args));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
assert.equal(code, 0);
|
||||
assert.deepEqual(JSON.parse(stdout.output()), {
|
||||
command: "search",
|
||||
positional: ["Karma Police"],
|
||||
json: true,
|
||||
public: false,
|
||||
limit: "3"
|
||||
});
|
||||
assert.equal(stderr.output(), "");
|
||||
});
|
||||
|
||||
test("known commands return structured placeholder errors in json mode", async () => {
|
||||
const stdout = createBuffer();
|
||||
const stderr = createBuffer();
|
||||
const code = await runCli(["status", "--json"], { stdout: stdout.stream, stderr: stderr.stream });
|
||||
|
||||
assert.equal(code, 2);
|
||||
assert.deepEqual(JSON.parse(stdout.output()), {
|
||||
ok: false,
|
||||
error: "Command not implemented yet: status"
|
||||
});
|
||||
assert.equal(stderr.output(), "");
|
||||
});
|
||||
Reference in New Issue
Block a user