File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import { ICollectionsRepository } from '../../../src/collections/domain/repositories/ICollectionsRepository'
2+ import { WriteError } from '../../../src'
3+ import { SetDefaultContributorRole } from '../../../src/collections/domain/useCases/SetDefaultContributorRole'
4+
5+ describe ( 'execute' , ( ) => {
6+ test ( 'should set default contributor role on repository success' , async ( ) => {
7+ const collectionRepositoryStub : ICollectionsRepository = { } as ICollectionsRepository
8+ collectionRepositoryStub . setDefaultContributorRole = jest . fn ( ) . mockResolvedValue ( undefined )
9+ const testSetDefaultContributorRole = new SetDefaultContributorRole (
10+ collectionRepositoryStub
11+ )
12+
13+ await expect ( testSetDefaultContributorRole . execute ( 1 , "curator" ) ) . resolves . toBeUndefined ( )
14+ expect ( collectionRepositoryStub . setDefaultContributorRole ) . toHaveBeenCalledWith ( 1 , "curator" )
15+ } )
16+
17+ test ( 'should return error result on repository error' , async ( ) => {
18+ const collectionRepositoryStub : ICollectionsRepository = { } as ICollectionsRepository
19+ collectionRepositoryStub . setDefaultContributorRole = jest
20+ . fn ( )
21+ . mockRejectedValue ( new WriteError ( ) )
22+ const testSetDefaultContributorRole = new SetDefaultContributorRole (
23+ collectionRepositoryStub
24+ )
25+
26+ await expect ( testSetDefaultContributorRole . execute ( 1 , "curator" ) ) . rejects . toThrow ( WriteError )
27+ expect ( collectionRepositoryStub . setDefaultContributorRole ) . toHaveBeenCalledWith ( 1 , "curator" )
28+ } )
29+ } )
You can’t perform that action at this time.
0 commit comments