-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test for StripeConnectSubscriptionService.find_or_create
- Loading branch information
Showing
9 changed files
with
39 additions
and
5 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
37 changes: 37 additions & 0 deletions
37
test/lib/code_corps/stripe_service/stripe_connect_subscription_service_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,37 @@ | ||
defmodule CodeCorps.StripeService.StripeConnectSubscriptionServiceTest do | ||
use CodeCorps.ModelCase | ||
|
||
alias CodeCorps.StripeService.StripeConnectSubscriptionService | ||
|
||
setup do | ||
organization = insert(:organization) | ||
insert(:stripe_connect_account, organization: organization) | ||
|
||
stripe_connect_plan = insert(:stripe_connect_plan) | ||
project = insert(:project, stripe_connect_plan: stripe_connect_plan, organization: organization) | ||
|
||
user = insert(:user) | ||
insert(:stripe_platform_customer, user: user) | ||
insert(:stripe_platform_card, user: user) | ||
|
||
{:ok, project: project, user: user} | ||
end | ||
|
||
describe "find_or_create/1" do | ||
test "retrieves and returns a subscription if one is already present", %{project: project, user: user} do | ||
insert(:stripe_connect_subscription, user: user, stripe_connect_plan: project.stripe_connect_plan, quantity: 300) | ||
|
||
{:ok, subscription} = | ||
StripeConnectSubscriptionService.find_or_create(%{"project_id" => project.id, "user_id" => user.id, "quantity" => 200}) | ||
|
||
assert subscription.quantity == 300 | ||
end | ||
|
||
test "creates and returns a subscription if none is present", %{project: project, user: user} do | ||
{:ok, subscription} = | ||
StripeConnectSubscriptionService.find_or_create(%{"project_id" => project.id, "user_id" => user.id, "quantity" => 200}) | ||
|
||
assert subscription.quantity == 200 | ||
end | ||
end | ||
end |