-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #272 from internxt/feat/pb-1706-retrieve-items-by-…
…folder-uuid [PB-1706]: Retrieve subitems by folder UUID
- Loading branch information
Showing
13 changed files
with
321 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,5 +36,6 @@ lerna-debug.log* | |
|
||
.npmrc | ||
|
||
.env | ||
.env.development | ||
.env.production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
export class Event { | ||
private createdAt: Date; | ||
constructor(public name: string, public payload: Record<string, any>) { | ||
constructor( | ||
public name: string, | ||
public payload: Record<string, any>, | ||
) { | ||
this.createdAt = new Date(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,55 @@ | ||
import { createMock } from '@golevelup/ts-jest'; | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { newFolder } from '../../../test/fixtures'; | ||
import { BadRequestException } from '@nestjs/common'; | ||
import { newFile, newFolder } from '../../../test/fixtures'; | ||
import { FileUseCases } from '../file/file.usecase'; | ||
import { FolderController } from './folder.controller'; | ||
import { | ||
BadRequestInvalidOffsetException, | ||
BadRequestOutOfRangeLimitException, | ||
FolderController, | ||
} from './folder.controller'; | ||
import { Folder } from './folder.domain'; | ||
import { FolderUseCases } from './folder.usecase'; | ||
import { CalculateFolderSizeTimeoutException } from './exception/calculate-folder-size-timeout.exception'; | ||
import { User } from '../user/user.domain'; | ||
import { FileStatus } from '../file/file.domain'; | ||
|
||
describe('FolderController', () => { | ||
let folderController: FolderController; | ||
let folderUseCases: FolderUseCases; | ||
let fileUseCases: FileUseCases; | ||
let folder: Folder; | ||
|
||
const userMocked = User.build({ | ||
id: 1, | ||
userId: 'userId', | ||
name: 'User Owner', | ||
lastname: 'Lastname', | ||
email: '[email protected]', | ||
username: 'fake', | ||
bridgeUser: null, | ||
rootFolderId: 1, | ||
errorLoginCount: 0, | ||
isEmailActivitySended: 1, | ||
referralCode: null, | ||
referrer: null, | ||
syncDate: new Date(), | ||
uuid: 'uuid', | ||
lastResend: new Date(), | ||
credit: null, | ||
welcomePack: true, | ||
registerCompleted: true, | ||
backupsBucket: 'bucket', | ||
sharedWorkspace: true, | ||
avatar: 'avatar', | ||
password: '', | ||
mnemonic: '', | ||
hKey: undefined, | ||
secret_2FA: '', | ||
tempKey: '', | ||
lastPasswordChangedAt: new Date(), | ||
}); | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
controllers: [FolderController], | ||
|
@@ -23,6 +61,7 @@ describe('FolderController', () => { | |
|
||
folderController = module.get<FolderController>(FolderController); | ||
folderUseCases = module.get<FolderUseCases>(FolderUseCases); | ||
fileUseCases = module.get<FileUseCases>(FileUseCases); | ||
folder = newFolder(); | ||
}); | ||
|
||
|
@@ -47,4 +86,151 @@ describe('FolderController', () => { | |
); | ||
}); | ||
}); | ||
|
||
describe('get folder content', () => { | ||
it('When get folder subfiles are requested by folder uuid, then the child files are returned', async () => { | ||
const expectedSubfiles = [ | ||
newFile({ attributes: { id: 1, folderUuid: folder.uuid } }), | ||
newFile({ attributes: { id: 2, folderUuid: folder.uuid } }), | ||
newFile({ attributes: { id: 3, folderUuid: folder.uuid } }), | ||
]; | ||
jest.spyOn(fileUseCases, 'getFiles').mockResolvedValue(expectedSubfiles); | ||
|
||
const result = await folderController.getFolderContentFiles( | ||
userMocked, | ||
folder.uuid, | ||
50, | ||
0, | ||
'id', | ||
'ASC', | ||
); | ||
expect(result).toEqual({ files: expectedSubfiles }); | ||
}); | ||
|
||
it('When get folder subfolders are requested by folder uuid, then the child folders are returned', async () => { | ||
const expectedSubfolders = [ | ||
newFolder({ attributes: { id: 1, parentUuid: folder.uuid } }), | ||
newFolder({ attributes: { id: 2, parentUuid: folder.uuid } }), | ||
newFolder({ attributes: { id: 3, parentUuid: folder.uuid } }), | ||
]; | ||
const mappedSubfolders = expectedSubfolders.map((f) => { | ||
let folderStatus: FileStatus; | ||
if (f.removed) { | ||
folderStatus = FileStatus.DELETED; | ||
} else if (f.deleted) { | ||
folderStatus = FileStatus.TRASHED; | ||
} else { | ||
folderStatus = FileStatus.EXISTS; | ||
} | ||
return { ...f, status: folderStatus }; | ||
}); | ||
|
||
jest | ||
.spyOn(folderUseCases, 'getFolders') | ||
.mockResolvedValue(expectedSubfolders); | ||
|
||
const result = await folderController.getFolderContentFolders( | ||
userMocked, | ||
folder.uuid, | ||
50, | ||
0, | ||
'id', | ||
'ASC', | ||
); | ||
|
||
expect(result).toEqual({ folders: mappedSubfolders }); | ||
}); | ||
|
||
it('When get folder subfiles are requested by invalid params, then it should throw an error', () => { | ||
expect( | ||
folderController.getFolderContentFiles( | ||
userMocked, | ||
'invalidUUID', | ||
50, | ||
0, | ||
'id', | ||
'ASC', | ||
), | ||
).rejects.toThrow(BadRequestException); | ||
|
||
expect( | ||
folderController.getFolderContentFiles( | ||
userMocked, | ||
folder.uuid, | ||
0, | ||
0, | ||
'id', | ||
'ASC', | ||
), | ||
).rejects.toThrow(BadRequestOutOfRangeLimitException); | ||
|
||
expect( | ||
folderController.getFolderContentFiles( | ||
userMocked, | ||
folder.uuid, | ||
51, | ||
0, | ||
'id', | ||
'ASC', | ||
), | ||
).rejects.toThrow(BadRequestOutOfRangeLimitException); | ||
|
||
expect( | ||
folderController.getFolderContentFiles( | ||
userMocked, | ||
folder.uuid, | ||
50, | ||
-1, | ||
'id', | ||
'ASC', | ||
), | ||
).rejects.toThrow(BadRequestInvalidOffsetException); | ||
}); | ||
|
||
it('When get folder subfolders are requested by invalid folder uuid, then it should throw an error', async () => { | ||
expect( | ||
folderController.getFolderContentFolders( | ||
userMocked, | ||
'invalidUUID', | ||
50, | ||
0, | ||
'id', | ||
'ASC', | ||
), | ||
).rejects.toThrow(BadRequestException); | ||
|
||
expect( | ||
folderController.getFolderContentFolders( | ||
userMocked, | ||
folder.uuid, | ||
0, | ||
0, | ||
'id', | ||
'ASC', | ||
), | ||
).rejects.toThrow(BadRequestOutOfRangeLimitException); | ||
|
||
expect( | ||
folderController.getFolderContentFolders( | ||
userMocked, | ||
folder.uuid, | ||
51, | ||
0, | ||
'id', | ||
'ASC', | ||
), | ||
).rejects.toThrow(BadRequestOutOfRangeLimitException); | ||
|
||
expect( | ||
folderController.getFolderContentFolders( | ||
userMocked, | ||
folder.uuid, | ||
50, | ||
-1, | ||
'id', | ||
'ASC', | ||
), | ||
).rejects.toThrow(BadRequestInvalidOffsetException); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.