Skip to content

Commit

Permalink
add&fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
stbnrivas committed Apr 29, 2021
1 parent 57d273c commit 3a2f1e8
Showing 1 changed file with 27 additions and 5 deletions.
32 changes: 27 additions & 5 deletions test/controllers/gobierto_data/api/v1/datasets_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ def datasets_md_with_translations
@datasets_md_with_translations ||= gobierto_common_custom_fields(:madrid_data_datasets_custom_field_md_with_translations)
end

def datasets_descriptions
@datasets_descriptions ||= gobierto_common_custom_fields(:madrid_data_datasets_custom_field_description)
end

def other_site_dataset
@other_site_dataset ||= gobierto_data_datasets(:santander_dataset)
end
Expand All @@ -93,7 +97,8 @@ def array_data(dataset)
dataset.rails_model&.columns_hash&.transform_values(&:type)&.to_s,
GobiertoCommon::CustomFieldRecord.find_by(item: dataset, custom_field: datasets_category)&.value_string,
GobiertoCommon::CustomFieldRecord.find_by(item: dataset, custom_field: datasets_md_without_translations)&.value_string,
GobiertoCommon::CustomFieldRecord.find_by(item: dataset, custom_field: datasets_md_with_translations)&.value_string
GobiertoCommon::CustomFieldRecord.find_by(item: dataset, custom_field: datasets_md_with_translations)&.value_string || "",
GobiertoCommon::CustomFieldRecord.find_by(item: dataset, custom_field: datasets_descriptions)&.value_string
]
end

Expand Down Expand Up @@ -168,8 +173,9 @@ def test_index_as_csv
parsed_csv = CSV.parse(response_data).map { |row| row.map(&:to_s) }

assert_equal active_datasets_count + 1, parsed_csv.count
assert_equal %w(id name slug table_name data_updated_at columns category md-without-translations md-with-translations), parsed_csv.first
assert_includes parsed_csv, array_data(dataset)
assert_equal %w(id name slug table_name data_updated_at columns category md-without-translations md-with-translations description), parsed_csv.first

assert_includes parsed_csv.drop(1).take(1), array_data(dataset)
refute_includes parsed_csv, array_data(other_site_dataset)
end
end
Expand Down Expand Up @@ -202,7 +208,7 @@ def test_index_xlsx_format
assert_equal 1, parsed_xlsx.worksheets.count
sheet = parsed_xlsx.worksheets.first
assert_nil sheet[active_datasets_count + 1]
assert_equal %w(id name slug table_name data_updated_at columns category md-without-translations md-with-translations), sheet[0].cells.map(&:value)
assert_equal %w(id name slug table_name data_updated_at columns category md-without-translations md-with-translations description), sheet[0].cells.map(&:value)
values = (1..active_datasets_count).map do |row_number|
sheet[row_number].cells.map { |cell| cell.value.to_s }
end
Expand Down Expand Up @@ -315,12 +321,28 @@ def test_index_when_md_custom_field_changes_translations_availability
parsed_csv = CSV.parse(response_data).map { |row| row.map(&:to_s) }

assert_equal active_datasets_count + 1, parsed_csv.count
assert_equal %w(id name slug table_name data_updated_at columns category md-without-translations md-with-translations), parsed_csv.first
assert_equal %w(id name slug table_name data_updated_at columns category md-without-translations md-with-translations description), parsed_csv.first
assert_includes parsed_csv, array_data(dataset)
refute_includes parsed_csv, array_data(other_site_dataset)
end
end

def test_catalog
with(site: site) do
get catalog_gobierto_data_api_v1_datasets_path(format: :xml), as: :xml
assert_response :success

response_xml = response.parsed_body
assert_includes response_xml, '<?xml version="1.0" encoding="utf-8" ?>'
assert_includes response_xml, '<rdf:RDF'
assert_includes response_xml, '<dcat:Catalog rdf:about="https://data.some.org/catalog">'
assert_includes response_xml, '<dcat:dataset>'
assert_includes response_xml, '</dcat:dataset>'
assert_includes response_xml, '</dcat:Catalog>'
assert_includes response_xml, '</rdf:RDF>'
end
end

end
end
end
Expand Down

0 comments on commit 3a2f1e8

Please sign in to comment.