From c59fbb6458309645965d5d1dfc1addcbfe99b74b Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Sat, 18 Nov 2023 18:50:30 +0000 Subject: [PATCH 1/8] update accession interface --- src/fragmentarium/domain/FragmentDtos.ts | 2 +- src/fragmentarium/infrastructure/FragmentRepository.ts | 1 + src/test-support/fragment-fixtures.ts | 2 +- src/test-support/test-fragment.ts | 8 ++++++-- 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/fragmentarium/domain/FragmentDtos.ts b/src/fragmentarium/domain/FragmentDtos.ts index 9b98ccce8..58ad7de72 100644 --- a/src/fragmentarium/domain/FragmentDtos.ts +++ b/src/fragmentarium/domain/FragmentDtos.ts @@ -80,7 +80,7 @@ export type ExternalNumbers = { export default interface FragmentDto { museumNumber: MuseumNumber - accession: string + accession: MuseumNumber editedInOraccProject: string publication: string description: string diff --git a/src/fragmentarium/infrastructure/FragmentRepository.ts b/src/fragmentarium/infrastructure/FragmentRepository.ts index c6676ff33..4f2bc018b 100644 --- a/src/fragmentarium/infrastructure/FragmentRepository.ts +++ b/src/fragmentarium/infrastructure/FragmentRepository.ts @@ -81,6 +81,7 @@ function createFragment(dto: FragmentDto): Fragment { return Fragment.create({ ...dto, number: museumNumberToString(dto.museumNumber), + accession: museumNumberToString(dto.accession), museum: Museum.of(dto.museum), joins: createJoins(dto.joins), measures: { diff --git a/src/test-support/fragment-fixtures.ts b/src/test-support/fragment-fixtures.ts index 5a133e1b8..4ec4dab54 100644 --- a/src/test-support/fragment-fixtures.ts +++ b/src/test-support/fragment-fixtures.ts @@ -234,7 +234,7 @@ export const fragmentFactory = Factory.define( const museumNumber = `${chance.word()}.${sequence}` return new Fragment( museumNumber, - chance.word(), + `${chance.word()}.${sequence}`, chance.sentence({ words: 4 }), associations.joins ?? [ [ diff --git a/src/test-support/test-fragment.ts b/src/test-support/test-fragment.ts index 78dabd6d2..4aaf82c1a 100644 --- a/src/test-support/test-fragment.ts +++ b/src/test-support/test-fragment.ts @@ -321,7 +321,11 @@ export const fragmentDto: FragmentDto = { number: 'Fragment', suffix: '', }, - accession: '', + accession: { + prefix: 'A', + number: '38', + suffix: 'b', + }, publication: 'electronic Babylonian Library', description: 'A fragment to be used when testing the eBL application', joins: [ @@ -423,7 +427,7 @@ export const fragmentDto: FragmentDto = { export const fragment = new Fragment( 'Test.Fragment', - '', + 'A.38.b', 'electronic Babylonian Library', [ [ From 1b237d22562c04ad0a8753827abc5b0616c7de35 Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Sun, 19 Nov 2023 12:36:44 +0000 Subject: [PATCH 2/8] add missing tests --- .../infrastructure/FragmentRepository.test.ts | 60 ++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/src/fragmentarium/infrastructure/FragmentRepository.test.ts b/src/fragmentarium/infrastructure/FragmentRepository.test.ts index 5863c8e1e..c58a8996e 100644 --- a/src/fragmentarium/infrastructure/FragmentRepository.test.ts +++ b/src/fragmentarium/infrastructure/FragmentRepository.test.ts @@ -13,6 +13,9 @@ import { QueryResult } from 'query/QueryResult' import { FragmentQuery } from 'query/FragmentQuery' import { queryItemFactory } from 'test-support/query-item-factory' import { museumNumberToString } from 'fragmentarium/domain/MuseumNumber' +import { Genre, Genres } from 'fragmentarium/domain/Genres' +import { mesopotamianDateFactory } from 'test-support/date-fixtures' +import { archaeologyFactory } from 'test-support/fragment-fixtures' const apiClient = { fetchJson: jest.fn(), @@ -30,6 +33,12 @@ const folio = new Folio({ name: 'MJG', number: 'K1' }) const word = 'šim' const introduction = 'Introduction' const lemmas = 'foo I+bar II' +const genres: Genre[] = [ + new Genre(['ARCHIVE', 'Letter'], false), + new Genre(['CANONICAL', 'Divination'], true), +] +const mesopotamianDate = mesopotamianDateFactory.build() +const archaeology = archaeologyFactory.build() const museumNumber = { prefix: 'A', number: '7', suffix: '' } const queryResult: QueryResult = { items: [ @@ -314,7 +323,56 @@ const testData: TestData[] = [ fragment, [ `/fragments/${encodeURIComponent(fragmentId)}/introduction`, - { introduction: introduction }, + { introduction }, + ], + Promise.resolve(fragmentDto) + ), + new TestData( + 'updateGenres', + [fragmentId, new Genres(genres)], + apiClient.postJson, + fragment, + [`/fragments/${encodeURIComponent(fragmentId)}/genres`, { genres }], + Promise.resolve(fragmentDto) + ), + new TestData( + 'updateDate', + [fragmentId, mesopotamianDate], + apiClient.postJson, + fragment, + [ + `/fragments/${encodeURIComponent(fragmentId)}/date`, + { date: mesopotamianDate }, + ], + Promise.resolve(fragmentDto) + ), + new TestData( + 'updateDatesInText', + [fragmentId, [mesopotamianDate]], + apiClient.postJson, + fragment, + [ + `/fragments/${encodeURIComponent(fragmentId)}/dates_in_text`, + { datesInText: [mesopotamianDate] }, + ], + Promise.resolve(fragmentDto) + ), + new TestData( + 'updateNotes', + [fragmentId, notes], + apiClient.postJson, + fragment, + [`/fragments/${encodeURIComponent(fragmentId)}/notes`, { notes }], + Promise.resolve(fragmentDto) + ), + new TestData( + 'updateArchaeology', + [fragmentId, archaeology], + apiClient.postJson, + fragment, + [ + `/fragments/${encodeURIComponent(fragmentId)}/archaeology`, + { archaeology }, ], Promise.resolve(fragmentDto) ), From 0160be9434f441631f2dcb235189c69736a18dec Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Tue, 21 Nov 2023 13:57:07 +0000 Subject: [PATCH 3/8] update placeholder --- src/fragmentarium/ui/SearchForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragmentarium/ui/SearchForm.tsx b/src/fragmentarium/ui/SearchForm.tsx index 9f16749bf..7cad69ca0 100644 --- a/src/fragmentarium/ui/SearchForm.tsx +++ b/src/fragmentarium/ui/SearchForm.tsx @@ -154,7 +154,7 @@ class SearchForm extends Component { type="text" name="number" value={this.state.number || ''} - placeholder="Museum, accession, or CDLI number" + placeholder="Museum, accession, CDLI, or ecavation number" aria-label="Number" onChange={( event: React.ChangeEvent From 938b481803f7ba5f08eae12412db6aa88e973d5c Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Tue, 21 Nov 2023 14:18:12 +0000 Subject: [PATCH 4/8] update snapshot --- .../ui/search/__snapshots__/FragmentariumSearch.test.tsx.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/fragmentarium/ui/search/__snapshots__/FragmentariumSearch.test.tsx.snap b/src/fragmentarium/ui/search/__snapshots__/FragmentariumSearch.test.tsx.snap index a2d8d34c0..7529c509b 100644 --- a/src/fragmentarium/ui/search/__snapshots__/FragmentariumSearch.test.tsx.snap +++ b/src/fragmentarium/ui/search/__snapshots__/FragmentariumSearch.test.tsx.snap @@ -82,7 +82,7 @@ exports[`Searching fragments by transliteration Displays corpus results when cli class="form-control" id="number" name="number" - placeholder="Museum, accession, or CDLI number" + placeholder="Museum, accession, CDLI, or ecavation number" type="text" value="" /> From cea7b1800e3f9c20a68540eb3c048e057f07798b Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Wed, 22 Nov 2023 11:21:42 +0000 Subject: [PATCH 5/8] allow empty accession --- src/fragmentarium/domain/FragmentDtos.ts | 2 +- src/fragmentarium/infrastructure/FragmentRepository.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/fragmentarium/domain/FragmentDtos.ts b/src/fragmentarium/domain/FragmentDtos.ts index 58ad7de72..7245913e1 100644 --- a/src/fragmentarium/domain/FragmentDtos.ts +++ b/src/fragmentarium/domain/FragmentDtos.ts @@ -80,7 +80,7 @@ export type ExternalNumbers = { export default interface FragmentDto { museumNumber: MuseumNumber - accession: MuseumNumber + accession: MuseumNumber | null editedInOraccProject: string publication: string description: string diff --git a/src/fragmentarium/infrastructure/FragmentRepository.ts b/src/fragmentarium/infrastructure/FragmentRepository.ts index 4f2bc018b..91faae699 100644 --- a/src/fragmentarium/infrastructure/FragmentRepository.ts +++ b/src/fragmentarium/infrastructure/FragmentRepository.ts @@ -81,7 +81,7 @@ function createFragment(dto: FragmentDto): Fragment { return Fragment.create({ ...dto, number: museumNumberToString(dto.museumNumber), - accession: museumNumberToString(dto.accession), + accession: dto.accession ? museumNumberToString(dto.accession) : '', museum: Museum.of(dto.museum), joins: createJoins(dto.joins), measures: { From d9270f09f92212f69bf8cce283e27f8d40dfeb32 Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Wed, 22 Nov 2023 12:04:26 +0000 Subject: [PATCH 6/8] Fix type errors --- .../application/FragmentSearchService.ts | 2 ++ src/fragmentarium/domain/fragment.ts | 5 ++++- .../infrastructure/FragmentRepository.ts | 12 +++++++++--- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/fragmentarium/application/FragmentSearchService.ts b/src/fragmentarium/application/FragmentSearchService.ts index 7c9d6b4af..848fa2aed 100644 --- a/src/fragmentarium/application/FragmentSearchService.ts +++ b/src/fragmentarium/application/FragmentSearchService.ts @@ -2,10 +2,12 @@ import _ from 'lodash' import Promise from 'bluebird' import { FragmentInfo, + FragmentInfoDto, FragmentInfosPagination, } from 'fragmentarium/domain/fragment' export type FragmentInfosPromise = Promise> +export type FragmentInfosDtoPromise = Promise> export type FragmentInfoPromise = Promise export type FragmentInfosPaginationPromise = Promise diff --git a/src/fragmentarium/domain/fragment.ts b/src/fragmentarium/domain/fragment.ts index c7865684c..fb4a956ed 100644 --- a/src/fragmentarium/domain/fragment.ts +++ b/src/fragmentarium/domain/fragment.ts @@ -10,7 +10,7 @@ import { Joins } from './join' import { MarkupPart } from 'transliteration/domain/markup' import { Period, PeriodModifier } from 'common/period' import { Session } from 'auth/Session' -import { +import FragmentDto, { ExternalNumber, ExternalNumbers, ExternalNumberTypes, @@ -33,6 +33,9 @@ export interface FragmentInfo { readonly genres: Genres } +export type FragmentInfoDto = Omit & + Pick + export interface FragmentInfosPagination { fragmentInfos: readonly FragmentInfo[] totalCount: number diff --git a/src/fragmentarium/infrastructure/FragmentRepository.ts b/src/fragmentarium/infrastructure/FragmentRepository.ts index 91faae699..8e3502476 100644 --- a/src/fragmentarium/infrastructure/FragmentRepository.ts +++ b/src/fragmentarium/infrastructure/FragmentRepository.ts @@ -5,6 +5,7 @@ import produce from 'immer' import { Fragment, FragmentInfo, + FragmentInfoDto, Script, ScriptDto, } from 'fragmentarium/domain/fragment' @@ -19,6 +20,7 @@ import { import Annotation from 'fragmentarium/domain/annotation' import { FragmentInfoRepository, + FragmentInfosDtoPromise, FragmentInfosPromise, } from 'fragmentarium/application/FragmentSearchService' import Reference from 'bibliography/domain/Reference' @@ -107,8 +109,12 @@ function createFragment(dto: FragmentDto): Fragment { }) } -export function createFragmentInfo(dto): FragmentInfo { - return { ...dto, script: createScript(dto.script) } +export function createFragmentInfo(dto: FragmentInfoDto): FragmentInfo { + return { + ...dto, + script: createScript(dto.script), + accession: dto.accession ? museumNumberToString(dto.accession) : '', + } } function createFragmentPath(number: string, ...subResources: string[]): string { @@ -179,7 +185,7 @@ class ApiFragmentRepository ) } - _fetch(params: Record): FragmentInfosPromise { + _fetch(params: Record): FragmentInfosDtoPromise { return this.apiClient.fetchJson(`/fragments?${stringify(params)}`, false) } From 34ec286160de107294fc1fae3c6e6ce35a8edf98 Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Wed, 22 Nov 2023 12:23:33 +0000 Subject: [PATCH 7/8] fix type errors --- .../infrastructure/FragmentRepository.test.ts | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/src/fragmentarium/infrastructure/FragmentRepository.test.ts b/src/fragmentarium/infrastructure/FragmentRepository.test.ts index c58a8996e..50768e346 100644 --- a/src/fragmentarium/infrastructure/FragmentRepository.test.ts +++ b/src/fragmentarium/infrastructure/FragmentRepository.test.ts @@ -1,9 +1,6 @@ import Promise from 'bluebird' import { testDelegation, TestData } from 'test-support/utils' -import FragmentRepository, { - createFragmentInfo, - createScript, -} from './FragmentRepository' +import FragmentRepository, { createScript } from './FragmentRepository' import Folio from 'fragmentarium/domain/Folio' import { fragment, fragmentDto } from 'test-support/test-fragment' import { ApiError } from 'http/ApiClient' @@ -16,6 +13,7 @@ import { museumNumberToString } from 'fragmentarium/domain/MuseumNumber' import { Genre, Genres } from 'fragmentarium/domain/Genres' import { mesopotamianDateFactory } from 'test-support/date-fixtures' import { archaeologyFactory } from 'test-support/fragment-fixtures' +import { FragmentInfo } from 'fragmentarium/domain/fragment' const apiClient = { fetchJson: jest.fn(), @@ -85,32 +83,17 @@ const lineToVecRankingDto = { scoreWeighted: [lineToVecScoreDto], } -const date = { - day: { - value: '1', - }, - isSeleucidEra: true, - month: { - value: '1', - }, - year: { - value: '1', - }, -} - -const fragmentInfo = { +const fragmentInfo: FragmentInfo = { number: 'K.1', - accession: '1234', - script: script, + accession: 'A.1234', + script: createScript(script), description: 'a fragment', matchingLines: null, editor: 'Editor', // eslint-disable-next-line camelcase edition_date: '2019-09-10T13:03:37.575580', references: [], - genres: [], - date: date, - dates: [date], + genres: new Genres([]), } const testData: TestData[] = [ @@ -163,7 +146,7 @@ const testData: TestData[] = [ 'random', [], apiClient.fetchJson, - [createFragmentInfo(fragmentInfo)], + [fragmentInfo], ['/fragments?random=true', false], Promise.resolve([fragmentInfo]) ), @@ -171,7 +154,7 @@ const testData: TestData[] = [ 'interesting', [], apiClient.fetchJson, - [createFragmentInfo(fragmentInfo)], + [fragmentInfo], ['/fragments?interesting=true', false], Promise.resolve([fragmentInfo]) ), @@ -179,7 +162,7 @@ const testData: TestData[] = [ 'fetchLatestTransliterations', [], apiClient.fetchJson, - [createFragmentInfo(fragmentInfo)], + [fragmentInfo], ['/fragments?latest=true', false], Promise.resolve([fragmentInfo]) ), @@ -187,7 +170,7 @@ const testData: TestData[] = [ 'fetchNeedsRevision', [], apiClient.fetchJson, - [createFragmentInfo(fragmentInfo)], + [fragmentInfo], ['/fragments?needsRevision=true', false], Promise.resolve([fragmentInfo]) ), From a39a35f5da701eb0707884251c27f646e9abbb77 Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Wed, 22 Nov 2023 12:28:33 +0000 Subject: [PATCH 8/8] fix tests --- .../infrastructure/FragmentRepository.test.ts | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/fragmentarium/infrastructure/FragmentRepository.test.ts b/src/fragmentarium/infrastructure/FragmentRepository.test.ts index 50768e346..483cde21c 100644 --- a/src/fragmentarium/infrastructure/FragmentRepository.test.ts +++ b/src/fragmentarium/infrastructure/FragmentRepository.test.ts @@ -13,7 +13,7 @@ import { museumNumberToString } from 'fragmentarium/domain/MuseumNumber' import { Genre, Genres } from 'fragmentarium/domain/Genres' import { mesopotamianDateFactory } from 'test-support/date-fixtures' import { archaeologyFactory } from 'test-support/fragment-fixtures' -import { FragmentInfo } from 'fragmentarium/domain/fragment' +import { FragmentInfo, FragmentInfoDto } from 'fragmentarium/domain/fragment' const apiClient = { fetchJson: jest.fn(), @@ -96,6 +96,16 @@ const fragmentInfo: FragmentInfo = { genres: new Genres([]), } +const fragmentInfoDto: FragmentInfoDto = { + ...fragmentInfo, + script, + accession: { + prefix: 'A', + number: '1234', + suffix: '', + }, +} + const testData: TestData[] = [ new TestData( 'statistics', @@ -148,7 +158,7 @@ const testData: TestData[] = [ apiClient.fetchJson, [fragmentInfo], ['/fragments?random=true', false], - Promise.resolve([fragmentInfo]) + Promise.resolve([fragmentInfoDto]) ), new TestData( 'interesting', @@ -156,7 +166,7 @@ const testData: TestData[] = [ apiClient.fetchJson, [fragmentInfo], ['/fragments?interesting=true', false], - Promise.resolve([fragmentInfo]) + Promise.resolve([fragmentInfoDto]) ), new TestData( 'fetchLatestTransliterations', @@ -164,7 +174,7 @@ const testData: TestData[] = [ apiClient.fetchJson, [fragmentInfo], ['/fragments?latest=true', false], - Promise.resolve([fragmentInfo]) + Promise.resolve([fragmentInfoDto]) ), new TestData( 'fetchNeedsRevision', @@ -172,7 +182,7 @@ const testData: TestData[] = [ apiClient.fetchJson, [fragmentInfo], ['/fragments?needsRevision=true', false], - Promise.resolve([fragmentInfo]) + Promise.resolve([fragmentInfoDto]) ), new TestData( 'updateTransliteration',