fix(db-mongodb): localized dates being returned as date objects instead of strings (#12354)

Fixes https://github.com/payloadcms/payload/issues/12334

We weren't passing locale through to the Date transformer function so
localized dates were being read as objects instead of strings.
This commit is contained in:
Paul
2025-05-10 17:15:15 -07:00
committed by GitHub
parent 3701de5056
commit c43891b2ba
6 changed files with 90 additions and 0 deletions

View File

@@ -27,6 +27,7 @@ import {
defaultLocale as englishLocale,
englishTitle,
hungarianLocale,
localizedDateFieldsSlug,
localizedPostsSlug,
localizedSortSlug,
portugueseLocale,
@@ -431,6 +432,32 @@ describe('Localization', () => {
})
})
describe('Localized date', () => {
it('can create a localized date', async () => {
const document = await payload.create({
collection: localizedDateFieldsSlug,
data: {
localizedDate: new Date().toISOString(),
date: new Date().toISOString(),
},
})
expect(document.localizedDate).toBeTruthy()
})
it('data is typed as string', async () => {
const document = await payload.create({
collection: localizedDateFieldsSlug,
data: {
localizedDate: new Date().toISOString(),
date: new Date().toISOString(),
},
})
expect(typeof document.localizedDate).toBe('string')
expect(typeof document.date).toBe('string')
})
})
describe('Localized Sort Count', () => {
const expectedTotalDocs = 5
const posts: LocalizedSort[] = []