Skip to content

Commit

Permalink
Refactor, rebase and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Genia Kazymova committed Dec 12, 2023
1 parent 4364992 commit 910389b
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
9 changes: 4 additions & 5 deletions lib/trln_argon/solr_document/highwire_field_mapping.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

module TrlnArgon
module SolrDocument
module HighwireFieldMapping
# https://raw.githubusercontent.com/zotero/translators/db2771d52d89d1480ff98efbd6968565893f2184/Embedded%20Metadata.js
MAPPING = {
'title_main' => 'citation_title',
'publication_year_sort' => 'citation_publication_date',
Expand All @@ -26,11 +25,11 @@ def highwire_metadata_tags

private

def process_docvalue(result, metadata_key, docvalue)
def process_docvalue(result, key, docvalue)
if docvalue.is_a?(Array)
docvalue.each { |dv| result << [metadata_key, dv] }
docvalue.each { |dv| result << [key, dv] }
else
result << [metadata_key, docvalue]
result << [key, docvalue]
end
end

Expand Down
48 changes: 48 additions & 0 deletions spec/lib/trln_argon/highwire_field_mapping_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
describe TrlnArgon::SolrDocument::HighwireFieldMapping do
include described_class
class SolrDocumentTestClass
include Blacklight::Solr::Document
include TrlnArgon::SolrDocument
end

describe '#highwire_metadata_tags' do
let(:document1) do
SolrDocumentTestClass.new(
'title_main' => 'Title',
'publisher_a' => 'Publisher',
'publication_year_sort' => '2023',
'isbn_number_a' => '12345678',
'publisher_location_a' => 'Durham',
'statement_of_responsibility_a' => [
{ name: 'Author 1', rel: 'author' },
{ name: 'Author 2', rel: 'editor' }
]
)
end

let(:document2) do
SolrDocumentTestClass.new(
'title_main' => 'Title',
'publisher_a' => 'Publisher'
)
end

it 'generates metadata tags based on the mapping' do
result = document1.highwire_metadata_tags
expect(result).to include(
['citation_title', 'Title'],
['citation_publisher', 'Publisher'],
['citation_publication_date', '2023'],
['citation_place', 'Durham'],
['citation_isbn', '12345678'],
['citation_author', { 'name' => 'Author 1', 'rel' => 'author' }],
['citation_author', { 'name' => 'Author 2', 'rel' => 'editor' }]
)
end

it 'does not include citation_author if there are no authors' do
result = document2.highwire_metadata_tags
expect(result).not_to include(['citation_author'])
end
end
end

0 comments on commit 910389b

Please sign in to comment.