test: update use correct check instead of unsafe unwrap
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { beforeEach, describe, expect, it } from "vitest";
|
|
||||||
import { AppErrorVariant } from "@/error";
|
import { AppErrorVariant } from "@/error";
|
||||||
import { getProjectConfigPath } from "@/model/projectConfig";
|
import { getProjectConfigPath } from "@/model/projectConfig";
|
||||||
|
import { beforeEach, describe, expect, it } from "vitest";
|
||||||
import { InMemoryFileSystem } from "../../tests/helpers/InMemoryFileSystem";
|
import { InMemoryFileSystem } from "../../tests/helpers/InMemoryFileSystem";
|
||||||
import { addProjectTag } from "./addProjectTag";
|
import { addProjectTag } from "./addProjectTag";
|
||||||
import { loadProjectConfig } from "./loadProjectConfig";
|
import { loadProjectConfig } from "./loadProjectConfig";
|
||||||
@@ -24,8 +24,10 @@ describe("addProjectTag", () => {
|
|||||||
expect(result.value.config.tags).toEqual(["bug"]);
|
expect(result.value.config.tags).toEqual(["bug"]);
|
||||||
|
|
||||||
const loaded = await loadProjectConfig(fs, folder);
|
const loaded = await loadProjectConfig(fs, folder);
|
||||||
expect(loaded._unsafeUnwrap().exists).toBe(true);
|
expect(loaded.isOk()).toBe(true);
|
||||||
expect(loaded._unsafeUnwrap().config.tags).toEqual(["bug"]);
|
if (loaded.isErr()) return;
|
||||||
|
expect(loaded.value.exists).toBe(true);
|
||||||
|
expect(loaded.value.config.tags).toEqual(["bug"]);
|
||||||
expect(await fs.readFile(getProjectConfigPath(folder))).toContain("bug");
|
expect(await fs.readFile(getProjectConfigPath(folder))).toContain("bug");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -47,7 +49,9 @@ describe("addProjectTag", () => {
|
|||||||
folderPath: folder,
|
folderPath: folder,
|
||||||
tag: "frontend",
|
tag: "frontend",
|
||||||
});
|
});
|
||||||
expect(result._unsafeUnwrap().config.tags).toEqual(["bug", "frontend"]);
|
expect(result.isOk()).toBe(true);
|
||||||
|
if (result.isErr()) return;
|
||||||
|
expect(result.value.config.tags).toEqual(["bug", "frontend"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("trims tag and rejects empty", async () => {
|
it("trims tag and rejects empty", async () => {
|
||||||
@@ -63,7 +67,9 @@ describe("addProjectTag", () => {
|
|||||||
folderPath: folder,
|
folderPath: folder,
|
||||||
tag: " docs ",
|
tag: " docs ",
|
||||||
});
|
});
|
||||||
expect(trimmed._unsafeUnwrap().config.tags).toEqual(["docs"]);
|
expect(trimmed.isOk()).toBe(true);
|
||||||
|
if (trimmed.isErr()) return;
|
||||||
|
expect(trimmed.value.config.tags).toEqual(["docs"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects missing folder", async () => {
|
it("rejects missing folder", async () => {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
|
||||||
import { AppErrorVariant } from "@/error";
|
import { AppErrorVariant } from "@/error";
|
||||||
|
import { describe, expect, it } from "vitest";
|
||||||
import { parseProjectConfig } from "./parseProjectConfig";
|
import { parseProjectConfig } from "./parseProjectConfig";
|
||||||
|
|
||||||
describe("parseProjectConfig", () => {
|
describe("parseProjectConfig", () => {
|
||||||
@@ -11,17 +11,23 @@ describe("parseProjectConfig", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("accepts empty / missing tags", () => {
|
it("accepts empty / missing tags", () => {
|
||||||
expect(parseProjectConfig("")._unsafeUnwrap().tags).toEqual([]);
|
let result = parseProjectConfig("");
|
||||||
expect(parseProjectConfig("tags: []\n")._unsafeUnwrap().tags).toEqual(
|
expect(result.isOk()).toBe(true);
|
||||||
[],
|
if (result.isErr()) return;
|
||||||
);
|
expect(result.value.tags).toEqual([]);
|
||||||
|
result = parseProjectConfig("tags: []\n");
|
||||||
|
expect(result.isOk()).toBe(true);
|
||||||
|
if (result.isErr()) return;
|
||||||
|
expect(result.value.tags).toEqual([]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("dedupes and trims tags", () => {
|
it("dedupes and trims tags", () => {
|
||||||
const result = parseProjectConfig(
|
const result = parseProjectConfig(
|
||||||
"tags:\n - bug\n - bug \n - frontend\n",
|
"tags:\n - bug\n - bug \n - frontend\n",
|
||||||
);
|
);
|
||||||
expect(result._unsafeUnwrap().tags).toEqual(["bug", "frontend"]);
|
expect(result.isOk()).toBe(true);
|
||||||
|
if (result.isErr()) return;
|
||||||
|
expect(result.value.tags).toEqual(["bug", "frontend"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("rejects invalid YAML", () => {
|
it("rejects invalid YAML", () => {
|
||||||
|
|||||||
@@ -8,12 +8,16 @@ describe("serializeProjectConfig", () => {
|
|||||||
expect(yaml).toContain("bug");
|
expect(yaml).toContain("bug");
|
||||||
expect(yaml).toContain("docs");
|
expect(yaml).toContain("docs");
|
||||||
const parsed = parseProjectConfig(yaml);
|
const parsed = parseProjectConfig(yaml);
|
||||||
expect(parsed._unsafeUnwrap().tags).toEqual(["bug", "docs"]);
|
expect(parsed.isOk()).toBe(true);
|
||||||
|
if (parsed.isErr()) return;
|
||||||
|
expect(parsed.value.tags).toEqual(["bug", "docs"]);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("serializes empty tags", () => {
|
it("serializes empty tags", () => {
|
||||||
const yaml = serializeProjectConfig({ tags: [] });
|
const yaml = serializeProjectConfig({ tags: [] });
|
||||||
const parsed = parseProjectConfig(yaml);
|
const parsed = parseProjectConfig(yaml);
|
||||||
expect(parsed._unsafeUnwrap().tags).toEqual([]);
|
expect(parsed.isOk()).toBe(true);
|
||||||
|
if (parsed.isErr()) return;
|
||||||
|
expect(parsed.value.tags).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user