faafd99ef8
Auto Tag Develop / tag (push) Successful in 8s
MR unique regroupant tout le module M5 « Tickets de pesée » (remplace les MR empilées #140/#141/#142/#143).
## Périmètre
- **ERP-188** — Page liste des tickets de pesée + export XLSX (colonnes Fournisseur/Client/Autre + Statut).
- **ERP-189** — Écran « Ajouter » (4 champs en haut, 2 blocs de pesée, pesée bascule/manuelle, date+heure horodatée à la validation).
- **ERP-190** — Écran « Modifier » + bouton Imprimer.
- **ERP-191** — i18n + libellés + branchement site courant.
- **ERP-192** — Bon de pesée PDF généré côté back (template Twig → Dompdf), endpoint `GET /api/weighing_tickets/{id}/print.pdf`.
- **ERP-193** — Cycle de vie brouillon/validé (status DRAFT/VALIDATED, numéro attribué à la validation), DSD saisi conservé en pesée manuelle, retours métier design.
## Vérifications
- Back : tests Logistique + architecture verts, php-cs-fixer propre, migrations appliquées (dev + test).
- Front : suite Vitest complète verte, ESLint propre.
Base : `develop` — contient les 16 commits du M5 (rien d'autre).
Reviewed-on: #144
Co-authored-by: tristan <tristan@yuno.malio.fr>
Co-committed-by: tristan <tristan@yuno.malio.fr>
62 lines
2.5 KiB
TypeScript
62 lines
2.5 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
|
|
// useApi / useI18n sont des auto-imports Nuxt : on les expose en globals.
|
|
const mockPost = vi.hoisted(() => vi.fn())
|
|
vi.stubGlobal('useApi', () => ({ post: mockPost }))
|
|
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
|
|
|
const { useWeighbridge } = await import('../useWeighbridge')
|
|
|
|
describe('useWeighbridge', () => {
|
|
beforeEach(() => {
|
|
mockPost.mockReset()
|
|
})
|
|
|
|
it('AUTO : POST { mode: AUTO } sans toast et renvoie la lecture', async () => {
|
|
mockPost.mockResolvedValue({ weight: 23187, dsd: 42, mode: 'AUTO' })
|
|
const { triggerAuto } = useWeighbridge()
|
|
|
|
const reading = await triggerAuto()
|
|
|
|
expect(mockPost).toHaveBeenCalledWith(
|
|
'/weighbridge_readings',
|
|
{ mode: 'AUTO' },
|
|
expect.objectContaining({ toast: false }),
|
|
)
|
|
expect(reading).toEqual({ weight: 23187, dsd: 42, mode: 'AUTO' })
|
|
})
|
|
|
|
it('MANUAL : POST { mode: MANUAL, weight, dsd } et renvoie la lecture', async () => {
|
|
// Le DSD est saisi par l'opérateur et conservé tel quel (ERP-193).
|
|
mockPost.mockResolvedValue({ weight: 5000, dsd: 16619, mode: 'MANUAL' })
|
|
const { triggerManual } = useWeighbridge()
|
|
|
|
const reading = await triggerManual(5000, 16619)
|
|
|
|
expect(mockPost).toHaveBeenCalledWith(
|
|
'/weighbridge_readings',
|
|
{ mode: 'MANUAL', weight: 5000, dsd: 16619 },
|
|
expect.objectContaining({ toast: false }),
|
|
)
|
|
expect(reading.dsd).toBe(16619)
|
|
})
|
|
|
|
it('erreur (RG-5.06) : extractWeighbridgeError privilégie le detail du 503', () => {
|
|
const { extractWeighbridgeError } = useWeighbridge()
|
|
const error = { response: { status: 503, _data: { title: 'Pont bascule indisponible', detail: 'Passez en pesée manuelle.' } } }
|
|
expect(extractWeighbridgeError(error)).toBe('Passez en pesée manuelle.')
|
|
})
|
|
|
|
it('erreur sans payload exploitable : retombe sur le libellé i18n générique', () => {
|
|
const { extractWeighbridgeError } = useWeighbridge()
|
|
expect(extractWeighbridgeError(new Error('network')))
|
|
.toBe('logistique.weighingTickets.form.weighbridge.unavailable')
|
|
})
|
|
|
|
it('triggerAuto propage l\'erreur API (gestion par l\'écran)', async () => {
|
|
mockPost.mockRejectedValue({ response: { status: 503 } })
|
|
const { triggerAuto } = useWeighbridge()
|
|
await expect(triggerAuto()).rejects.toBeDefined()
|
|
})
|
|
})
|