Skip to content

Commit ac9ac1c

Browse files
fix: preserve relation and locale data in lifecycle hooks (#1040) (#1044)
* fix: preserve relation and locale data in lifecycle hooks (#1040) Fixes an issue where lifecycle results only contained relation counts instead of full relation objects, and locale data was not being properly passed to getEntry. The fix ensures: - Complete entries with full relations are fetched instead of using lifecycle results with counts - Locale from lifecycle result is passed to maintain i18n consistency - Status 'published' is always passed to ensure only published content is indexed - Added comprehensive tests for the fix * fix: missing empty result guard * docs: add comment explaining Strapi 5 publishedAt behavior Added clarifying comment that publishedAt is always set in Strapi 5 even when draftAndPublish is disabled, with link to migration docs. * refactor: auto format code * fix: typo in content-types.js * refactor: cleanup getEntries' locale In strapi v5, locale is part of strapi core right now, so checking locale is not needed. More information: https://docs.strapi.io/cms/migration/v4-to-v5/breaking-changes/i18n-content-manager-locale * refactor: extract query options into separate variable for cleaner code Simplify strapi.documents().findOne() call by extracting query parameters into a queryOptions object * Add 'publishedAt' to mock entries in tests Updated mock entries to include 'publishedAt' attribute for Strapi v5 compatibility. * Wrap fetchedEntry in an array for Meilisearch calls --------- Co-authored-by: Michel Díaz <contacto@michelmartinez.com>
1 parent 5e27e17 commit ac9ac1c

File tree

7 files changed

+740
-28
lines changed

7 files changed

+740
-28
lines changed

server/src/__tests__/content-types.test.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ describe('Tests content types', () => {
2929
expect(contentTypes.sort()).toEqual(
3030
[
3131
'api::about.about',
32+
'api::article.article',
3233
'api::movie.movie',
3334
'api::restaurant.restaurant',
3435
'plugin::users-permissions.user',
@@ -176,6 +177,8 @@ describe('Tests content types', () => {
176177
documentId: '200',
177178
fields: '*',
178179
populate: '*',
180+
locale: undefined,
181+
status: 'published',
179182
})
180183
expect(strapiMock.documents('').findOne).toHaveBeenCalledTimes(1)
181184
expect(entry).toEqual([{ id: 1 }])
@@ -203,6 +206,8 @@ describe('Tests content types', () => {
203206
populate: {
204207
subClass: true,
205208
},
209+
locale: undefined,
210+
status: 'published',
206211
})
207212
expect(strapiMock.documents('').findOne).toHaveBeenCalledTimes(1)
208213
expect(entry).toEqual([{ id: 1 }])

0 commit comments

Comments
 (0)