"use strict";
var import_vitest = require("vitest");
var import_package_ref = require("./package-ref");
const path = "/my/path";
const prefixedUlid = "intver_01HF58RDKE3M7K5RJ5XZ7GF6HE";
const uuid = "a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a11";
const name = "myintegration";
(0, import_vitest.describe)("parsePackageRef", () => {
  (0, import_vitest.test)("parse empty string should return undefined", () => {
    const ref = "";
    const result = (0, import_package_ref.parsePackageRef)(ref);
    (0, import_vitest.expect)(result).toBeUndefined();
  });
  (0, import_vitest.test)("parse with invalid version should return undefined", () => {
    const ref0 = `${name}@lol`;
    const ref1 = `${name}@>>1`;
    const ref2 = `${name}@1.0.b`;
    const result0 = (0, import_package_ref.parsePackageRef)(ref0);
    const result1 = (0, import_package_ref.parsePackageRef)(ref1);
    const result2 = (0, import_package_ref.parsePackageRef)(ref2);
    (0, import_vitest.expect)(result0).toBeUndefined();
    (0, import_vitest.expect)(result1).toBeUndefined();
    (0, import_vitest.expect)(result2).toBeUndefined();
  });
  (0, import_vitest.test)("parse with an absolute path should return path", () => {
    const ref = path;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    const expected = { type: "path", path: ref };
    (0, import_vitest.expect)(result).toEqual(expected);
  });
  (0, import_vitest.test)("parse with a prefixed ULID sets `id` type", () => {
    const ref = prefixedUlid;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    const expected = { type: "id", id: ref };
    (0, import_vitest.expect)(result).toEqual(expected);
  });
  (0, import_vitest.test)("parse with a legacy UUID sets `id` type", () => {
    const ref = uuid;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    const expected = { type: "id", id: ref };
    (0, import_vitest.expect)(result).toEqual(expected);
  });
  (0, import_vitest.test)("parse with a name and version should return name and version", () => {
    const version = "1.0.0";
    const ref = `${name}@${version}`;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    const expected = { type: "name", name, version };
    (0, import_vitest.expect)(result).toEqual(expected);
  });
  (0, import_vitest.test)("parse with a name and latest should return name and latest", () => {
    const version = "latest";
    const ref = `${name}@${version}`;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    const expected = { type: "name", name, version };
    (0, import_vitest.expect)(result).toEqual(expected);
  });
  (0, import_vitest.test)("parse with only a name should return name and latest", () => {
    const ref = name;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    const expected = { type: "name", name, version: "latest" };
    (0, import_vitest.expect)(result).toEqual(expected);
  });
  (0, import_vitest.test)("parse with a package type and a name should return the pkg, name and latest", () => {
    const ref = `integration:${name}`;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    const expected = { type: "name", name, version: "latest", pkg: "integration" };
    (0, import_vitest.expect)(result).toEqual(expected);
  });
  (0, import_vitest.test)("parse with a package type, a name and a version should return all", () => {
    const ref = `integration:${name}@1.0.0`;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    const expected = { type: "name", name, version: "1.0.0", pkg: "integration" };
    (0, import_vitest.expect)(result).toEqual(expected);
  });
  (0, import_vitest.test)("parse with a package type and a version should return undefined", () => {
    const ref = `plugin:@1.0.0`;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    (0, import_vitest.expect)(result).toBeUndefined();
  });
  (0, import_vitest.test)("parse with an invalid package type should return undefined", () => {
    const ref = `bot:${name}@1.0.0`;
    const result = (0, import_package_ref.parsePackageRef)(ref);
    (0, import_vitest.expect)(result).toBeUndefined();
  });
});
(0, import_vitest.describe)("formatPackageRef", () => {
  (0, import_vitest.test)("format with a path should return path", () => {
    const ref = { type: "path", path };
    const result = (0, import_package_ref.formatPackageRef)(ref);
    (0, import_vitest.expect)(result).toEqual(ref.path);
  });
  (0, import_vitest.test)("format with a prefixed ULID uses `id` type", () => {
    const ref = { type: "id", id: prefixedUlid };
    const result = (0, import_package_ref.formatPackageRef)(ref);
    (0, import_vitest.expect)(result).toEqual(ref.id);
  });
  (0, import_vitest.test)("format with a legacy UUID uses `id` type", () => {
    const ref = { type: "id", id: uuid };
    const result = (0, import_package_ref.formatPackageRef)(ref);
    (0, import_vitest.expect)(result).toEqual(ref.id);
  });
  (0, import_vitest.test)("format with a name and version should return name and version", () => {
    const version = "1.0.0";
    const ref = { type: "name", name, version };
    const result = (0, import_package_ref.formatPackageRef)(ref);
    (0, import_vitest.expect)(result).toEqual(`${name}@${version}`);
  });
});
//# sourceMappingURL=package-ref.test.js.map
