EnterpriseController testing - 22/05/2026
1. Dead code et refactor
Section titled “1. Dead code et refactor”- Le
if (!$user) -> 401present dans chacune des 6 methodes est inatteignable : le middlewareauth:apidu groupe renvoie deja 401 avant d’entrer dans le controller. - Incoherence d’acces :
indexetstorerenvoient 403 pour un non-owner, maisshow/update/destroy/updateStorefrontn’ont aucun check de role — un non-owner (ou un owner tiers) tombe sur un 404 via le scopewhere('owner_id', $user->id). Comportement sûr (pas de fuite de donnees) mais reponse incoherente d’une route a l’autre.
2. Tests de chaque route — approche features-first (non-unit)
Section titled “2. Tests de chaque route — approche features-first (non-unit)”Routes du groupe ['auth:api', 'banned', 'verified', 'onboarding'].
2.1 index — GET /api/enterprises
Section titled “2.1 index — GET /api/enterprises”- utilisateur non authentifie -> 401
- utilisateur authentifie avec role !== owner -> 403 (“Only owners can access enterprises.”)
- owner -> 200, renvoie uniquement ses propres
EnterpriseProfile(scopeowner_id) ; les entreprises d’autres owners sont exclues
2.2 store — POST /api/enterprises
Section titled “2.2 store — POST /api/enterprises”- utilisateur non authentifie -> 401
- role !== owner -> 403 (“Only owners can create enterprises.”)
- validation :
namemanquant -> 422 ;name> 255 -> 422 ;sirenmanquant -> 422 ;sirenpas exactement 9 chiffres -> 422 ;emailformat invalide -> 422 ;phone> 20 -> 422 - happy path : cree une
EnterpriseProfilerattachee a l’owner connecte (owner_id= user), 200 - geocoding : l’
addressest geocodee via la BAN (Http) ; succes ->latitude/longitudepre-remplies ; echec / 0 resultat ->latitude/longitudenull (echec silencieux, la creation reussit quand meme)
2.3 show — GET /api/enterprises/{id}
Section titled “2.3 show — GET /api/enterprises/{id}”- utilisateur non authentifie -> 401
- enterprise appartenant a l’owner connecte -> 200
idinexistant -> 404 (“Enterprise not found.”)- enterprise appartenant a un AUTRE owner -> 404 (scope
owner_id) - pas de check de role : un worker tombe sur 404 (aucune enterprise scoped a son id)
2.4 update — PUT /api/enterprises/{id}
Section titled “2.4 update — PUT /api/enterprises/{id}”- utilisateur non authentifie -> 401
- enterprise inexistante ou n’appartenant pas a l’owner -> 404
- validation :
name> 255 /sirenmauvais format /emailinvalide /phone> 20 -> 422 - update partiel : seuls les champs presents dans le payload sont modifies ; un champ absent garde sa valeur
- changement d’
address-> re-geocoding ; succes ->latitude/longitudemises a jour - geocoding en echec sur changement d’adresse ->
latitude/longitudesont mises a null (et non conservees) :getCoordinatesFromAddressrenvoienullsans throw, letry/catchdu controller ne sert a rien et$coords['latitude'] ?? nullecritnull. Comportement destructif a signaler en section 1. - si la position est propagee (lat/lng presents dans l’updateData) ->
EnterpriseService::propagatePositionToOpenMissionsest appele - reponse : 200 avec l’entreprise fraiche
2.5 destroy — DELETE /api/enterprises/{id}
Section titled “2.5 destroy — DELETE /api/enterprises/{id}”- utilisateur non authentifie -> 401
- enterprise inexistante ou non possedee -> 404
- enterprise avec au moins une mission active (status hors
completed/cancel) -> 422 (“Cannot delete enterprise with active missions.”) - enterprise sans mission, ou avec uniquement des missions
completed/cancel-> supprimee (hard delete :EnterpriseProfilen’utilise PAS SoftDeletes), 200 - echec du delete -> 500 (“Failed to delete enterprise.”) — chemin d’erreur non force en test
2.6 updateStorefront — POST /api/enterprises/{id}/storefront
Section titled “2.6 updateStorefront — POST /api/enterprises/{id}/storefront”- utilisateur non authentifie -> 401
- enterprise inexistante ou non possedee -> 404
- validation :
storefront_photomanquant -> 422 ; mime hors jpeg/jpg/png -> 422 ; > 10 Mo -> 422 - happy path : remplace l’image via
ImageService::replace, persiste le nouveaufront_picture, 200 ; la response contientpath+url+ l’enterprisefraiche