Skip to content

Commit

Permalink
Move basic validation back to Seed
Browse files Browse the repository at this point in the history
  • Loading branch information
elsom25 committed May 22, 2024
1 parent 009a5e3 commit 266073c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 31 deletions.
16 changes: 16 additions & 0 deletions db/seed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,22 @@ def import_taxonomy!(values_data:, attributes_data:, verticals_data:)
vputs(" ✓ Imported #{Category.verticals.count} verticals with #{Category.count} categories")

vputs(" → Validating taxonomy...")
if values_data.size != Value.count
vputs(" ✗ Import failed. Values count mismatch")
exit(1)
elsif attributes_data["base_attributes"].size != Attribute.base.count
vputs(" ✗ Import failed. Base attributes count mismatch")
exit(1)
elsif attributes_data["extended_attributes"].size != Attribute.extended.count
vputs(" ✗ Import failed. Extended attributes count mismatch")
exit(1)
elsif verticals_data.size != Category.verticals.count
vputs(" ✗ Import failed. Verticals count mismatch")
exit(1)
elsif verticals_data.sum(&:size) != Category.count
vputs(" ✗ Import failed. Categories count mismatch")
exit(1)
end
[Value, Attribute, AttributesValue, Category, CategoriesAttribute].each do |model|
if model.count.zero?
vputs(" ✗ Import failed. No #{model.name.pluralize} found")
Expand Down
31 changes: 0 additions & 31 deletions test/integration/all_data_files_import_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,6 @@ def after_all
end
end

test "AttributeValues are correctly imported from values.yml" do
assert_equal @raw_values_data.size, Value.count
end

test "AttributeValues are consistent with values.yml" do
@raw_values_data.each do |raw_value|
deserialized_value = Value.new_from_data(raw_value)
Expand All @@ -64,10 +60,6 @@ def after_all
end
end

test "Attributes are correctly imported from attributes.yml" do
assert_equal @raw_attributes_data.values.flat_map { _1 }.size, Attribute.count
end

test "Attributes are consistent with attributes.yml" do
base_attributes = @raw_attributes_data["base_attributes"]
extended_attributes = @raw_attributes_data["extended_attributes"]
Expand Down Expand Up @@ -104,17 +96,6 @@ def after_all
end
end

test "Attributes are all valid" do
Attribute.all.each do |attribute|
assert_predicate attribute, :valid?
end
end

test "Categories are fully imported from categories/*.yml" do
assert_equal @raw_verticals_data.size, Category.verticals.count
assert_equal @raw_verticals_data.map(&:size).sum, Category.count
end

test "Categories are consistent with categories/*.yml" do
@raw_verticals_data.flatten.each do |raw_category|
deserialized_category = Category.new_from_data(raw_category)
Expand All @@ -126,12 +107,6 @@ def after_all
end
end

test "Categories are all valid" do
Category.all.each do |category|
assert_predicate category, :valid?
end
end

test "Category ↔ Attribute relationships are consistent with categories/*.yml" do
@raw_verticals_data.flatten.each do |raw_category|
properties_via_raw_category_id = Category.find(raw_category.fetch("id")).related_attributes
Expand Down Expand Up @@ -196,12 +171,6 @@ def after_all
assert_includes real_value_friendly_ids, "snowboard_construction__rocker"
end

test "MappingRules are fully imported from integrations/*/*/mappings/*_shopify.yml" do
assert_equal @raw_mapping_rules_data.size,
MappingRule.select(:integration_id, :from_shopify).distinct.to_a.count
assert_equal @raw_mapping_rules_data.map { |raw| raw[:content]["rules"].count }.sum, MappingRule.count
end

test "MappingRule ↔ Product relationships are consistent with integrations/*/*/mappings/*_shopify.yml" do
@raw_mapping_rules_data.each do |raw|
from_shopify = File.basename(raw[:file_name], ".*").split("_")[0] == "from"
Expand Down

0 comments on commit 266073c

Please sign in to comment.