From 9fccb15e3a533f2c141abb30858cd372c8e73a81 Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Mon, 6 Nov 2023 14:29:50 +0000 Subject: [PATCH] add tests for dto functions --- src/fragmentarium/domain/archaeology.test.ts | 99 +++++++++++++++++++- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/src/fragmentarium/domain/archaeology.test.ts b/src/fragmentarium/domain/archaeology.test.ts index fed8fcaf6..6b999bcdd 100644 --- a/src/fragmentarium/domain/archaeology.test.ts +++ b/src/fragmentarium/domain/archaeology.test.ts @@ -1,18 +1,111 @@ -import { archaeologyFactory } from 'test-support/fragment-fixtures' +import _ from 'lodash' import { + archaeologyFactory, + dateRangeFactory, + findspotFactory, +} from 'test-support/fragment-fixtures' +import { + FindspotDto, + SiteKey, createArchaeology, + excavationSites, + fromDateRangeDto, + fromFindspotDto, + fromPlanDto, toArchaeologyDto, + toDateRangeDto, toFindspotDto, + toPlanDto, } from './archaeology' import MuseumNumber, { museumNumberToString } from './MuseumNumber' +import { + cslDataFactory, + referenceDtoFactory, +} from 'test-support/bibliography-fixtures' +import createReference from 'bibliography/application/createReference' const excavationNumber: MuseumNumber = { prefix: 'A', number: '38', suffix: '', } -const archaeology = archaeologyFactory.build({ - excavationNumber: museumNumberToString(excavationNumber), +const site: SiteKey = 'Assyria' + +const cslData = cslDataFactory.build() +const referenceDto = referenceDtoFactory.build( + { id: cslData.id }, + { associations: { document: cslData } } +) +const reference = createReference(referenceDto) +const planDto = { + svg: '', + references: [referenceDto], +} +const plan = { svg: '', references: [reference] } +const dateRange = dateRangeFactory.build() +const dateRangeDto = { + start: dateRange.start?.toString(), + end: dateRange.end?.toString(), + notes: dateRange.notes, +} +const findspot = findspotFactory.build({ + site: excavationSites[site], + dateRange: dateRange, + plans: [plan], +}) +const findspotDto: FindspotDto = { + ..._.pick( + findspot, + 'area', + 'building', + 'buildingType', + 'levelLayerPhase', + 'room', + 'context', + 'primaryContext', + 'notes' + ), + _id: findspot.id, + site: site, + dateRange: dateRangeDto, + plans: [planDto], +} +const archaeology = archaeologyFactory.build( + { + excavationNumber: museumNumberToString(excavationNumber), + }, + { + associations: { + findspot, + }, + } +) +test('fromDateRangeDto', () => { + expect(fromDateRangeDto(dateRangeDto)).toEqual(dateRange) +}) +test('toDateRangeDto', () => { + expect(toDateRangeDto(dateRange)).toEqual(dateRangeDto) +}) +test('fromPlanDto', () => { + expect(fromPlanDto(planDto)).toEqual(plan) +}) +test('toPlanDto', () => { + expect(toPlanDto(plan)).toEqual(planDto) +}) +test('fromFindspotDto', () => { + expect(fromFindspotDto(findspotDto)).toEqual(findspot) +}) +test('toFindspotDto', () => { + expect(toFindspotDto(findspot)).toEqual(findspotDto) +}) +test('fromDateRangeDto', () => { + expect(fromDateRangeDto(dateRangeDto)).toEqual(dateRange) +}) +test('fromPlanDto', () => { + expect(fromPlanDto(planDto)).toEqual(plan) +}) +test('toDateRangeDto', () => { + expect(toDateRangeDto(dateRange)).toEqual(dateRangeDto) }) test('toArchaeologyDto', () => {