fix: éviter un crash sur updatedBy non peuplé
This commit is contained in:
@@ -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'
|
||||
}]
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -8,7 +8,8 @@
|
||||
"description": ""
|
||||
},
|
||||
"options": {
|
||||
"draftAndPublish": true
|
||||
"draftAndPublish": true,
|
||||
"populateCreatorFields": true
|
||||
},
|
||||
"pluginOptions": {},
|
||||
"attributes": {
|
||||
|
||||
Reference in New Issue
Block a user