import assert from "node:assert";
import { describe, it } from "node:test";
import { buildEnvironmentPromptChoices } from "./build-environment-prompt-choices.js";
function makeEnv(environmentType, name, branchName) {
    return {
        name,
        accountName: "acme",
        projectName: "my-project",
        createdOn: null,
        branchName,
        environmentType,
    };
}
function isSeparator(item) {
    return (item != null &&
        typeof item === "object" &&
        item.type === "separator");
}
describe("buildEnvironmentPromptChoices", () => {
    it("groups choices with a Separator header per non-empty bucket", () => {
        const envs = [
            makeEnv("preview", "env-test-staging-1", "staging"),
            makeEnv("working_copy", "env-test-main-abc", "main"),
            makeEnv("production", "env-test-prod-xyz", "main"),
            makeEnv("preview", "env-test-feature-2", "feature-auth"),
        ];
        const choices = buildEnvironmentPromptChoices(envs);
        assert.strictEqual(choices.length, 7);
        assert.ok(isSeparator(choices[0]));
        assert.ok(isSeparator(choices[2]));
        assert.ok(isSeparator(choices[5]));
        assert.deepStrictEqual(choices[1], {
            name: "env-test-main-abc — recommended for local development",
            value: "env-test-main-abc",
        });
        assert.deepStrictEqual(choices[3], {
            name: "feature-auth",
            value: "env-test-feature-2",
            description: "env-test-feature-2",
        });
        assert.deepStrictEqual(choices[4], {
            name: "staging",
            value: "env-test-staging-1",
            description: "env-test-staging-1",
        });
        assert.deepStrictEqual(choices[6], {
            name: "main",
            value: "env-test-prod-xyz",
            description: "env-test-prod-xyz",
        });
    });
    it("skips a Separator for an empty bucket", () => {
        const envs = [
            makeEnv("preview", "env-test-staging-1", "staging"),
            makeEnv("preview", "env-test-feature-2", "feature-auth"),
        ];
        const choices = buildEnvironmentPromptChoices(envs);
        const separators = choices.filter(isSeparator);
        assert.strictEqual(separators.length, 1);
        assert.strictEqual(choices.length, 3);
    });
    it("returns an empty array when there are no envs", () => {
        assert.deepStrictEqual(buildEnvironmentPromptChoices([]), []);
    });
    it("normalizes all working-copy type spellings into the working-copy bucket", () => {
        const envs = [
            makeEnv("development", "env-test-main-1", "main"),
            makeEnv("working_copy", "env-test-main-2", "main"),
            makeEnv("working-copy", "env-test-main-3", "main"),
        ];
        const choices = buildEnvironmentPromptChoices(envs);
        assert.strictEqual(choices.length, 4);
        assert.ok(isSeparator(choices[0]));
    });
    it("places envs with unknown environmentType into an 'Other' bucket at the end", () => {
        const envs = [
            makeEnv("preview", "env-test-staging-1", "staging"),
            makeEnv("staging", "env-test-mystery-zzz", "mystery-branch"),
        ];
        const choices = buildEnvironmentPromptChoices(envs);
        assert.strictEqual(choices.length, 4);
        assert.ok(isSeparator(choices[0]));
        assert.deepStrictEqual(choices[1], {
            name: "staging",
            value: "env-test-staging-1",
            description: "env-test-staging-1",
        });
        assert.ok(isSeparator(choices[2]));
        assert.strictEqual(choices[2].separator, "── Other ──");
        assert.deepStrictEqual(choices[3], {
            name: "mystery-branch",
            value: "env-test-mystery-zzz",
            description: "env-test-mystery-zzz",
        });
    });
});
//# sourceMappingURL=build-environment-prompt-choices.test.js.map