Skip to content

Commit

Permalink
Save point for adding faked API and more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsmith committed Nov 22, 2016
1 parent 0e394e2 commit 25c4a97
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/code_corps/stripe/stripe_connect_account.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule CodeCorps.Stripe.StripeConnectAccount do

@api Application.get_env(:code_corps, :stripe)

def create(%{"account" => authorization_code, "organization_id" => _organization_id} = attributes) do
def create(%{"access_code" => authorization_code, "organization_id" => _organization_id} = attributes) do
authorization_code
|> @api.Connect.OAuth.token
|> get_account_id
Expand Down
28 changes: 28 additions & 0 deletions lib/code_corps/stripity_stripe_testing/account.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
defmodule CodeCorps.StripityStripeTesting.Account do
def retrieve(_id) do
{:ok, do_retrieve}
end

defp do_retrieve do
%Stripe.Account{
business_name: "Code Corps PBC",
business_primary_color: nil,
business_url: "codecorps.org",
charges_enabled: true,
country: "US",
default_currency: "usd",
details_submitted: true,
display_name: "Code Corps Customer",
email: "volunteers@codecorps.org",
id: "acct_123",
managed: false,
metadata: %{},
statement_descriptor: "CODECORPS.ORG",
support_email: nil,
support_phone: "1234567890",
support_url: nil,
timezone: "America/Los_Angeles",
transfers_enabled: true
}
end
end
13 changes: 13 additions & 0 deletions lib/code_corps/stripity_stripe_testing/connect/token.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
defmodule CodeCorps.StripityStripeTesting.Connect.OAuth do
def token(_code) do
%Stripe.Connect.OAuth.TokenResponse{
access_token: "ACCESS_TOKEN",
livemode: false,
refresh_token: "REFRESH_TOKEN",
scope: "read_write",
stripe_publishable_key: "PUBLISHABLE_KEY",
stripe_user_id: "USER_ID",
token_type: "bearer"
}
end
end
16 changes: 16 additions & 0 deletions test/controllers/stripe_connect_account_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,20 @@ defmodule CodeCorps.StripeConnectAccountControllerTest do
assert conn |> request_show(stripe_connect_account) |> json_response(403)
end
end

describe "create" do
@tag :authenticated
test "creates and renders resource user is authenticated and authorized", %{conn: conn, current_user: current_user} do
assert conn |> request_create(%{access_code: "123"}) |> json_response(201)
end

test "does not create resource and renders 401 when unauthenticated", %{conn: conn} do
assert conn |> request_create |> json_response(401)
end

@tag :authenticated
test "does not create resource and renders 403 when not authorized", %{conn: conn} do
assert conn |> request_create |> json_response(403)
end
end
end

0 comments on commit 25c4a97

Please sign in to comment.