Skip to content

Commit

Permalink
feat(dunning): Add permission to DunningCampaignsResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Oct 17, 2024
1 parent ba3de6a commit 80b1ec9
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 4 deletions.
1 change: 1 addition & 0 deletions app/config/permissions/definition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ customers:
update:
delete:
dunning_campaigns:
view:
create:
subscriptions:
view: true
Expand Down
1 change: 1 addition & 0 deletions app/config/permissions/role-finance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ customers:
update: false
delete: false
dunning_campaigns:
view: true
create: true
subscriptions:
create: false
Expand Down
1 change: 1 addition & 0 deletions app/config/permissions/role-manager.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ customers:
update: true
delete: true
dunning_campaigns:
view: false
create: false
subscriptions:
create: true
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/resolvers/dunning_campaigns_resolver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class DunningCampaignsResolver < Resolvers::BaseResolver

description "Query dunning campaigns of an organization"

REQUIRED_PERMISSION = "dunning_campaigns:view"

argument :applied_to_organization, Boolean, required: false
argument :limit, Integer, required: false
argument :order, String, required: false
Expand Down
1 change: 1 addition & 0 deletions schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion spec/graphql/resolvers/dunning_campaigns_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "rails_helper"

RSpec.describe Resolvers::DunningCampaignsResolver, type: :graphql do
let(:required_permission) { "dunning_campaigns:view" }
let(:query) do
<<~GQL
query {
Expand All @@ -20,10 +21,15 @@

before { dunning_campaign }

it "returns a list of dunning campaigns" do
it_behaves_like "requires current user"
it_behaves_like "requires current organization"
it_behaves_like "requires permission", "dunning_campaigns:view"

it "returns a list of dunning campaigns", :aggregate_failures do
result = execute_graphql(
current_user: membership.user,
current_organization: organization,
permissions: required_permission,
query:
)

Expand Down Expand Up @@ -55,6 +61,7 @@
result = execute_graphql(
current_user: membership.user,
current_organization: create(:organization),
permissions: required_permission,
query:
)

Expand Down
6 changes: 3 additions & 3 deletions spec/queries/dunning_campaigns_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
create(:dunning_campaign, organization:, name: "defgh", code: "11", applied_to_organization: true)
end
let(:dunning_campaign_second) do
create(:dunning_campaign, organization:, name: "abcde", code: "22", applied_to_organization: true)
create(:dunning_campaign, organization:, name: "abcde", code: "22", applied_to_organization: false)
end

let(:dunning_campaign_third) do
Expand Down Expand Up @@ -45,7 +45,7 @@
context "with pagination" do
let(:pagination) { {page: 2, limit: 2} }

it "applies the pagination" do
it "applies the pagination", :aggregate_failures do
aggregate_failures do
expect(result).to be_success
expect(result.dunning_campaigns.count).to eq(1)
Expand All @@ -70,7 +70,7 @@
let(:filters) { {applied_to_organization: false} }

it "returns only one dunning campaign" do
expect(result.dunning_campaigns).to eq([dunning_campaign_third])
expect(result.dunning_campaigns).to eq([dunning_campaign_second, dunning_campaign_third])
end
end

Expand Down

0 comments on commit 80b1ec9

Please sign in to comment.