Skip to content

Commit 9d20668

Browse files
committed
fix: make test assertions better
1 parent 3c6da0a commit 9d20668

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

test/integration/collections/CollectionsRepository.test.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -805,20 +805,23 @@ describe('CollectionsRepository', () => {
805805
})
806806

807807
describe('getCollectionsForLinking', () => {
808+
const linkingParentCollection = 'collectionsRepositoryLinkingTestParentCollection'
808809
const linkingTargetAlias = 'collectionsRepositoryLinkTarget'
809810

810811
beforeAll(async () => {
811-
await createCollectionViaApi(linkingTargetAlias)
812+
await createCollectionViaApi(linkingParentCollection)
813+
await createCollectionViaApi(linkingTargetAlias, linkingParentCollection)
812814
})
813815

814816
afterAll(async () => {
815817
await deleteCollectionViaApi(linkingTargetAlias)
818+
await deleteCollectionViaApi(linkingParentCollection)
816819
})
817820

818821
test('should list collections for linking for a given collection alias', async () => {
819822
const results = await sut.getCollectionsForLinking(
820823
'collection',
821-
testCollectionAlias,
824+
linkingParentCollection,
822825
'Scientific',
823826
false
824827
)
@@ -835,7 +838,7 @@ describe('CollectionsRepository', () => {
835838
// Create a temporary dataset to query linking candidates
836839
const { persistentId, numericId } = await createDataset.execute(
837840
TestConstants.TEST_NEW_DATASET_DTO,
838-
testCollectionAlias
841+
linkingParentCollection
839842
)
840843

841844
const results = await sut.getCollectionsForLinking(
@@ -854,30 +857,28 @@ describe('CollectionsRepository', () => {
854857
expect(found?.displayName).toBe('Scientific Research')
855858
})
856859

857-
test('should return collections for unlking when sending alreadyLinked param to true', async () => {
858-
// Link the test collection with the linking target collection
859-
await sut.linkCollection(testCollectionAlias, linkingTargetAlias)
860-
861-
await new Promise((resolve) => setTimeout(resolve, 2000))
862-
863-
const collectionsForLinking = await sut.getCollectionsForLinking(
860+
test('should return collections for unlinking when sending alreadyLinked param to true', async () => {
861+
const collectionsForUnlinkingBefore = await sut.getCollectionsForLinking(
864862
'collection',
865-
testCollectionAlias,
863+
linkingParentCollection,
866864
'',
867-
false
865+
true
868866
)
869867

870-
const collectionsForUnlinking = await sut.getCollectionsForLinking(
868+
// Link the test collection with the linking target collection
869+
await sut.linkCollection(linkingParentCollection, linkingTargetAlias)
870+
871+
const collectionsForUnlinkingAfter = await sut.getCollectionsForLinking(
871872
'collection',
872-
testCollectionAlias,
873+
linkingParentCollection,
873874
'',
874875
true
875876
)
876877

877-
expect(collectionsForLinking.length).toBe(0)
878-
expect(collectionsForUnlinking.length).toBeGreaterThan(0)
879-
expect(collectionsForUnlinking[0].alias).toBe(linkingTargetAlias)
880-
expect(collectionsForUnlinking[0].displayName).toBe('Scientific Research')
878+
expect(collectionsForUnlinkingBefore.length).toBe(0)
879+
expect(collectionsForUnlinkingAfter.length).toBeGreaterThan(0)
880+
expect(collectionsForUnlinkingAfter[0].alias).toBe(linkingTargetAlias)
881+
expect(collectionsForUnlinkingAfter[0].displayName).toBe('Scientific Research')
881882
})
882883

883884
it('should return error when collection does not exist', async () => {

0 commit comments

Comments
 (0)