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'))
|
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: [
|
difference: [
|
||||||
...result.difference,
|
...result.difference,
|
||||||
{
|
{
|
||||||
admin_user: result.updatedBy.id,
|
admin_user: result.updatedBy?.id ?? null,
|
||||||
paroles: state.diff.path,
|
paroles: state.diff.path,
|
||||||
jsonDiff: state.diff.jsonDiff,
|
jsonDiff: state.diff.jsonDiff,
|
||||||
date: new Date(),
|
date: new Date(),
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
"description": ""
|
"description": ""
|
||||||
},
|
},
|
||||||
"options": {
|
"options": {
|
||||||
"draftAndPublish": true
|
"draftAndPublish": true,
|
||||||
|
"populateCreatorFields": true
|
||||||
},
|
},
|
||||||
"pluginOptions": {},
|
"pluginOptions": {},
|
||||||
"attributes": {
|
"attributes": {
|
||||||
|
|||||||
Reference in New Issue
Block a user