11import { Test , type TestingModule } from '@nestjs/testing' ;
2-
3- jest . mock ( '../../lib/query-timeout' , ( ) => ( {
4- withQueryTimeout : jest . fn ( ( _sequelize , _timeout , cb ) => cb ( { } ) ) ,
5- } ) ) ;
62import { getModelToken } from '@nestjs/sequelize' ;
73import { createMock } from '@golevelup/ts-jest' ;
84import {
@@ -23,6 +19,10 @@ import { UserModel } from '../user/user.model';
2319import { WorkspaceItemUserModel } from '../workspaces/models/workspace-items-users.model' ;
2420import { Time } from '../../lib/time' ;
2521
22+ jest . mock ( '../../lib/query-timeout' , ( ) => ( {
23+ withQueryTimeout : jest . fn ( ( _sequelize , _timeout , cb ) => cb ( { } ) ) ,
24+ } ) ) ;
25+
2626describe ( 'FileRepository' , ( ) => {
2727 let repository : FileRepository ;
2828 let fileModel : typeof FileModel ;
@@ -534,13 +534,66 @@ describe('FileRepository', () => {
534534 } ) ;
535535 } ) ;
536536
537+ describe ( 'findTrashedNotExpired' , ( ) => {
538+ const userId = 1 ;
539+ const limit = 10 ;
540+ const offset = 0 ;
541+
542+ it ( 'When no expiration date is set, then it should return all trashed files regardless of when they were trashed' , async ( ) => {
543+ jest . spyOn ( fileModel , 'findAll' ) . mockResolvedValue ( [ ] ) ;
544+
545+ await repository . findTrashedNotExpired ( userId , null , limit , offset ) ;
546+
547+ expect ( fileModel . findAll ) . toHaveBeenCalledWith (
548+ expect . objectContaining ( {
549+ where : { userId, status : FileStatus . TRASHED } ,
550+ } ) ,
551+ ) ;
552+ } ) ;
553+
554+ it ( 'When an expiration date is set, then it should only return trashed files that have not yet expired' , async ( ) => {
555+ const cutoffDate = new Date ( '2026-03-04' ) ;
556+ jest . spyOn ( fileModel , 'findAll' ) . mockResolvedValue ( [ ] ) ;
557+
558+ await repository . findTrashedNotExpired ( userId , cutoffDate , limit , offset ) ;
559+
560+ expect ( fileModel . findAll ) . toHaveBeenCalledWith (
561+ expect . objectContaining ( {
562+ where : {
563+ userId,
564+ status : FileStatus . TRASHED ,
565+ updatedAt : { [ Op . gte ] : cutoffDate } ,
566+ } ,
567+ } ) ,
568+ ) ;
569+ } ) ;
570+
571+ it ( 'When retrieving trashed files, then it should also load the name of the folder each file belongs to' , async ( ) => {
572+ jest . spyOn ( fileModel , 'findAll' ) . mockResolvedValue ( [ ] ) ;
573+
574+ await repository . findTrashedNotExpired ( userId , null , limit , offset ) ;
575+
576+ expect ( fileModel . findAll ) . toHaveBeenCalledWith (
577+ expect . objectContaining ( {
578+ include : expect . arrayContaining ( [
579+ expect . objectContaining ( {
580+ as : 'folder' ,
581+ attributes : [ 'plainName' , 'removed' , 'deleted' , 'uuid' ] ,
582+ required : false ,
583+ } ) ,
584+ ] ) ,
585+ } ) ,
586+ ) ;
587+ } ) ;
588+ } ) ;
589+
537590 describe ( 'findTrashedNotExpiredInWorkspace' , ( ) => {
538591 const createdBy = v4 ( ) ;
539592 const workspaceId = v4 ( ) ;
540593 const limit = 10 ;
541594 const offset = 0 ;
542595
543- it ( 'When cutoffDate is null , then it should query trashed files without a date filter ' , async ( ) => {
596+ it ( 'When no expiration date is set , then it should return all trashed workspace files regardless of when they were trashed ' , async ( ) => {
544597 jest . spyOn ( fileModel , 'findAll' ) . mockResolvedValue ( [ ] ) ;
545598
546599 await repository . findTrashedNotExpiredInWorkspace (
@@ -558,7 +611,7 @@ describe('FileRepository', () => {
558611 ) ;
559612 } ) ;
560613
561- it ( 'When cutoffDate is provided , then it should add an updatedAt >= cutoffDate filter ' , async ( ) => {
614+ it ( 'When an expiration date is set , then it should only return workspace trashed files that have not yet expired ' , async ( ) => {
562615 const cutoffDate = new Date ( '2026-03-04' ) ;
563616 jest . spyOn ( fileModel , 'findAll' ) . mockResolvedValue ( [ ] ) ;
564617
@@ -579,6 +632,30 @@ describe('FileRepository', () => {
579632 } ) ,
580633 ) ;
581634 } ) ;
635+
636+ it ( 'When retrieving workspace trashed files, then it should also load the name of the folder each file belongs to' , async ( ) => {
637+ jest . spyOn ( fileModel , 'findAll' ) . mockResolvedValue ( [ ] ) ;
638+
639+ await repository . findTrashedNotExpiredInWorkspace (
640+ createdBy ,
641+ workspaceId ,
642+ null ,
643+ limit ,
644+ offset ,
645+ ) ;
646+
647+ expect ( fileModel . findAll ) . toHaveBeenCalledWith (
648+ expect . objectContaining ( {
649+ include : expect . arrayContaining ( [
650+ expect . objectContaining ( {
651+ as : 'folder' ,
652+ attributes : [ 'plainName' , 'removed' , 'deleted' , 'uuid' ] ,
653+ required : false ,
654+ } ) ,
655+ ] ) ,
656+ } ) ,
657+ ) ;
658+ } ) ;
582659 } ) ;
583660
584661 describe ( 'findRecent' , ( ) => {
0 commit comments