Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/graphql/types/record_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ def publication_information
end

def file_formats
@object['file_formats'].uniq
@object['file_formats']&.uniq
end

def imprint
Expand Down
33 changes: 33 additions & 0 deletions test/graphql/types/record_type_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
require 'test_helper'
Comment thread
qltysh[bot] marked this conversation as resolved.

class RecordTypeTest < ActiveSupport::TestCase
# Test that file_formats handles missing key gracefully
test 'file_formats returns nil when file_formats key is missing' do
record_data = { 'title' => 'Test Record' }
record_type = Types::RecordType.send(:new, record_data, {})

result = record_type.file_formats
assert_nil result, 'file_formats should return nil when key is missing'
end

# Test that file_formats handles explicit nil gracefully
test 'file_formats returns nil when file_formats is nil' do
record_data = { 'title' => 'Test Record', 'file_formats' => nil }
record_type = Types::RecordType.send(:new, record_data, {})

result = record_type.file_formats
assert_nil result, 'file_formats should return nil when value is nil'
end

# Test that file_formats works correctly when data is present
test 'file_formats returns unique formats when present' do
record_data = {
'title' => 'Test Record',
'file_formats' => %w[PDF PDF EPUB PDF]
}
record_type = Types::RecordType.send(:new, record_data, {})

result = record_type.file_formats
assert_equal %w[PDF EPUB], result, 'file_formats should return unique values'
end
end