fix(core-shared): narrow Payload Field union before accessing name in tests

Payload's Field type is a discriminated union; field.name only exists on
named variants. Tests now narrow on type (and 'name' in field for groups)
before reading variant-specific properties.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-04 20:43:23 +02:00
parent 428346a36d
commit 884b0c01e8
2 changed files with 5 additions and 1 deletions

View File

@@ -3,6 +3,9 @@ import { seoFields } from "./seo-fields";
describe("seoFields", () => {
it("is a group field named 'seo'", () => {
if (seoFields.type !== "group" || !("name" in seoFields)) {
throw new Error("seoFields must be a named group");
}
expect(seoFields.name).toBe("seo");
expect(seoFields.type).toBe("group");
});

View File

@@ -4,8 +4,8 @@ import { slugField } from "./slug-field";
describe("slugField", () => {
it("returns a Payload Field with default name 'slug'", () => {
const field = slugField();
if (field.type !== "text") throw new Error("expected text field");
expect(field.name).toBe("slug");
expect(field.type).toBe("text");
expect(field.required).toBe(true);
expect(field.unique).toBe(true);
expect(field.index).toBe(true);
@@ -13,6 +13,7 @@ describe("slugField", () => {
it("accepts a custom field name", () => {
const field = slugField("permalink");
if (field.type !== "text") throw new Error("expected text field");
expect(field.name).toBe("permalink");
});
});