Skip to content

Commit 0a0dcf2

Browse files
committed
updated tests
1 parent ba8de45 commit 0a0dcf2

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed
File renamed without changes.

test/integration/collections/CollectionsRepository.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,23 @@ describe('CollectionsRepository', () => {
9494
})
9595
})
9696

97+
describe('publishCollection', () => {
98+
const testPublishCollectionAlias = 'publishCollection-test'
99+
100+
afterAll(async () => {
101+
await deleteCollectionViaApi(testPublishCollectionAlias)
102+
})
103+
104+
test('should publish a collection', async () => {
105+
const newCollectionDTO = createCollectionDTO(testPublishCollectionAlias)
106+
const actualId = await sut.createCollection(newCollectionDTO)
107+
await sut.publishCollection(actualId)
108+
const createdCollection = await sut.getCollection(actualId)
109+
110+
expect(createdCollection.isReleased).toBe(true)
111+
expect(createdCollection.name).toBe(newCollectionDTO.name)
112+
})
113+
})
97114
describe('createCollection', () => {
98115
const testCreateCollectionAlias1 = 'createCollection-test-1'
99116
const testCreateCollectionAlias2 = 'createCollection-test-2'
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { ICollectionsRepository } from '../../../src/collections/domain/repositories/ICollectionsRepository'
2+
import { PublishCollection } from '../../../src/collections/domain/useCases/PublishCollection'
3+
import { WriteError } from '../../../src'
4+
5+
describe('execute', () => {
6+
test('should return undefined on repository success', async () => {
7+
const collectionsRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
8+
collectionsRepositoryStub.publishCollection = jest.fn().mockResolvedValue(undefined)
9+
const sut = new PublishCollection(collectionsRepositoryStub)
10+
11+
const actual = await sut.execute(1)
12+
13+
expect(actual).toEqual(undefined)
14+
})
15+
16+
test('should return error result on repository error', async () => {
17+
const collectionsRepositoryStub: ICollectionsRepository = {} as ICollectionsRepository
18+
collectionsRepositoryStub.publishCollection = jest.fn().mockRejectedValue(new WriteError())
19+
const sut = new PublishCollection(collectionsRepositoryStub)
20+
21+
await expect(sut.execute(1)).rejects.toThrow(WriteError)
22+
})
23+
})

0 commit comments

Comments
 (0)