Skip to main content

Casos de prueba: módulo File

Documenta los tests unitarios del módulo file (subida, almacenamiento y lectura de archivos con URL firmada).

Specs fuente (src/app/modules/file/):

  • controllers/file.controller.spec.ts
  • services/file.service.spec.ts

Resumen: 2 archivos de spec, 2 suites raíz, 38 tests it() (8 de controlador y 30 de servicio; uno de ellos usa it.each con 2 variantes, por lo que se ejecutan 31 casos en el servicio).


file.controller.spec.ts​

Suite raíz: FileController. El servicio se reemplaza por un mock; el tenant se toma del usuario autenticado.

upload​

TestEscenarioResultado esperadoMocks
should delegate to service with user.tenantId and return translated messageUn usuario sube un archivoLlama a service.upload con el archivo y el tenant del usuario y responde con mensaje traducido y el documentomockService.upload
should propagate errors thrown by the serviceEl servicio rechaza con storage errorEl error se propagamockService.upload

findAll​

TestEscenarioResultado esperadoMocks
should return all files scoped to user tenantListado de archivosLlama a findAll(tenantId) y responde con la listamockService.findAll
should return empty results when no files existSin archivosRespuesta con lista vacíamockService.findAll

findOne​

TestEscenarioResultado esperadoMocks
should return a single file scoped to user tenantArchivo existenteDelegación con id y tenant y respuesta con el archivomockService.findOne
should propagate NotFoundException when file is not foundNo existeLa NotFoundException se propagamockService.findOne

remove​

TestEscenarioResultado esperadoMocks
should delete file scoped to user tenant and return the documentEliminación válidaDelegación con id y tenant y respuesta con el documento eliminadomockService.remove
should propagate NotFoundException when file is not foundNo existeLa NotFoundException se propagamockService.remove

file.service.spec.ts​

Suite raíz: FileService. Mocks: StorageService (subida, borrado y URL firmada), repositorio de archivos, procesador de media (processAudio, processVideo, analyzeAudio, getAudioDuration) y traducción. Las imágenes se convierten a WebP al subir.

upload​

TestEscenarioResultado esperadoMocks
should upload to storage and persist the file documentSubida de una imagenSube al storage bajo tenantId/ con mimetype image/webp, persiste con tipo image y devuelve el documentoStorageService.upload, fileRepository.create
should resolve type "audio" for audio mimetypesMimetype de audioSe persiste con tipo audioupload, create
converts audio to OGG/Opus and stores it with that extensionAudio audio/webm (el navegador graba WebM y WhatsApp no lo reproduce)Llama a processAudio, guarda mimetype audio/ogg y storageKey terminada en .oggprocessAudio, upload, create
persists the duration and waveform of an audioSubida de audioSe persisten durationSeconds (6) y waveform para no decodificar en cada envíoprocessAudio, create
does not attach audio metadata to a non-audio fileSubida de un PDFNo se agregan duración ni ondacreate
validates the duration before convertingAudio de 500 sRechaza y no llama a processAudio (no se paga la conversión de un audio rechazado)getAudioDuration
should resolve type "video" for video mimetypesMimetype de videoSe persiste con tipo videoprocessVideo, create
persists the video thumbnailSubida de videoSe persiste el thumbnail extraídoprocessVideo, create
stores the video even when the thumbnail could not be extractedprocessVideo no obtiene thumbnailEl video se guarda igualmente, sin previewprocessVideo, create
should resolve type "document" for non-media mimetypesMimetype no multimediaSe persiste con tipo documentupload, create
should use empty extension when filename has no dotNombre de archivo sin puntoLa extensión de la clave de storage queda vacíaupload, create
should resolve a signed url for the just-uploaded file instead of the stored (permanent) oneSubida exitosaLa URL devuelta es la firmada (getSignedUrl), no la permanentegetSignedUrl, create
should accept XLSX documents (%s)it.each con application/vnd.ms-excel (sheet.xls) y con el mimetype OOXML (sheet.xlsx)Se aceptan y se persisten como document con su mimetypeupload, create
should reject an image larger than 5 MBImagen mayor a 5 MBLanza BadRequestException y no persistefileRepository.create
should accept an image at or under 5 MBImagen de 5 MB o menosLa subida se resuelve sin errorupload, create
should reject audio shorter than 1 secondAudio de 0,5 sLanza BadRequestException y no persistegetAudioDuration
should reject audio longer than 120 secondsAudio de 121 sLanza BadRequestException y no persistegetAudioDuration
should accept audio within the 1s–120s rangeAudio de 60 sLa subida se resuelve sin errorgetAudioDuration, upload, create
should reject an audio file larger than the 15 MB defense-in-depth capAudio de más de 15 MBLanza BadRequestException; no mide duración ni persistegetAudioDuration, create

storeIncoming​

Almacena archivos recibidos de canales externos (no validados como subida de usuario).

TestEscenarioResultado esperadoMocks
stores the file without validating its mime typeArchivo entrante de documentoSe guarda sin validar el mimetypeupload, create
reads duration and waveform of an incoming audio without re-encoding itAudio entranteLlama a analyzeAudio, no a processAudio, y persiste duración y ondaanalyzeAudio, processAudio, create
stores the audio anyway when it cannot be analyzedanalyzeAudio rechaza con corruptEl audio se guarda igualmenteanalyzeAudio rechaza, create
does not analyze a non-audio fileImagen entranteNo se llama a analyzeAudioanalyzeAudio, create

findAll​

TestEscenarioResultado esperadoMocks
should return all files for the tenantTenant con archivosLlama a findAll(tenantId) y devuelve los mismos documentos (mutados con URL firmada)fileRepository.findAll
should resolve a signed url for every file instead of reusing the stored oneVarios archivosFirma la URL de cada archivo desde su storageKey y la asigna a urlfindAll, getSignedUrl

findOne​

TestEscenarioResultado esperadoMocks
should return the file when foundArchivo del tenantBusca por id y tenant y lo devuelvefindByIdAndTenant
should resolve a signed url from storageKey instead of the stored (permanent) urlArchivo encontradourl es la firmada y distinta de la permanentefindByIdAndTenant, getSignedUrl
should throw NotFoundException when file is not foundfindByIdAndTenant devuelve nullLanza NotFoundException con mensaje traducidofindByIdAndTenant, traducción

remove​

TestEscenarioResultado esperadoMocks
should delete from storage and repository, then return the documentArchivo existenteBorra del storage por storageKey, elimina del repositorio y devuelve el documentofindByIdAndTenant, storage.delete, remove
should throw NotFoundException when file is not foundArchivo inexistenteLanza NotFoundException y no borra del storagefindByIdAndTenant (null)