-
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 #277 from internxt/feat/add-items-to-trash-by-uuid
[PB-1740]: feat/add items to trash by uuid
- Loading branch information
Showing
10 changed files
with
421 additions
and
71 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
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
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
65 changes: 65 additions & 0 deletions
65
src/modules/trash/dto/controllers/move-items-to-trash.dto.spec.ts
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 |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { validate } from 'class-validator'; | ||
import { plainToInstance } from 'class-transformer'; | ||
import { | ||
ItemToTrash, | ||
ItemType, | ||
MoveItemsToTrashDto, | ||
} from './move-items-to-trash.dto'; | ||
|
||
describe('MoveItemsToTrashDto', () => { | ||
it('When valid data is passed, then no errors should be returned', async () => { | ||
const dto = plainToInstance(MoveItemsToTrashDto, { | ||
items: [ | ||
{ id: '1', type: ItemType.FILE }, | ||
{ uuid: '5bf9dca1-fd68-4864-9a16-ef36b77d063b', type: ItemType.FOLDER }, | ||
], | ||
}); | ||
|
||
const errors = await validate(dto); | ||
expect(errors.length).toBe(0); | ||
}); | ||
|
||
it('When items array exceeds max size, then should fail', async () => { | ||
const items = Array.from({ length: 51 }, (_, i) => ({ | ||
id: `${i + 1}`, | ||
type: ItemType.FILE, | ||
})); | ||
const dto = plainToInstance(MoveItemsToTrashDto, { items }); | ||
|
||
const errors = await validate(dto); | ||
expect(errors.length).toBeGreaterThan(0); | ||
expect(errors[0].constraints).toBeDefined(); | ||
}); | ||
|
||
describe('ItemToTrash', () => { | ||
it('When both id and uuid are provided in one item, then should fail', async () => { | ||
const item = plainToInstance(ItemToTrash, { | ||
id: '1', | ||
uuid: '5bf9dca1-fd68-4864-9a16-ef36b77d063b', | ||
type: ItemType.FILE, | ||
}); | ||
const errors = await validate(item); | ||
expect(errors.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('When neither id nor uuid are provided in one item, then should fail', async () => { | ||
const item = plainToInstance(ItemToTrash, { type: ItemType.FILE }); | ||
const errors = await validate(item); | ||
expect(errors.length).toBeGreaterThan(0); | ||
}); | ||
|
||
it('when either id or uuid are provided, then should validate successfuly ', async () => { | ||
const onlyIdErrors = await validate( | ||
plainToInstance(ItemToTrash, { id: '1', type: ItemType.FILE }), | ||
); | ||
const onlyUuidErrors = await validate( | ||
plainToInstance(ItemToTrash, { | ||
uuid: '5bf9dca1-fd68-4864-9a16-ef36b77d063b', | ||
type: ItemType.FILE, | ||
}), | ||
); | ||
expect(onlyIdErrors.length).toBe(0); | ||
expect(onlyUuidErrors.length).toBe(0); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.