From c4f45f712a3ed08e9f2967e0d9e280d30546e696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Sat, 4 Jul 2026 11:37:40 +0400 Subject: [PATCH] =?UTF-8?q?fix:=20=C3=A9viter=20un=20crash=20sur=20updated?= =?UTF-8?q?By=20non=20peupl=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../parole/__tests__/lifecycles.test.js | 34 +++++++++++++++++++ .../parole/content-types/parole/lifecycles.js | 2 +- .../parole/content-types/parole/schema.json | 3 +- 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/api/parole/content-types/parole/__tests__/lifecycles.test.js b/src/api/parole/content-types/parole/__tests__/lifecycles.test.js index 9f0ddb9..a93d267 100644 --- a/src/api/parole/content-types/parole/__tests__/lifecycles.test.js +++ b/src/api/parole/content-types/parole/__tests__/lifecycles.test.js @@ -117,3 +117,37 @@ describe('beforeUpdate — notifications Telegram/Revolt', () => { expect(strapiMock.log.error).toHaveBeenCalledWith(expect.stringContaining('Revolt')) }) }) + +describe('afterUpdate — historique de différence', () => { + afterEach(() => { + delete global.strapi + }) + + it("n'échoue pas quand updatedBy n'est pas peuplé", async () => { + const entityServiceUpdate = vi.fn(async () => {}) + const strapiMock = { + entityService: {update: entityServiceUpdate} + } + + const {afterUpdate} = await loadLifecycles(strapiMock) + + const event = { + result: {id: 1, difference: [], updatedBy: undefined}, + state: {diff: {path: 'transcription', jsonDiff: []}} + } + + await afterUpdate(event) + + expect(entityServiceUpdate).toHaveBeenCalledWith('api::parole.parole', 1, { + data: { + difference: [{ + admin_user: null, + paroles: 'transcription', + jsonDiff: [], + date: expect.any(Date), + sources: 'transcription' + }] + } + }) + }) +}) diff --git a/src/api/parole/content-types/parole/lifecycles.js b/src/api/parole/content-types/parole/lifecycles.js index 89e31ff..fbc8c15 100644 --- a/src/api/parole/content-types/parole/lifecycles.js +++ b/src/api/parole/content-types/parole/lifecycles.js @@ -256,7 +256,7 @@ module.exports = { difference: [ ...result.difference, { - admin_user: result.updatedBy.id, + admin_user: result.updatedBy?.id ?? null, paroles: state.diff.path, jsonDiff: state.diff.jsonDiff, date: new Date(), diff --git a/src/api/parole/content-types/parole/schema.json b/src/api/parole/content-types/parole/schema.json index a1ef029..0f6c54e 100644 --- a/src/api/parole/content-types/parole/schema.json +++ b/src/api/parole/content-types/parole/schema.json @@ -8,7 +8,8 @@ "description": "" }, "options": { - "draftAndPublish": true + "draftAndPublish": true, + "populateCreatorFields": true }, "pluginOptions": {}, "attributes": {