From 459444225d58c5b5957a56fe029c80a511845d28 Mon Sep 17 00:00:00 2001 From: Justin Coyne Date: Mon, 21 Sep 2020 15:34:50 -0500 Subject: [PATCH] Rollback accepting an integer value in the description Committee can't decide which type this is. See https://github.com/interagent/committee/issues/286 Fixes https://github.com/sul-dlss/argo/issues/2253 Ref https://github.com/sul-dlss/cocina-models/pull/144 --- openapi.yml | 4 ++- spec/requests/update_metadata_spec.rb | 52 ++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 2 deletions(-) diff --git a/openapi.yml b/openapi.yml index 7154b846eb..bdbe078b35 100644 --- a/openapi.yml +++ b/openapi.yml @@ -1381,7 +1381,9 @@ components: description: String or integer value of the descriptive element. oneOf: - type: string - - type: integer + # Title note (nonsorting character count) was supposed to be able to accept an integer value, + # but this triggered a bug in comittee: + # - type: integer type: description: Type of value provided by the descriptive element. type: string diff --git a/spec/requests/update_metadata_spec.rb b/spec/requests/update_metadata_spec.rb index d8498f359d..7623a5b429 100644 --- a/spec/requests/update_metadata_spec.rb +++ b/spec/requests/update_metadata_spec.rb @@ -65,6 +65,11 @@ identification: identification, structural: structural) end + + let(:description) do + { title: [{ value: title }] } + end + let(:data) do <<~JSON { @@ -78,7 +83,7 @@ "useAndReproductionStatement":"Property rights reside with the repository..." }, "administrative":{"releaseTags":[],"hasAdminPolicy":"druid:dd999df4567","partOfProject":"Google Books"}, - "description":{"title":[{"value":"#{title}"}]}, + "description":#{description.to_json}, "identification":#{identification.to_json}, "structural":{ "hasMemberOrders":[{"viewingDirection":"right-to-left"}], @@ -106,6 +111,51 @@ expect(AdministrativeTags).to have_received(:create).with(pid: druid, tags: ['Project : Google Books']) end + context 'with a structured title that has nonsorting characters' do + # This tests the problem found in https://github.com/sul-dlss/argo/issues/2253 + # where an integer value in a string field was being detected as invalid data. + let(:description) do + { + title: [ + { structuredValue: [ + { value: 'The', "type": 'nonsorting characters' }, + { value: 'romantic Bach', "type": 'main title' }, + { value: "a celebration of Bach's most romantic music", "type": 'subtitle' }, + { note: [{ "value": '4', "type": 'nonsorting character count' }] } + ] } + ] + } + end + + let(:ng_xml) do + Nokogiri::XML <<~XML + + + The + romantic Bach + a celebration of Bach's most romantic music + + + XML + end + + let(:item) do + Dor::Item.new(pid: druid).tap do |item| + item.descMetadata.content = ng_xml.to_xml + end + end + + it 'accepts the request with a supplied nonsorting character count' do + patch "/v1/objects/#{druid}", + params: data, + headers: { 'Authorization' => "Bearer #{jwt}", 'Content-Type' => 'application/json' } + expect(response.status).to eq(200) + expect(item).to have_received(:save!) + end + end + context 'with a structured title' do let(:expected) do Cocina::Models::DRO.new(externalIdentifier: druid,