From 3a2f1e882fad743505a7e1e774809f06d471e64a Mon Sep 17 00:00:00 2001 From: stbn Date: Thu, 29 Apr 2021 15:59:07 +0200 Subject: [PATCH] add&fix test --- .../api/v1/datasets_controller_test.rb | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/test/controllers/gobierto_data/api/v1/datasets_controller_test.rb b/test/controllers/gobierto_data/api/v1/datasets_controller_test.rb index a72cf5eda3..e48e5f3020 100644 --- a/test/controllers/gobierto_data/api/v1/datasets_controller_test.rb +++ b/test/controllers/gobierto_data/api/v1/datasets_controller_test.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -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, '' + assert_includes response_xml, '' + assert_includes response_xml, '' + assert_includes response_xml, '' + assert_includes response_xml, '' + assert_includes response_xml, '' + end + end + end end end