From a899f65113b5e16247db7ab32ffaf8ff5f96dd32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Mon, 11 Nov 2024 13:20:30 -0300 Subject: [PATCH 1/4] feat: update model and transformer --- src/collections/domain/dtos/CollectionDTO.ts | 14 ++--------- src/collections/domain/models/Collection.ts | 6 +++++ .../domain/models/CollectionContact.ts | 4 ++++ .../domain/models/CollectionType.ts | 11 +++++++++ .../transformers/CollectionPayload.ts | 9 ++++++++ .../transformers/collectionTransformers.ts | 23 ++++++++++++++++++- 6 files changed, 54 insertions(+), 13 deletions(-) create mode 100644 src/collections/domain/models/CollectionContact.ts create mode 100644 src/collections/domain/models/CollectionType.ts diff --git a/src/collections/domain/dtos/CollectionDTO.ts b/src/collections/domain/dtos/CollectionDTO.ts index f732afea..b669ef6c 100644 --- a/src/collections/domain/dtos/CollectionDTO.ts +++ b/src/collections/domain/dtos/CollectionDTO.ts @@ -1,3 +1,5 @@ +import { CollectionType } from '../models/CollectionType' + export interface CollectionDTO { alias: string name: string @@ -15,15 +17,3 @@ export interface CollectionInputLevelDTO { include: boolean required: boolean } - -export enum CollectionType { - RESEARCHERS = 'RESEARCHERS', - RESEARCH_PROJECTS = 'RESEARCH_PROJECTS', - JOURNALS = 'JOURNALS', - ORGANIZATIONS_INSTITUTIONS = 'ORGANIZATIONS_INSTITUTIONS', - TEACHING_COURSES = 'TEACHING_COURSES', - UNCATEGORIZED = 'UNCATEGORIZED', - LABORATORY = 'LABORATORY', - RESEARCH_GROUP = 'RESEARCH_GROUP', - DEPARTMENT = 'DEPARTMENT' -} diff --git a/src/collections/domain/models/Collection.ts b/src/collections/domain/models/Collection.ts index 1cc1f1e4..9aeb1f2b 100644 --- a/src/collections/domain/models/Collection.ts +++ b/src/collections/domain/models/Collection.ts @@ -1,4 +1,6 @@ import { DvObjectOwnerNode } from '../../../core' +import { CollectionContact } from './CollectionContact' +import { CollectionType } from './CollectionType' export interface Collection { id: number @@ -9,6 +11,10 @@ export interface Collection { description?: string isPartOf: DvObjectOwnerNode inputLevels?: CollectionInputLevel[] + type: CollectionType + contacts?: CollectionContact[] + usesMetadataFieldsFromParent: boolean + usesBrowseSearchFacetsFromParent: boolean } export interface CollectionInputLevel { diff --git a/src/collections/domain/models/CollectionContact.ts b/src/collections/domain/models/CollectionContact.ts new file mode 100644 index 00000000..4264b9c0 --- /dev/null +++ b/src/collections/domain/models/CollectionContact.ts @@ -0,0 +1,4 @@ +export interface CollectionContact { + email: string + displayOrder: number +} diff --git a/src/collections/domain/models/CollectionType.ts b/src/collections/domain/models/CollectionType.ts new file mode 100644 index 00000000..2b587895 --- /dev/null +++ b/src/collections/domain/models/CollectionType.ts @@ -0,0 +1,11 @@ +export enum CollectionType { + RESEARCHERS = 'RESEARCHERS', + RESEARCH_PROJECTS = 'RESEARCH_PROJECTS', + JOURNALS = 'JOURNALS', + ORGANIZATIONS_INSTITUTIONS = 'ORGANIZATIONS_INSTITUTIONS', + TEACHING_COURSES = 'TEACHING_COURSES', + UNCATEGORIZED = 'UNCATEGORIZED', + LABORATORY = 'LABORATORY', + RESEARCH_GROUP = 'RESEARCH_GROUP', + DEPARTMENT = 'DEPARTMENT' +} diff --git a/src/collections/infra/repositories/transformers/CollectionPayload.ts b/src/collections/infra/repositories/transformers/CollectionPayload.ts index 4b63d715..afd34a6d 100644 --- a/src/collections/infra/repositories/transformers/CollectionPayload.ts +++ b/src/collections/infra/repositories/transformers/CollectionPayload.ts @@ -9,6 +9,10 @@ export interface CollectionPayload { description?: string isPartOf: OwnerNodePayload inputLevels?: CollectionInputLevelPayload[] + dataverseContacts?: CollectionContactPayload[] + dataverseType: string + usesMetadataFieldsFromParent: boolean + usesBrowseSearchFacetsFromParent: boolean } export interface CollectionInputLevelPayload { @@ -16,3 +20,8 @@ export interface CollectionInputLevelPayload { required: boolean include: boolean } + +export interface CollectionContactPayload { + contactEmail: string + displayOrder: number +} diff --git a/src/collections/infra/repositories/transformers/collectionTransformers.ts b/src/collections/infra/repositories/transformers/collectionTransformers.ts index 9c4afd79..aad601bc 100644 --- a/src/collections/infra/repositories/transformers/collectionTransformers.ts +++ b/src/collections/infra/repositories/transformers/collectionTransformers.ts @@ -1,6 +1,10 @@ import { Collection, CollectionInputLevel } from '../../../domain/models/Collection' import { AxiosResponse } from 'axios' -import { CollectionInputLevelPayload, CollectionPayload } from './CollectionPayload' +import { + CollectionContactPayload, + CollectionInputLevelPayload, + CollectionPayload +} from './CollectionPayload' import { transformPayloadToOwnerNode } from '../../../../core/infra/repositories/transformers/dvObjectOwnerNodeTransformer' import { transformHtmlToMarkdown } from '../../../../datasets/infra/repositories/transformers/datasetTransformers' import { CollectionFacet } from '../../../domain/models/CollectionFacet' @@ -15,6 +19,8 @@ import { transformFilePreviewPayloadToFilePreview } from '../../../../files/infr import { transformCollectionPreviewPayloadToCollectionPreview } from './collectionPreviewsTransformers' import { CollectionPreviewPayload } from './CollectionPreviewPayload' import { CollectionPreview } from '../../../domain/models/CollectionPreview' +import { CollectionContact } from '../../../domain/models/CollectionContact' +import { CollectionType } from '../../../domain/models/CollectionType' export const transformCollectionResponseToCollection = (response: AxiosResponse): Collection => { const collectionPayload = response.data.data @@ -39,6 +45,9 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col name: collectionPayload.name, isReleased: collectionPayload.isReleased, affiliation: collectionPayload.affiliation, + type: collectionPayload.dataverseType as CollectionType, + usesMetadataFieldsFromParent: true, // collectionPayload.usesMetadataFieldsFromParent // TODO:ME - Remove hardcoded value once https://github.com/IQSS/dataverse/issues/11012 is done + usesBrowseSearchFacetsFromParent: true, // collectionPayload.usesBrowseSearchFacetsFromParent collectionPayload.usesMetadataFieldsFromParent // TODO:ME - Remove hardcoded value once https://github.com/IQSS/dataverse/issues/11012 is done ...(collectionPayload.description && { description: transformHtmlToMarkdown(collectionPayload.description) }), @@ -47,6 +56,9 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col }), ...(collectionPayload.inputLevels && { inputLevels: transformInputLevelsPayloadToInputLevels(collectionPayload.inputLevels) + }), + ...(collectionPayload.dataverseContacts && { + contacts: transformContactsPayloadToContacts(collectionPayload.dataverseContacts) }) } return collectionModel @@ -90,3 +102,12 @@ export const transformCollectionItemsResponseToCollectionItemSubset = ( totalItemCount: responseDataPayload.total_count } } + +const transformContactsPayloadToContacts = ( + contactsPayload: CollectionContactPayload[] +): CollectionContact[] => { + return contactsPayload.map((contactPayload) => ({ + email: contactPayload.contactEmail, + displayOrder: contactPayload.displayOrder + })) +} From 654db9d34189134401bd7700181e832121c40f1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Mon, 11 Nov 2024 13:21:05 -0300 Subject: [PATCH 2/4] test: add integration test --- .../collections/CollectionsRepository.test.ts | 5 ++++ .../collections/collectionHelper.ts | 25 ++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/test/integration/collections/CollectionsRepository.test.ts b/test/integration/collections/CollectionsRepository.test.ts index 81140cbe..1265f17b 100644 --- a/test/integration/collections/CollectionsRepository.test.ts +++ b/test/integration/collections/CollectionsRepository.test.ts @@ -23,6 +23,7 @@ import { CollectionPayload } from '../../../src/collections/infra/repositories/t import { uploadFileViaApi } from '../../testHelpers/files/filesHelper' import { deleteUnpublishedDatasetViaApi } from '../../testHelpers/datasets/datasetHelper' import { PublicationStatus } from '../../../src/core/domain/models/PublicationStatus' +import { CollectionType } from '../../../src/collections/domain/models/CollectionType' describe('CollectionsRepository', () => { const testCollectionAlias = 'collectionsRepositoryTestCollection' @@ -61,6 +62,10 @@ describe('CollectionsRepository', () => { expect(actual.affiliation).toBe(undefined) expect(actual.description).toBe('The root dataverse.') expect(actual.inputLevels).toBe(undefined) + expect(actual.type).toBe(CollectionType.UNCATEGORIZED) + expect(actual.contacts).toEqual([{ email: 'root@mailinator.com', displayOrder: 0 }]) + expect(actual.usesMetadataFieldsFromParent).toBe(true) + expect(actual.usesBrowseSearchFacetsFromParent).toBe(true) }) test('should return isReleased is true for root collection', async () => { diff --git a/test/testHelpers/collections/collectionHelper.ts b/test/testHelpers/collections/collectionHelper.ts index c2ecccf3..67fa09ed 100644 --- a/test/testHelpers/collections/collectionHelper.ts +++ b/test/testHelpers/collections/collectionHelper.ts @@ -3,9 +3,10 @@ import { DvObjectType } from '../../../src' import { CollectionPayload } from '../../../src/collections/infra/repositories/transformers/CollectionPayload' import { TestConstants } from '../TestConstants' import axios from 'axios' -import { CollectionDTO, CollectionType } from '../../../src/collections/domain/dtos/CollectionDTO' +import { CollectionDTO } from '../../../src/collections/domain/dtos/CollectionDTO' import { NewCollectionRequestPayload } from '../../../src/collections/infra/repositories/CollectionsRepository' import { CollectionFacetPayload } from '../../../src/collections/infra/repositories/transformers/CollectionFacetPayload' +import { CollectionType } from '../../../src/collections/domain/models/CollectionType' const COLLECTION_ID = 11111 const COLLECTION_IS_RELEASED = true @@ -35,7 +36,16 @@ export const createCollectionModel = (): Collection => { required: true, include: true } - ] + ], + type: CollectionType.UNCATEGORIZED, + contacts: [ + { + email: 'dataverse@test.com', + displayOrder: 0 + } + ], + usesMetadataFieldsFromParent: true, + usesBrowseSearchFacetsFromParent: true } return collectionModel } @@ -55,7 +65,16 @@ export const createCollectionPayload = (): CollectionPayload => { required: true, include: true } - ] + ], + dataverseType: CollectionType.UNCATEGORIZED, + dataverseContacts: [ + { + contactEmail: 'dataverse@test.com', + displayOrder: 0 + } + ], + usesBrowseSearchFacetsFromParent: true, + usesMetadataFieldsFromParent: true } return collectionPayload } From f3747d30210ba1bb20673079466515400836b418 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Tue, 12 Nov 2024 09:59:09 -0300 Subject: [PATCH 3/4] feat: change property names --- src/collections/domain/models/Collection.ts | 4 ++-- .../infra/repositories/transformers/CollectionPayload.ts | 4 ++-- .../repositories/transformers/collectionTransformers.ts | 4 ++-- test/environment/.env | 2 +- .../integration/collections/CollectionsRepository.test.ts | 4 ++-- test/testHelpers/collections/collectionHelper.ts | 8 ++++---- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/collections/domain/models/Collection.ts b/src/collections/domain/models/Collection.ts index 9aeb1f2b..d2016e84 100644 --- a/src/collections/domain/models/Collection.ts +++ b/src/collections/domain/models/Collection.ts @@ -13,8 +13,8 @@ export interface Collection { inputLevels?: CollectionInputLevel[] type: CollectionType contacts?: CollectionContact[] - usesMetadataFieldsFromParent: boolean - usesBrowseSearchFacetsFromParent: boolean + isMetadataBlockRoot: boolean + isFacetRoot: boolean } export interface CollectionInputLevel { diff --git a/src/collections/infra/repositories/transformers/CollectionPayload.ts b/src/collections/infra/repositories/transformers/CollectionPayload.ts index afd34a6d..2323bf1a 100644 --- a/src/collections/infra/repositories/transformers/CollectionPayload.ts +++ b/src/collections/infra/repositories/transformers/CollectionPayload.ts @@ -11,8 +11,8 @@ export interface CollectionPayload { inputLevels?: CollectionInputLevelPayload[] dataverseContacts?: CollectionContactPayload[] dataverseType: string - usesMetadataFieldsFromParent: boolean - usesBrowseSearchFacetsFromParent: boolean + isMetadataBlockRoot: boolean + isFacetRoot: boolean } export interface CollectionInputLevelPayload { diff --git a/src/collections/infra/repositories/transformers/collectionTransformers.ts b/src/collections/infra/repositories/transformers/collectionTransformers.ts index aad601bc..34ffe390 100644 --- a/src/collections/infra/repositories/transformers/collectionTransformers.ts +++ b/src/collections/infra/repositories/transformers/collectionTransformers.ts @@ -46,8 +46,8 @@ const transformPayloadToCollection = (collectionPayload: CollectionPayload): Col isReleased: collectionPayload.isReleased, affiliation: collectionPayload.affiliation, type: collectionPayload.dataverseType as CollectionType, - usesMetadataFieldsFromParent: true, // collectionPayload.usesMetadataFieldsFromParent // TODO:ME - Remove hardcoded value once https://github.com/IQSS/dataverse/issues/11012 is done - usesBrowseSearchFacetsFromParent: true, // collectionPayload.usesBrowseSearchFacetsFromParent collectionPayload.usesMetadataFieldsFromParent // TODO:ME - Remove hardcoded value once https://github.com/IQSS/dataverse/issues/11012 is done + isMetadataBlockRoot: collectionPayload.isMetadataBlockRoot, + isFacetRoot: collectionPayload.isFacetRoot, ...(collectionPayload.description && { description: transformHtmlToMarkdown(collectionPayload.description) }), diff --git a/test/environment/.env b/test/environment/.env index 6e32dcbb..340ef3b0 100644 --- a/test/environment/.env +++ b/test/environment/.env @@ -2,5 +2,5 @@ POSTGRES_VERSION=13 DATAVERSE_DB_USER=dataverse SOLR_VERSION=9.3.0 DATAVERSE_IMAGE_REGISTRY=ghcr.io -DATAVERSE_IMAGE_TAG=10904-edit-dataverse-collection +DATAVERSE_IMAGE_TAG=11012-get-dataverse-api-ext DATAVERSE_BOOTSTRAP_TIMEOUT=5m diff --git a/test/integration/collections/CollectionsRepository.test.ts b/test/integration/collections/CollectionsRepository.test.ts index 1265f17b..e4094730 100644 --- a/test/integration/collections/CollectionsRepository.test.ts +++ b/test/integration/collections/CollectionsRepository.test.ts @@ -64,8 +64,8 @@ describe('CollectionsRepository', () => { expect(actual.inputLevels).toBe(undefined) expect(actual.type).toBe(CollectionType.UNCATEGORIZED) expect(actual.contacts).toEqual([{ email: 'root@mailinator.com', displayOrder: 0 }]) - expect(actual.usesMetadataFieldsFromParent).toBe(true) - expect(actual.usesBrowseSearchFacetsFromParent).toBe(true) + expect(actual.isMetadataBlockRoot).toBe(true) + expect(actual.isFacetRoot).toBe(true) }) test('should return isReleased is true for root collection', async () => { diff --git a/test/testHelpers/collections/collectionHelper.ts b/test/testHelpers/collections/collectionHelper.ts index 67fa09ed..f2d2e5ae 100644 --- a/test/testHelpers/collections/collectionHelper.ts +++ b/test/testHelpers/collections/collectionHelper.ts @@ -44,8 +44,8 @@ export const createCollectionModel = (): Collection => { displayOrder: 0 } ], - usesMetadataFieldsFromParent: true, - usesBrowseSearchFacetsFromParent: true + isMetadataBlockRoot: true, + isFacetRoot: true } return collectionModel } @@ -73,8 +73,8 @@ export const createCollectionPayload = (): CollectionPayload => { displayOrder: 0 } ], - usesBrowseSearchFacetsFromParent: true, - usesMetadataFieldsFromParent: true + isMetadataBlockRoot: true, + isFacetRoot: true } return collectionPayload } From 7d31a701bd1bc38c85ac3a10100f0fb9d40ef3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Germ=C3=A1n=20Saracca?= Date: Thu, 14 Nov 2024 08:30:22 -0300 Subject: [PATCH 4/4] chore: back to unstable image for tests --- test/environment/.env | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/environment/.env b/test/environment/.env index 340ef3b0..80e9a14e 100644 --- a/test/environment/.env +++ b/test/environment/.env @@ -1,6 +1,6 @@ POSTGRES_VERSION=13 DATAVERSE_DB_USER=dataverse SOLR_VERSION=9.3.0 -DATAVERSE_IMAGE_REGISTRY=ghcr.io -DATAVERSE_IMAGE_TAG=11012-get-dataverse-api-ext +DATAVERSE_IMAGE_REGISTRY=docker.io +DATAVERSE_IMAGE_TAG=unstable DATAVERSE_BOOTSTRAP_TIMEOUT=5m