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:
@@ -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[] = []
|
||||
|
||||
Reference in New Issue
Block a user