-
Notifications
You must be signed in to change notification settings - Fork 356
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for subscription schedules
- Loading branch information
1 parent
59b6ccf
commit 212c157
Showing
1 changed file
with
126 additions
and
0 deletions.
There are no files selected for viewing
126 changes: 126 additions & 0 deletions
126
test/stripe/subscriptions/subscription_schedule_test.exs
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,126 @@ | ||
defmodule Stripe.SubscriptionScheduleTest do | ||
use Stripe.StripeCase, async: true | ||
|
||
@invalid_params %{ | ||
customer: "cus_123", | ||
renewal_behavior: "release", | ||
phases: [ | ||
%{ | ||
coupon: nil, | ||
default_tax_rates: [], | ||
end_date: 1_557_566_037, | ||
start_date: 1_554_974_037, | ||
tax_percent: 0 | ||
} | ||
] | ||
} | ||
describe "retrieve/2" do | ||
test "retrieves a subscription" do | ||
assert {:ok, %Stripe.SubscriptionSchedule{}} = | ||
Stripe.SubscriptionSchedule.retrieve("sub_sched_123") | ||
|
||
assert_stripe_requested(:get, "/v1/subscription_schedules/sub_sched_123") | ||
end | ||
end | ||
|
||
describe "create/2" do | ||
test "creates a subscription schedule" do | ||
params = %{ | ||
customer: "cus_123", | ||
renewal_behavior: "release", | ||
phases: [ | ||
%{ | ||
coupon: nil, | ||
default_tax_rates: [], | ||
end_date: 1_557_566_037, | ||
plans: [ | ||
%{ | ||
billing_thresholds: nil, | ||
plan: "some plan", | ||
quantity: 2, | ||
tax_rates: [] | ||
} | ||
], | ||
start_date: 1_554_974_037, | ||
tax_percent: 0 | ||
} | ||
] | ||
} | ||
|
||
assert {:ok, %Stripe.SubscriptionSchedule{}} = Stripe.SubscriptionSchedule.create(params) | ||
|
||
assert_stripe_requested(:post, "/v1/subscription_schedules") | ||
end | ||
|
||
test "fails with missing plans in phases" do | ||
assert {:error, %Stripe.Error{} = error} = | ||
Stripe.SubscriptionSchedule.create(@invalid_params) | ||
|
||
assert_stripe_requested(:post, "/v1/subscription_schedules") | ||
end | ||
end | ||
|
||
describe "update/2" do | ||
test "updates a subscription" do | ||
params = %{ | ||
renewal_behavior: "release", | ||
phases: [ | ||
%{ | ||
coupon: nil, | ||
default_tax_rates: [], | ||
end_date: 1_557_566_037, | ||
plans: [ | ||
%{ | ||
billing_thresholds: nil, | ||
plan: "some plan", | ||
quantity: 2, | ||
tax_rates: [] | ||
} | ||
], | ||
start_date: 1_554_974_037, | ||
tax_percent: 0 | ||
} | ||
] | ||
} | ||
|
||
assert {:ok, subscription} = Stripe.SubscriptionSchedule.update("sub_sched_123", params) | ||
assert_stripe_requested(:post, "/v1/subscription_schedules/#{subscription.id}") | ||
end | ||
|
||
test "fails with missing plans in phases" do | ||
assert {:error, %Stripe.Error{}} = | ||
Stripe.SubscriptionSchedule.update("sub_sched_123", @invalid_params) | ||
|
||
assert_stripe_requested(:post, "/v1/subscription_schedules/sub_sched_123") | ||
end | ||
end | ||
|
||
describe "list/2" do | ||
test "lists all subscriptions" do | ||
assert {:ok, %Stripe.List{data: subscriptions}} = Stripe.SubscriptionSchedule.list() | ||
assert_stripe_requested(:get, "/v1/subscription_schedules") | ||
assert is_list(subscriptions) | ||
assert %Stripe.SubscriptionSchedule{} = hd(subscriptions) | ||
end | ||
end | ||
|
||
describe "cancel/2" do | ||
test "cancels a subscription schedule" do | ||
{:ok, subscription} = Stripe.SubscriptionSchedule.retrieve("sub_sched_123") | ||
assert_stripe_requested(:get, "/v1/subscription_schedules/#{subscription.id}") | ||
|
||
assert {:ok, _} = Stripe.SubscriptionSchedule.cancel("sub_sched_123") | ||
assert_stripe_requested(:post, "/v1/subscription_schedules/#{subscription.id}/cancel") | ||
end | ||
end | ||
|
||
describe "release/2" do | ||
test "releases a subscription schedule" do | ||
{:ok, subscription} = Stripe.SubscriptionSchedule.retrieve("sub_sched_123") | ||
assert_stripe_requested(:get, "/v1/subscription_schedules/#{subscription.id}") | ||
|
||
assert {:ok, _} = Stripe.SubscriptionSchedule.release("sub_sched_123") | ||
assert_stripe_requested(:post, "/v1/subscription_schedules/#{subscription.id}/release") | ||
end | ||
end | ||
end |