-
Notifications
You must be signed in to change notification settings - Fork 460
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests and fixes for pricing edge cases (#703)
* Better logging when creating prices * Always pull tiers when pulling prices * Fix helper to debug missing order * Minor doc * Testing edge case where billing_scheme is defined without any tiers * Fix up user limit console helper * Shorter log entries * Doc on pricing tests * Shortening log fields * Stripe deep copy * Allow ids to be passed to order condition check * Safe tier comparison * Use deep_copy everywhere * Price reuse tests * Missing envs * Bug fix from deep_dup not working properly * Log improvement * running tests locally documentation
- Loading branch information
1 parent
29f0ddb
commit a15c7f2
Showing
15 changed files
with
215 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,8 +122,9 @@ def get_all(object_name) | |
sf.query("SELECT #{all_fields} FROM #{object_name}") | ||
end | ||
|
||
def limits | ||
sf.limits.slice(*%w{DailyApiRequests DailyAsyncApexExecutions DailyBulkApiBatches DailyFunctionsApiCallLimit DailyStreamingApiEvents}) | ||
# or `sfdx force:limits:api:display -u [email protected]` | ||
def user_limits(user) | ||
user.sf_client.limits.slice(*%w{DailyApiRequests DailyAsyncApexExecutions DailyBulkApiBatches DailyFunctionsApiCallLimit DailyStreamingApiEvents}) | ||
end | ||
|
||
# new scratch orgs come without pricebooks active, this causes issues with amendments | ||
|
@@ -149,12 +150,18 @@ def touch_order(sf_order) | |
}) | ||
end | ||
|
||
def ensure_order_is_included_in_custom_where_clause(sf_order) | ||
def ensure_order_is_included_in_custom_where_clause(sf_order_or_id) | ||
sf_order = if sf_order_or_id.is_a?(String) | ||
sf_get(sf_order_or_id) | ||
else | ||
sf_order_or_id | ||
end | ||
|
||
order_poller = StripeForce::OrderPoller.new(@user) | ||
custom_soql = order_poller.send(:user_specified_where_clause_for_object) | ||
results = @sf.query("SELECT Id FROM #{SF_ORDER} WHERE Id = '#{sf_order.Id}' " + custom_soql) | ||
|
||
if results.first.empty? | ||
if results.first.blank? | ||
puts "Order is not included in custom soql" | ||
else | ||
puts "Order is included in custom soql" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# frozen_string_literal: true | ||
# typed: true | ||
|
||
require_relative '../../test_helper' | ||
|
||
class Critic::PriceReuse < Critic::FunctionalTest | ||
before do | ||
@user = make_user(save: true) | ||
end | ||
|
||
it 'gracefully fails when a metered price is specified without billing tiers' do | ||
@user.field_defaults = {"price" => {"billing_scheme" => "tiered"}} | ||
@user.save | ||
|
||
sf_order = create_subscription_order | ||
|
||
# before this test, this would throw a fatal exception without a nice user error | ||
exception = assert_raises(Stripe::InvalidRequestError) do | ||
StripeForce::Translate.perform_inline(@user, sf_order.Id) | ||
end | ||
|
||
assert_match("tiered the parameter tiers must be set", exception.message) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# frozen_string_literal: true | ||
# typed: true | ||
|
||
require_relative '../../test_helper' | ||
|
||
class Critic::PriceReuse < Critic::FunctionalTest | ||
before do | ||
@user = make_user(save: true) | ||
end | ||
|
||
it 'uses the same tiered price when there are no customizations on the order line level' do | ||
sf_product_id, sf_pricebook_entry_id = create_recurring_per_unit_tiered_price | ||
|
||
# first, translate the price twice and ensure the same ID is used, then we'll test the order line | ||
StripeForce::Translate.perform_inline(@user, sf_pricebook_entry_id) | ||
|
||
sf_pricebook_entry = sf.find(SF_PRICEBOOK_ENTRY, sf_pricebook_entry_id) | ||
stripe_price_id = sf_pricebook_entry[prefixed_stripe_field(GENERIC_STRIPE_ID)] | ||
refute_nil(stripe_price_id) | ||
|
||
stripe_price = Stripe::Price.retrieve(stripe_price_id, @user.stripe_credentials) | ||
|
||
Stripe::Price.expects(:create).never | ||
|
||
StripeForce::Translate.perform_inline(@user, sf_pricebook_entry_id) | ||
|
||
sf_pricebook_entry.refresh | ||
assert_equal(stripe_price.id, sf_pricebook_entry[prefixed_stripe_field(GENERIC_STRIPE_ID)]) | ||
|
||
sf_order = create_subscription_order(sf_product_id: sf_product_id) | ||
|
||
StripeForce::Translate.perform_inline(@user, sf_order.Id) | ||
|
||
sf_order.refresh | ||
stripe_id = sf_order[prefixed_stripe_field(GENERIC_STRIPE_ID)] | ||
refute_nil(stripe_id) | ||
|
||
subscription_schedule = Stripe::SubscriptionSchedule.retrieve(stripe_id, @user.stripe_credentials) | ||
|
||
assert_equal(1, subscription_schedule.phases.count) | ||
assert_equal(1, subscription_schedule.phases.first&.items&.count) | ||
|
||
item = subscription_schedule.phases.first&.items&.first | ||
assert_equal(stripe_price_id, item&.price) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.