Fix multiple subscriptions sort
Dieser Commit ist enthalten in:
Ursprung
705c84dd02
Commit
00ba8425e3
2 geänderte Dateien mit 17 neuen und 6 gelöschten Zeilen
|
@ -117,7 +117,7 @@ class CustomWizard::Subscription
|
||||||
end
|
end
|
||||||
|
|
||||||
id_and_slug = ids_and_slugs.sort do |a, b|
|
id_and_slug = ids_and_slugs.sort do |a, b|
|
||||||
PRODUCT_HIERARCHY[a[:slug]] - PRODUCT_HIERARCHY[b[:slug]]
|
PRODUCT_HIERARCHY.index(b[:slug]) - PRODUCT_HIERARCHY.index(a[:slug])
|
||||||
end.first
|
end.first
|
||||||
|
|
||||||
@product_id = id_and_slug[:id]
|
@product_id = id_and_slug[:id]
|
||||||
|
|
|
@ -78,17 +78,18 @@ describe CustomWizard::Subscription do
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with subscriptions" do
|
context "with subscriptions" do
|
||||||
def get_subscription_result(product_id)
|
def get_subscription_result(product_ids)
|
||||||
result = SubscriptionClient::Subscriptions::Result.new
|
result = SubscriptionClient::Subscriptions::Result.new
|
||||||
result.supplier = SubscriptionClientSupplier.new(product_slugs)
|
result.supplier = SubscriptionClientSupplier.new(product_slugs)
|
||||||
result.resource = SubscriptionClientResource.new
|
result.resource = SubscriptionClientResource.new
|
||||||
result.subscriptions = [SubscriptionClientSubscription.new(product_id)]
|
result.subscriptions = product_ids.map { |product_id| SubscriptionClientSubscription.new(product_id) }
|
||||||
result.products = product_slugs
|
result.products = product_slugs
|
||||||
result
|
result
|
||||||
end
|
end
|
||||||
let!(:business_subscription_result) { get_subscription_result(business_product_id) }
|
let!(:business_subscription_result) { get_subscription_result([business_product_id]) }
|
||||||
let!(:standard_subscription_result) { get_subscription_result(standard_product_id) }
|
let!(:standard_subscription_result) { get_subscription_result([standard_product_id]) }
|
||||||
let!(:community_subscription_result) { get_subscription_result(community_product_id) }
|
let!(:community_subscription_result) { get_subscription_result([community_product_id]) }
|
||||||
|
let!(:multiple_subscription_result) { get_subscription_result([community_product_id, business_product_id]) }
|
||||||
|
|
||||||
it "handles mapped values" do
|
it "handles mapped values" do
|
||||||
SubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result)
|
SubscriptionClient.stubs(:find_subscriptions).returns(standard_subscription_result)
|
||||||
|
@ -143,6 +144,16 @@ describe CustomWizard::Subscription do
|
||||||
expect(described_class.includes?(:action, :type, 'create_category')).to eq(true)
|
expect(described_class.includes?(:action, :type, 'create_category')).to eq(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "with multiple subscriptions" do
|
||||||
|
before do
|
||||||
|
SubscriptionClient.stubs(:find_subscriptions).returns(multiple_subscription_result)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "detects correct type in hierarchy" do
|
||||||
|
expect(described_class.type).to eq(:business)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Laden …
In neuem Issue referenzieren