Skip to content

Commit 196b7fa

Browse files
committed
test: add tests for (un)assigning roles on datasets and collections
1 parent 71e0047 commit 196b7fa

File tree

4 files changed

+100
-0
lines changed

4 files changed

+100
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ICollectionsRepository } from '../../../src/collections/domain/repositories/ICollectionsRepository'
2+
import { WriteError } from '../../../src'
3+
import { AssignRoleOnCollection } from '../../../src/collections/domain/useCases/AssignRoleOnCollection'
4+
5+
describe('execute', () => {
6+
test('should assign role successfully on repository success', async () => {
7+
const collectionRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
8+
collectionRepositoryStub.assignRoleOnCollection = jest.fn().mockResolvedValue(undefined)
9+
10+
const testAssignRoleOnCollection = new AssignRoleOnCollection(collectionRepositoryStub)
11+
12+
await expect(testAssignRoleOnCollection.execute(1, "@testUser", "curator")).resolves.toBeUndefined()
13+
expect(collectionRepositoryStub.assignRoleOnCollection).toHaveBeenCalledWith(1, "@testUser", "curator")
14+
})
15+
16+
test('should throw error on repository failure', async () => {
17+
const collectionRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
18+
collectionRepositoryStub.assignRoleOnCollection = jest.fn().mockRejectedValue(new WriteError())
19+
20+
const testAssignRoleOnCollection = new AssignRoleOnCollection(collectionRepositoryStub)
21+
22+
await expect(testAssignRoleOnCollection.execute(1, "@testUser", "curator")).rejects.toThrow(WriteError)
23+
expect(collectionRepositoryStub.assignRoleOnCollection).toHaveBeenCalledWith(1, "@testUser", "curator")
24+
})
25+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { ICollectionsRepository } from '../../../src/collections/domain/repositories/ICollectionsRepository'
2+
import { WriteError } from '../../../src'
3+
import { UnassignRoleOnCollection } from '../../../src/collections/domain/useCases/UnassignRoleOnCollection'
4+
5+
describe('execute', () => {
6+
test('should unassign role successfully on repository success', async () => {
7+
const collectionRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
8+
collectionRepositoryStub.unassignRoleOnCollection = jest.fn().mockResolvedValue(undefined)
9+
10+
const testUnassignRoleOnCollection = new UnassignRoleOnCollection(collectionRepositoryStub)
11+
12+
await expect(testUnassignRoleOnCollection.execute(1, 2)).resolves.toBeUndefined()
13+
expect(collectionRepositoryStub.unassignRoleOnCollection).toHaveBeenCalledWith(1, 2)
14+
})
15+
16+
test('should throw error on repository failure', async () => {
17+
const collectionRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
18+
collectionRepositoryStub.unassignRoleOnCollection = jest.fn().mockRejectedValue(new WriteError())
19+
20+
const testUnassignRoleOnCollection = new UnassignRoleOnCollection(collectionRepositoryStub)
21+
22+
await expect(testUnassignRoleOnCollection.execute(1, 2)).rejects.toThrow(WriteError)
23+
expect(collectionRepositoryStub.unassignRoleOnCollection).toHaveBeenCalledWith(1, 2)
24+
})
25+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { IDatasetsRepository } from '../../../src/datasets/domain/repositories/IDatasetsRepository'
2+
import { WriteError } from '../../../src'
3+
import { AssignRoleOnDataset } from '../../../src/datasets/domain/useCases/AssignRoleOnDataset'
4+
5+
describe('execute', () => {
6+
test('should assign role successfully on repository success', async () => {
7+
const datasetsRepositoryStub: IDatasetsRepository = {} as IDatasetsRepository
8+
datasetsRepositoryStub.assignRoleOnDataset = jest.fn().mockResolvedValue(undefined)
9+
10+
const testAssignRoleOnDataset = new AssignRoleOnDataset(datasetsRepositoryStub)
11+
12+
await expect(testAssignRoleOnDataset.execute(1, "@testUser", "curator")).resolves.toBeUndefined()
13+
expect(datasetsRepositoryStub.assignRoleOnDataset).toHaveBeenCalledWith(1, "@testUser", "curator")
14+
})
15+
16+
test('should throw error on repository failure', async () => {
17+
const datasetsRepositoryStub: IDatasetsRepository = {} as IDatasetsRepository
18+
datasetsRepositoryStub.assignRoleOnDataset = jest.fn().mockRejectedValue(new WriteError())
19+
20+
const testAssignRoleOnDataset = new AssignRoleOnDataset(datasetsRepositoryStub)
21+
22+
await expect(testAssignRoleOnDataset.execute(1, "@testUser", "curator")).rejects.toThrow(WriteError)
23+
expect(datasetsRepositoryStub.assignRoleOnDataset).toHaveBeenCalledWith(1, "@testUser", "curator")
24+
})
25+
})
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { IDatasetsRepository } from '../../../src/datasets/domain/repositories/IDatasetsRepository'
2+
import { WriteError } from '../../../src'
3+
import { UnassignRoleOnDataset } from '../../../src/datasets/domain/useCases/UnassignRoleOnDataset'
4+
5+
describe('execute', () => {
6+
test('should unassign role successfully on repository success', async () => {
7+
const datasetsRepositoryStub: IDatasetsRepository = {} as IDatasetsRepository
8+
datasetsRepositoryStub.unassignRoleOnDataset = jest.fn().mockResolvedValue(undefined)
9+
10+
const testUnassignRoleOnDataset = new UnassignRoleOnDataset(datasetsRepositoryStub)
11+
12+
await expect(testUnassignRoleOnDataset.execute(1, 2)).resolves.toBeUndefined()
13+
expect(datasetsRepositoryStub.unassignRoleOnDataset).toHaveBeenCalledWith(1, 2)
14+
})
15+
16+
test('should throw error on repository failure', async () => {
17+
const datasetsRepositoryStub: IDatasetsRepository = {} as IDatasetsRepository
18+
datasetsRepositoryStub.unassignRoleOnDataset = jest.fn().mockRejectedValue(new WriteError())
19+
20+
const testUnassignRoleOnDataset = new UnassignRoleOnDataset(datasetsRepositoryStub)
21+
22+
await expect(testUnassignRoleOnDataset.execute(1, 2)).rejects.toThrow(WriteError)
23+
expect(datasetsRepositoryStub.unassignRoleOnDataset).toHaveBeenCalledWith(1, 2)
24+
})
25+
})

0 commit comments

Comments
 (0)