Skip to content

Commit

Permalink
Add tests to ensure associations are setup correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
elsom25 committed Mar 21, 2024
1 parent c3622d0 commit 015d5f2
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions test/integration/all_data_files_import_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 <sg-4-17-2-17> 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

0 comments on commit 015d5f2

Please sign in to comment.