fix: valider data.user/data.artistes avant déréférencement

This commit is contained in:
2026-07-04 11:38:02 +04:00
parent c4f45f712a
commit 6f77c17003
6 changed files with 64 additions and 0 deletions
@@ -81,4 +81,22 @@ describe('commentaire.create', () => {
await expect(controller.create(ctx)).rejects.toThrow('Texte introuvable.')
expect(commentaireDocuments.create).not.toHaveBeenCalled()
})
it('refuse sans planter quand data.user est absent', async () => {
const {strapi, userDbQuery} = buildStrapi()
const controller = createController({strapi})
const ctx = buildCtx(buildData({user: undefined}))
await expect(controller.create(ctx)).rejects.toThrow('Informations manquantes.')
expect(userDbQuery.findOne).not.toHaveBeenCalled()
})
it('refuse sans planter quand data.parole est absent', async () => {
const {strapi, paroleDbQuery} = buildStrapi()
const controller = createController({strapi})
const ctx = buildCtx(buildData({parole: undefined}))
await expect(controller.create(ctx)).rejects.toThrow('Informations manquantes.')
expect(paroleDbQuery.findOne).not.toHaveBeenCalled()
})
})
@@ -8,6 +8,10 @@ module.exports = createCoreController('api::commentaire.commentaire', ({strapi})
const {body} = ctx.request
let {data} = body
if (!data?.user?.id || !data?.parole) {
throw new ApplicationError('Informations manquantes.')
}
const user = await strapi.db.query('plugin::users-permissions.user').findOne({
where: {id: data.user.id}
})