fix(machines) : pièce supprimée ne bloque plus la machine
Auto Tag Develop / tag (push) Successful in 9s
Auto Tag Develop / tag (push) Successful in 9s
Un lien machine_piece_links orphelin (pieceid pointant vers une pièce
supprimée) faisait charger les documents via l'id du lien
(GET /documents/piece/{linkId}) → 404 + toast bloquant, et la catégorie
restait affichée à vide.
- front : useEntityDocuments ne charge plus les documents pour un node
pending (refreshDocuments + ensureDocumentsLoaded) + test
- back : migration Version20260529150000 réparant les 2 FK CASCADE vers
pieces (fk_mpl_piece, fk_cfv_piece) jamais appliquées par
Version20260528090000, avec nettoyage des orphelins (1 mpl + 3 cfv)
This commit is contained in:
@@ -56,7 +56,9 @@ export function useEntityDocuments(deps: EntityDocumentsDeps) {
|
||||
// CRUD operations
|
||||
const refreshDocuments = async () => {
|
||||
const e = entity()
|
||||
if (!e?.id || e._structurePiece) return
|
||||
// Pending / category-only nodes carry the link id (not a real entity id) and
|
||||
// have no backing piece/composant — never request documents for them.
|
||||
if (!e?.id || e._structurePiece || e.pendingEntity) return
|
||||
loadingDocuments.value = true
|
||||
try {
|
||||
const result: any = await loadDocumentsFn(e.id, { updateStore: false })
|
||||
@@ -70,7 +72,8 @@ export function useEntityDocuments(deps: EntityDocumentsDeps) {
|
||||
}
|
||||
|
||||
const ensureDocumentsLoaded = async () => {
|
||||
if (documentsLoaded.value || !entity()?.id) return
|
||||
const e = entity()
|
||||
if (documentsLoaded.value || !e?.id || e.pendingEntity) return
|
||||
await refreshDocuments()
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
||||
|
||||
import { useEntityDocuments } from '~/composables/useEntityDocuments'
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Mocks
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
const mockLoadDocumentsByPiece = vi.fn()
|
||||
const mockLoadDocumentsByComponent = vi.fn()
|
||||
|
||||
vi.mock('~/composables/useDocuments', () => ({
|
||||
useDocuments: () => ({
|
||||
loadDocumentsByPiece: mockLoadDocumentsByPiece,
|
||||
loadDocumentsByComponent: mockLoadDocumentsByComponent,
|
||||
uploadDocuments: vi.fn(),
|
||||
deleteDocument: vi.fn(),
|
||||
updateDocument: vi.fn(),
|
||||
}),
|
||||
}))
|
||||
|
||||
vi.mock('~/utils/documentPreview', () => ({
|
||||
canPreviewDocument: () => true,
|
||||
}))
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks()
|
||||
})
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// refreshDocuments — pending / orphan entities
|
||||
// ---------------------------------------------------------------------------
|
||||
describe('refreshDocuments', () => {
|
||||
it('does NOT load documents for a pending piece node (orphan link id is not a piece id)', async () => {
|
||||
// A category-only / pending piece node: its `id` is the machinePieceLink id,
|
||||
// there is no real piece behind it (pieceId is null).
|
||||
const pendingNode = {
|
||||
id: 'cl48179803369dd93b4a90b784', // machinePieceLink id, NOT a piece id
|
||||
pieceId: null,
|
||||
pendingEntity: true,
|
||||
documents: [],
|
||||
}
|
||||
|
||||
const { refreshDocuments } = useEntityDocuments({
|
||||
entity: () => pendingNode,
|
||||
entityType: 'piece',
|
||||
})
|
||||
|
||||
await refreshDocuments()
|
||||
|
||||
expect(mockLoadDocumentsByPiece).not.toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('loads documents for a real piece node using its piece id', async () => {
|
||||
mockLoadDocumentsByPiece.mockResolvedValue({ success: true, data: [] })
|
||||
|
||||
const realNode = {
|
||||
id: 'clrealpieceid000000000000',
|
||||
pieceId: 'clrealpieceid000000000000',
|
||||
pendingEntity: false,
|
||||
documents: [],
|
||||
}
|
||||
|
||||
const { refreshDocuments } = useEntityDocuments({
|
||||
entity: () => realNode,
|
||||
entityType: 'piece',
|
||||
})
|
||||
|
||||
await refreshDocuments()
|
||||
|
||||
expect(mockLoadDocumentsByPiece).toHaveBeenCalledWith('clrealpieceid000000000000', { updateStore: false })
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user