|
1 | 1 | import { CollectionsRepository } from '../../../src/collections/infra/repositories/CollectionsRepository'
|
2 | 2 | import { TestConstants } from '../../testHelpers/TestConstants'
|
3 | 3 | import {
|
| 4 | + CollectionDTO, |
4 | 5 | CollectionFeaturedItemsDTO,
|
5 | 6 | CollectionItemType,
|
6 | 7 | CollectionPreview,
|
@@ -149,11 +150,15 @@ describe('CollectionsRepository', () => {
|
149 | 150 | const testCreateCollectionAlias1 = 'createCollection-test-1'
|
150 | 151 | const testCreateCollectionAlias2 = 'createCollection-test-2'
|
151 | 152 | const testCreateCollectionAlias3 = 'createCollection-test-3'
|
| 153 | + const testCreateCollectionAlias4 = 'createCollection-test-4' |
| 154 | + const testCreateCollectionAlias5 = 'createCollection-test-5' |
152 | 155 |
|
153 | 156 | afterAll(async () => {
|
154 | 157 | await deleteCollectionViaApi(testCreateCollectionAlias1)
|
155 | 158 | await deleteCollectionViaApi(testCreateCollectionAlias2)
|
156 | 159 | await deleteCollectionViaApi(testCreateCollectionAlias3)
|
| 160 | + await deleteCollectionViaApi(testCreateCollectionAlias4) |
| 161 | + await deleteCollectionViaApi(testCreateCollectionAlias5) |
157 | 162 | })
|
158 | 163 |
|
159 | 164 | test('should create collection in root when no parent collection is set', async () => {
|
@@ -184,13 +189,48 @@ describe('CollectionsRepository', () => {
|
184 | 189 | testCollectionId
|
185 | 190 | )
|
186 | 191 | expect(typeof actualId).toBe('number')
|
| 192 | + |
| 193 | + const collectionCreated = await sut.getCollection(actualId) |
| 194 | + |
| 195 | + expect(collectionCreated.isMetadataBlockRoot).toBe(true) |
| 196 | + expect(collectionCreated.isFacetRoot).toBe(true) |
187 | 197 | })
|
188 | 198 |
|
189 |
| - test('should create collection without input levels', async () => { |
190 |
| - const newCollectionDTO = createCollectionDTO(testCreateCollectionAlias3) |
191 |
| - newCollectionDTO.inputLevels = undefined |
192 |
| - const actualId = await sut.createCollection(newCollectionDTO, testCollectionId) |
193 |
| - expect(typeof actualId).toBe('number') |
| 199 | + test('should create a collection to inherit metadata blocks from parent collection', async () => { |
| 200 | + const childCollectionDTO = createCollectionDTO(testCreateCollectionAlias3) |
| 201 | + childCollectionDTO.inheritMetadataBlocksFromParent = true |
| 202 | + |
| 203 | + const childCollectionId = await sut.createCollection(childCollectionDTO) |
| 204 | + |
| 205 | + const childCollection = await sut.getCollection(childCollectionId) |
| 206 | + |
| 207 | + expect(childCollection.isMetadataBlockRoot).toBe(false) |
| 208 | + expect(childCollection.isFacetRoot).toBe(true) |
| 209 | + }) |
| 210 | + |
| 211 | + test('should create a collection to inherit facets from parent collection', async () => { |
| 212 | + const childCollectionDTO = createCollectionDTO(testCreateCollectionAlias4) |
| 213 | + childCollectionDTO.inheritFacetsFromParent = true |
| 214 | + |
| 215 | + const childCollectionId = await sut.createCollection(childCollectionDTO) |
| 216 | + |
| 217 | + const childCollection = await sut.getCollection(childCollectionId) |
| 218 | + |
| 219 | + expect(childCollection.isMetadataBlockRoot).toBe(true) |
| 220 | + expect(childCollection.isFacetRoot).toBe(false) |
| 221 | + }) |
| 222 | + |
| 223 | + test('should create a collection to inherit metadata blocks and facets from parent collection', async () => { |
| 224 | + const childCollectionDTO = createCollectionDTO(testCreateCollectionAlias5) |
| 225 | + childCollectionDTO.inheritMetadataBlocksFromParent = true |
| 226 | + childCollectionDTO.inheritFacetsFromParent = true |
| 227 | + |
| 228 | + const childCollectionId = await sut.createCollection(childCollectionDTO) |
| 229 | + |
| 230 | + const childCollection = await sut.getCollection(childCollectionId) |
| 231 | + |
| 232 | + expect(childCollection.isMetadataBlockRoot).toBe(false) |
| 233 | + expect(childCollection.isFacetRoot).toBe(false) |
194 | 234 | })
|
195 | 235 |
|
196 | 236 | test('should return error when parent collection does not exist', async () => {
|
@@ -918,6 +958,126 @@ describe('CollectionsRepository', () => {
|
918 | 958 | expect(updatedInputLevel?.required).toBe(false)
|
919 | 959 | })
|
920 | 960 |
|
| 961 | + test('should update the collection to inherit metadata blocks from parent collection', async () => { |
| 962 | + const parentCollectionAlias = 'inherit-metablocks-parent-update' |
| 963 | + const parentCollectionDTO = createCollectionDTO(parentCollectionAlias) |
| 964 | + const parentCollectionId = await sut.createCollection(parentCollectionDTO) |
| 965 | + |
| 966 | + const childCollectionAlias = 'inherit-metablocks-child-update' |
| 967 | + const childCollectionDTO = createCollectionDTO(childCollectionAlias) |
| 968 | + |
| 969 | + const childCollectionId = await sut.createCollection(childCollectionDTO, parentCollectionId) |
| 970 | + |
| 971 | + const childCollection = await sut.getCollection(childCollectionId) |
| 972 | + |
| 973 | + expect(childCollection.isMetadataBlockRoot).toBe(true) |
| 974 | + expect(childCollection.isFacetRoot).toBe(true) |
| 975 | + |
| 976 | + const updatedChildCollectionDTO = createCollectionDTO(childCollectionAlias) |
| 977 | + updatedChildCollectionDTO.inheritMetadataBlocksFromParent = true |
| 978 | + |
| 979 | + await sut.updateCollection(childCollectionId, updatedChildCollectionDTO) |
| 980 | + |
| 981 | + const childCollectionAfterUpdate = await sut.getCollection(childCollectionId) |
| 982 | + |
| 983 | + expect(childCollectionAfterUpdate.isMetadataBlockRoot).toBe(false) |
| 984 | + expect(childCollectionAfterUpdate.isFacetRoot).toBe(true) |
| 985 | + |
| 986 | + await deleteCollectionViaApi(childCollectionAlias) |
| 987 | + await deleteCollectionViaApi(parentCollectionAlias) |
| 988 | + }) |
| 989 | + |
| 990 | + test('should update the collection to inherit facets from parent collection', async () => { |
| 991 | + const parentCollectionAlias = 'inherit-facets-parent-update' |
| 992 | + const parentCollectionDTO = createCollectionDTO(parentCollectionAlias) |
| 993 | + const parentCollectionId = await sut.createCollection(parentCollectionDTO) |
| 994 | + |
| 995 | + const childCollectionAlias = 'inherit-facets-child-update' |
| 996 | + const childCollectionDTO = createCollectionDTO(childCollectionAlias) |
| 997 | + |
| 998 | + const childCollectionId = await sut.createCollection(childCollectionDTO, parentCollectionId) |
| 999 | + |
| 1000 | + const childCollection = await sut.getCollection(childCollectionId) |
| 1001 | + |
| 1002 | + expect(childCollection.isMetadataBlockRoot).toBe(true) |
| 1003 | + expect(childCollection.isFacetRoot).toBe(true) |
| 1004 | + |
| 1005 | + const updatedChildCollectionDTO = createCollectionDTO(childCollectionAlias) |
| 1006 | + updatedChildCollectionDTO.inheritFacetsFromParent = true |
| 1007 | + |
| 1008 | + await sut.updateCollection(childCollectionId, updatedChildCollectionDTO) |
| 1009 | + |
| 1010 | + const childCollectionAfterUpdate = await sut.getCollection(childCollectionId) |
| 1011 | + |
| 1012 | + expect(childCollectionAfterUpdate.isMetadataBlockRoot).toBe(true) |
| 1013 | + expect(childCollectionAfterUpdate.isFacetRoot).toBe(false) |
| 1014 | + |
| 1015 | + await deleteCollectionViaApi(childCollectionAlias) |
| 1016 | + await deleteCollectionViaApi(parentCollectionAlias) |
| 1017 | + }) |
| 1018 | + |
| 1019 | + test('should update the collection to inherit metadata blocks and facets from parent collection', async () => { |
| 1020 | + const parentCollectionAlias = 'inherit-metablocks-facets-parent-update' |
| 1021 | + const parentCollectionDTO = createCollectionDTO(parentCollectionAlias) |
| 1022 | + const parentCollectionId = await sut.createCollection(parentCollectionDTO) |
| 1023 | + |
| 1024 | + const childCollectionAlias = 'inherit-metablocks-facets-child-update' |
| 1025 | + const childCollectionDTO = createCollectionDTO(childCollectionAlias) |
| 1026 | + |
| 1027 | + const childCollectionId = await sut.createCollection(childCollectionDTO, parentCollectionId) |
| 1028 | + |
| 1029 | + const childCollection = await sut.getCollection(childCollectionId) |
| 1030 | + |
| 1031 | + expect(childCollection.isMetadataBlockRoot).toBe(true) |
| 1032 | + expect(childCollection.isFacetRoot).toBe(true) |
| 1033 | + |
| 1034 | + const updatedChildCollectionDTO = createCollectionDTO(childCollectionAlias) |
| 1035 | + updatedChildCollectionDTO.inheritFacetsFromParent = true |
| 1036 | + updatedChildCollectionDTO.inheritMetadataBlocksFromParent = true |
| 1037 | + |
| 1038 | + await sut.updateCollection(childCollectionId, updatedChildCollectionDTO) |
| 1039 | + |
| 1040 | + const childCollectionAfterUpdate = await sut.getCollection(childCollectionId) |
| 1041 | + |
| 1042 | + expect(childCollectionAfterUpdate.isMetadataBlockRoot).toBe(false) |
| 1043 | + expect(childCollectionAfterUpdate.isFacetRoot).toBe(false) |
| 1044 | + |
| 1045 | + await deleteCollectionViaApi(childCollectionAlias) |
| 1046 | + await deleteCollectionViaApi(parentCollectionAlias) |
| 1047 | + }) |
| 1048 | + |
| 1049 | + test('should not update root collection facets and keep isMetadataBlockRoot and isFacetRoot in true if facet ids are sent as undefined', async () => { |
| 1050 | + const rootCollection = await sut.getCollection() |
| 1051 | + |
| 1052 | + const rootCollectionFacets = await sut.getCollectionFacets(rootCollection.alias) |
| 1053 | + |
| 1054 | + const updatedRootCollectionDTO: CollectionDTO = { |
| 1055 | + alias: rootCollection.alias, |
| 1056 | + name: rootCollection.name, |
| 1057 | + contacts: [rootCollection.contacts?.[0].email as string], |
| 1058 | + type: rootCollection.type, |
| 1059 | + description: rootCollection.description, |
| 1060 | + affiliation: rootCollection.affiliation, |
| 1061 | + metadataBlockNames: undefined, |
| 1062 | + facetIds: undefined, |
| 1063 | + inputLevels: undefined, |
| 1064 | + inheritFacetsFromParent: false, |
| 1065 | + inheritMetadataBlocksFromParent: false |
| 1066 | + } |
| 1067 | + |
| 1068 | + await sut.updateCollection(rootCollection.id, updatedRootCollectionDTO) |
| 1069 | + |
| 1070 | + const rootCollectionAfterUpdate = await sut.getCollection() |
| 1071 | + |
| 1072 | + const rootCollectionFacetsAfterUpdate = await sut.getCollectionFacets(rootCollection.alias) |
| 1073 | + |
| 1074 | + expect(rootCollectionFacets).toStrictEqual(rootCollectionFacetsAfterUpdate) |
| 1075 | + expect(rootCollection.isMetadataBlockRoot).toBe(true) |
| 1076 | + expect(rootCollection.isFacetRoot).toBe(true) |
| 1077 | + expect(rootCollectionAfterUpdate.isMetadataBlockRoot).toBe(true) |
| 1078 | + expect(rootCollectionAfterUpdate.isFacetRoot).toBe(true) |
| 1079 | + }) |
| 1080 | + |
921 | 1081 | test('should return error when collection does not exist', async () => {
|
922 | 1082 | const expectedError = new WriteError(
|
923 | 1083 | `[404] Can't find dataverse with identifier='${TestConstants.TEST_DUMMY_COLLECTION_ID}'`
|
|
0 commit comments