File tree Expand file tree Collapse file tree 6 files changed +53
-3
lines changed
Expand file tree Collapse file tree 6 files changed +53
-3
lines changed Original file line number Diff line number Diff line change 11import { UseCase } from '../../../core/domain/useCases/UseCase'
22import { ICollectionsRepository } from '../repositories/ICollectionsRepository'
33
4- export class UnLinkCollection implements UseCase < void > {
4+ export class UnlinkCollection implements UseCase < void > {
55 private collectionsRepository : ICollectionsRepository
66
77 constructor ( collectionsRepository : ICollectionsRepository ) {
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import { DeleteCollection } from './domain/useCases/DeleteCollection'
1313import { GetMyDataCollectionItems } from './domain/useCases/GetMyDataCollectionItems'
1414import { DeleteCollectionFeaturedItem } from './domain/useCases/DeleteCollectionFeaturedItem'
1515import { LinkCollection } from './domain/useCases/LinkCollection'
16- import { UnLinkCollection } from './domain/useCases/UnLinkCollection'
16+ import { UnlinkCollection } from './domain/useCases/UnLinkCollection'
1717
1818const collectionsRepository = new CollectionsRepository ( )
1919
@@ -31,7 +31,7 @@ const deleteCollectionFeaturedItems = new DeleteCollectionFeaturedItems(collecti
3131const deleteCollection = new DeleteCollection ( collectionsRepository )
3232const deleteCollectionFeaturedItem = new DeleteCollectionFeaturedItem ( collectionsRepository )
3333const linkCollection = new LinkCollection ( collectionsRepository )
34- const unlinkCollection = new UnLinkCollection ( collectionsRepository )
34+ const unlinkCollection = new UnlinkCollection ( collectionsRepository )
3535
3636export {
3737 getCollection ,
File renamed without changes.
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 { LinkCollection } from '../../../src/collections/domain/useCases/LinkCollection'
4+
5+ describe ( 'execute' , ( ) => {
6+ test ( 'should link collection successfully on repository success' , async ( ) => {
7+ const collectionRepositoryStub : ICollectionsRepository = { } as ICollectionsRepository
8+ collectionRepositoryStub . linkCollection = jest . fn ( ) . mockResolvedValue ( undefined )
9+
10+ const testLinkCollection = new LinkCollection ( collectionRepositoryStub )
11+
12+ await expect ( testLinkCollection . execute ( 1 , 2 ) ) . resolves . toBeUndefined ( )
13+ expect ( collectionRepositoryStub . linkCollection ) . toHaveBeenCalledWith ( 1 , 2 )
14+ } )
15+
16+ test ( 'should throw error on repository failure' , async ( ) => {
17+ const collectionRepositoryStub : ICollectionsRepository = { } as ICollectionsRepository
18+ collectionRepositoryStub . linkCollection = jest . fn ( ) . mockRejectedValue ( new WriteError ( ) )
19+
20+ const testLinkCollection = new LinkCollection ( collectionRepositoryStub )
21+
22+ await expect ( testLinkCollection . execute ( 1 , 2 ) ) . rejects . toThrow ( WriteError )
23+ expect ( collectionRepositoryStub . linkCollection ) . toHaveBeenCalledWith ( 1 , 2 )
24+ } )
25+ } )
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 { UnlinkCollection } from '../../../src/collections/domain/useCases/UnlinkCollection'
4+
5+ describe ( 'execute' , ( ) => {
6+ test ( 'should unlink collection successfully on repository success' , async ( ) => {
7+ const collectionRepositoryStub : ICollectionsRepository = { } as ICollectionsRepository
8+ collectionRepositoryStub . unlinkCollection = jest . fn ( ) . mockResolvedValue ( undefined )
9+
10+ const testUnlinkCollection = new UnlinkCollection ( collectionRepositoryStub )
11+
12+ await expect ( testUnlinkCollection . execute ( 1 , 2 ) ) . resolves . toBeUndefined ( )
13+ expect ( collectionRepositoryStub . unlinkCollection ) . toHaveBeenCalledWith ( 1 , 2 )
14+ } )
15+
16+ test ( 'should throw error on repository failure' , async ( ) => {
17+ const collectionRepositoryStub : ICollectionsRepository = { } as ICollectionsRepository
18+ collectionRepositoryStub . unlinkCollection = jest . fn ( ) . mockRejectedValue ( new WriteError ( ) )
19+
20+ const testUnlinkCollection = new UnlinkCollection ( collectionRepositoryStub )
21+
22+ await expect ( testUnlinkCollection . execute ( 1 , 2 ) ) . rejects . toThrow ( WriteError )
23+ expect ( collectionRepositoryStub . unlinkCollection ) . toHaveBeenCalledWith ( 1 , 2 )
24+ } )
25+ } )
You can’t perform that action at this time.
0 commit comments