diff --git a/test/integration/all_data_files_import_test.rb b/test/integration/all_data_files_import_test.rb index d7dfcc0e7..712e17405 100644 --- a/test/integration/all_data_files_import_test.rb +++ b/test/integration/all_data_files_import_test.rb @@ -79,4 +79,64 @@ def before_all assert_predicate category, :valid? end end + + test "Category ↔ Attribute relationships are consistent with categories/*.yml" do + @raw_verticals_data.flatten.each do |raw_category| + real_category = Category.find(raw_category.fetch("id")) + raw_category.fetch("attributes").each do |friendly_id| + real_attribute = Property.find_by(friendly_id:) + assert_includes real_category.properties, real_attribute + end + end + end + + test "Attribute ↔ Value relationships are consistent with attributes.yml" do + Property.all.each do |attribute| + raw_attribute = @raw_attributes_data.find { _1.fetch("id") == attribute.id } + raw_values = raw_attribute.fetch("values") + real_values = attribute.property_values + + assert_equal raw_values.size, real_values.size + raw_values.each do |raw_value| + real_value = real_values.find { _1.id == raw_value.fetch("id") } + assert_equal Serializers::Data::PropertyValueSerializer.deserialize(raw_value), real_value + end + end + end + + # more fragile, but easier sanity check + test "Snowboards category is fully imported and modeled correctly" do + snowboard_id = "sg-4-17-2-17" + raw_snowboard_category = @raw_verticals_data.flatten.find { _1.fetch("id") == snowboard_id } + snowboard_category = Category.find(snowboard_id) + + assert_equal raw_snowboard_category.fetch("name"), snowboard_category.name + assert_empty snowboard_category.children + + raw_snowboard_attributes = raw_snowboard_category.fetch("attributes").sort + assert_equal raw_snowboard_attributes.size, snowboard_category.properties.size + raw_snowboard_attributes + .zip(snowboard_category.properties.reorder(:friendly_id)) + .each do |friendly_id, property| + assert_equal friendly_id, property.friendly_id + end + end + + # more fragile, but easier sanity check + test "Color attribute <1> is fully imported and modeled correctly" do + color_id = 1" + raw_color_attribute = @raw_attributes_data.find { _1.fetch("id") == color_id } + color_attribute = Property.find(color_id) + + assert_equal raw_color_attribute.fetch("name"), color_attribute.name + + raw_color_values = raw_color_attribute.fetch("values").sort_by { _1.fetch("id") } + assert_equal raw_color_values.size, color_attribute.property_values.size + raw_color_values + .zip(color_attribute.property_values.reorder(:id)) + .each do |raw_value, value| + assert_equal raw_value.fetch("id"), value.id + assert_equal raw_value.fetch("name"), value.name + end + end end