fix: corriger les mauvais identifiants utilisés (id vs documentId)
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
import {describe, it, expect, vi, afterEach} from 'vitest'
|
||||
|
||||
async function loadLifecycles(strapiMock) {
|
||||
vi.resetModules()
|
||||
global.strapi = strapiMock
|
||||
const mod = await import('../lifecycles.js')
|
||||
return mod
|
||||
}
|
||||
|
||||
describe('afterCreate — notification au soumetteur', () => {
|
||||
afterEach(() => {
|
||||
delete global.strapi
|
||||
})
|
||||
|
||||
it('recherche le user par id (pas par un champ "user" inexistant) et envoie le mail', async () => {
|
||||
const userFindOne = vi.fn(async ({where}) => {
|
||||
if (where.id === 5) return {id: 5, username: 'foo', email: 'foo@bar.com'}
|
||||
return null
|
||||
})
|
||||
const emailSend = vi.fn()
|
||||
|
||||
const strapiMock = {
|
||||
db: {
|
||||
query: vi.fn(uid => {
|
||||
if (uid === 'plugin::users-permissions.user') return {findOne: userFindOne}
|
||||
return {findOne: vi.fn(async () => null)}
|
||||
})
|
||||
},
|
||||
plugins: {
|
||||
email: {services: {email: {send: emailSend}}}
|
||||
}
|
||||
}
|
||||
|
||||
const {afterCreate} = await loadLifecycles(strapiMock)
|
||||
|
||||
await afterCreate({params: {data: {titre: 'Titre', user: {id: 5}}}})
|
||||
|
||||
expect(userFindOne).toHaveBeenCalledWith({where: {id: 5}})
|
||||
expect(emailSend).toHaveBeenCalled()
|
||||
})
|
||||
})
|
||||
@@ -53,8 +53,8 @@ const jwennUserEpiId = async userId => {
|
||||
}
|
||||
|
||||
const user = await strapi.db.query('plugin::users-permissions.user').findOne({
|
||||
where: {user: userId}
|
||||
})
|
||||
where: {id: userId}
|
||||
})
|
||||
|
||||
if (!user) {
|
||||
throw new ApplicationError('Utilisateur introuvable.')
|
||||
|
||||
Reference in New Issue
Block a user