Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promo Migrator: Ignore missing rules and actions #63

Merged
merged 1 commit into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/solidus_friendly_promotions/promotion_migrator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ def call
generate_new_promotion_rules(old_promotion_rule)
end
new_promotion.actions = promotion.actions.flat_map do |old_promotion_action|
generate_new_promotion_actions(old_promotion_action).tap do |new_promotion_action|
generate_new_promotion_actions(old_promotion_action)&.tap do |new_promotion_action|
new_promotion_action.original_promotion_action = old_promotion_action
end
end
end.compact
new_promotion.save!
copy_promotion_code_batches(new_promotion)
copy_promotion_codes(new_promotion)
Expand Down Expand Up @@ -79,7 +79,7 @@ def generate_new_promotion_actions(old_promotion_action)
promo_action_config = promotion_map[:actions][old_promotion_action.class]
if promo_action_config.nil?
puts("#{old_promotion_action.class} is not supported")
return []
return nil
end
promo_action_config.call(old_promotion_action)
end
Expand Down
15 changes: 15 additions & 0 deletions spec/lib/solidus_friendly_promotions/promotion_migrator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,19 @@
expect(promotion_code_batch.base_code).to eq("DISNEY4LIFE")
end
end

context "if our rules and actions are missing from the promotion map" do
let(:promotion_map) do
{
rules: {},
actions: {}
}
end

it "still creates the promotion, but without rules or actions" do
subject
expect(Spree::Promotion.count).not_to be_zero
expect(SolidusFriendlyPromotions::Promotion.count).to eq(Spree::Promotion.count)
end
end
end