| 1 | import { describe, it, expect } from "vitest"; |
| 2 | import { createVersionedSpec } from "../src/versions"; |
| 3 | |
| 4 | type VersionedSpec = (version?: string) => unknown; |
| 5 | describe("test createVersionedSpec", () => { |
| 6 | it("test it returns the correct version when versions are correctly sorted", async () => { |
| 7 | const versionedSpec = createVersionedSpec("fig", ["1.0.0", "2.0.0", "3.0.0"]) as VersionedSpec; |
| 8 | expect(await versionedSpec()).toStrictEqual({ |
| 9 | versionedSpecPath: "fig/3.0.0", |
| 10 | version: undefined, |
| 11 | }); |
| 12 | expect(await versionedSpec("1.3.1")).toStrictEqual({ |
| 13 | versionedSpecPath: "fig/1.0.0", |
| 14 | version: "1.3.1", |
| 15 | }); |
| 16 | expect(await versionedSpec("2.0.0")).toStrictEqual({ |
| 17 | versionedSpecPath: "fig/2.0.0", |
| 18 | version: "2.0.0", |
| 19 | }); |
| 20 | }); |
| 21 | |
| 22 | it("test it returns the correct version when versions are NOT correctly sorted", async () => { |
| 23 | const versionedSpec = createVersionedSpec("fig", ["2.0.0", "1.0.0", "3.0.0"]) as VersionedSpec; |
| 24 | expect(await versionedSpec()).toStrictEqual({ |
| 25 | versionedSpecPath: "fig/3.0.0", |
| 26 | version: undefined, |
| 27 | }); |
| 28 | expect(await versionedSpec("1.3.1")).toStrictEqual({ |
| 29 | versionedSpecPath: "fig/1.0.0", |
| 30 | version: "1.3.1", |
| 31 | }); |
| 32 | expect(await versionedSpec("2.0.0")).toStrictEqual({ |
| 33 | versionedSpecPath: "fig/2.0.0", |
| 34 | version: "2.0.0", |
| 35 | }); |
| 36 | }); |
| 37 | }); |