fillGlobal: a field already holding the seeded value is skipped, not rewritten

Seeding exactly the default (allowThemeToggle: true) used to count as unset,
rewrite it and report create on every run. Now: skip (exists), no write. A choice
at its default is still replaced by a different seeded value; editor changes stay.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-10-29 16:39:55 +01:00
co-authored by Claude Opus 5.5
parent 6f56ef4205
commit 37131e9930
6 changed files with 17 additions and 5 deletions
+9
View File
@@ -256,6 +256,15 @@ describe('createSeeder', () => {
expect(first.note).toBe('empty fields filled: mode, toggle')
const look = (await payload.findGlobal({ slug: 'look' as never })) as { greeting: string; mode: string; toggle: boolean }
expect(look).toMatchObject({ greeting: 'Hello', mode: 'system', toggle: false })
// Seeding exactly what is stored (here the default) writes nothing and reports a skip, every run.
await payload.updateGlobal({ slug: 'look' as never, data: { mode: 'light', toggle: true } as never })
const before = ((await payload.findGlobal({ slug: 'look' as never })) as { updatedAt: string }).updatedAt
for (let run = 0; run < 2; run++) {
expect(await seeder().fillGlobal('look', { mode: 'light', toggle: true })).toMatchObject({ status: 'skip (exists)' })
}
expect(((await payload.findGlobal({ slug: 'look' as never })) as { updatedAt: string }).updatedAt).toBe(before)
// A different seeded value still replaces a choice at its default.
expect(await seeder().fillGlobal('look', { mode: 'system', toggle: true })).toMatchObject({ note: 'empty fields filled: mode', status: 'create' })
// An editor's choice that differs from the default stays.
await payload.updateGlobal({ slug: 'look' as never, data: { mode: 'dark' } as never })
await seeder().fillGlobal('look', { mode: 'system' })