-
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.
- Loading branch information
1 parent
c6cc27a
commit e0de53b
Showing
5 changed files
with
89 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
defmodule CodeCorps.StripeAccountPolicyTest do | ||
use CodeCorps.PolicyCase | ||
|
||
import CodeCorps.StripeAccount | ||
import CodeCorps.StripeAccountPolicy, only: [show?: 2] | ||
|
||
alias CodeCorps.StripeAccount | ||
|
||
describe "show?" do | ||
test "returns true when user is an admin" do | ||
user = build(:user, admin: true) | ||
stripe_account = insert(:stripe_account) | ||
|
||
assert show?(user, stripe_account) | ||
end | ||
|
||
test "returns true when user is owner of organization" do | ||
user = insert(:user) | ||
organization = insert(:organization) | ||
insert(:organization_membership, role: "owner", member: user, organization: organization) | ||
|
||
stripe_account = insert(:stripe_account, organization: organization) | ||
|
||
assert show?(user, stripe_account) | ||
end | ||
|
||
test "returns false when user is admin of organization" do | ||
user = insert(:user) | ||
organization = insert(:organization) | ||
insert(:organization_membership, role: "admin", member: user) | ||
|
||
stripe_account = insert(:stripe_account, organization: organization) | ||
|
||
refute show?(user, stripe_account) | ||
end | ||
|
||
test "returns false when user is not member of organization" do | ||
user = insert(:user) | ||
stripe_account = insert(:stripe_account) | ||
|
||
refute show?(user, stripe_account) | ||
end | ||
|
||
test "returns false when user is pending member of organization" do | ||
user = insert(:user) | ||
organization = insert(:organization) | ||
insert(:organization_membership, role: "pending", member: user) | ||
|
||
stripe_account = insert(:stripe_account, organization: organization) | ||
|
||
refute show?(user, stripe_account) | ||
end | ||
|
||
test "returns false when user is contributor of organization" do | ||
user = insert(:user) | ||
organization = insert(:organization) | ||
insert(:organization_membership, role: "contributor", member: user) | ||
|
||
stripe_account = insert(:stripe_account, organization: organization) | ||
|
||
refute show?(user, stripe_account) | ||
end | ||
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
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,13 @@ | ||
defmodule CodeCorps.StripeAccountPolicy do | ||
import CodeCorps.Helpers.Policy, | ||
only: [get_membership: 2, get_role: 1, owner?: 1] | ||
|
||
alias CodeCorps.StripeAccount | ||
alias CodeCorps.User | ||
alias CodeCorps.OrganizationMembership | ||
alias Ecto.Changeset | ||
|
||
def show?(%User{admin: true}, %StripeAccount{}), do: true | ||
def show?(%User{} = user, %StripeAccount{} = stripe_account), do: stripe_account |> get_membership(user) |> get_role |> owner? | ||
def show?(%User{}, %StripeAccount{}), do: false | ||
end |