-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dunning): Create dunning thresholds when creating the campaign
- Loading branch information
Showing
7 changed files
with
96 additions
and
12 deletions.
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
app/graphql/types/dunning_campaign_thresholds/create_input.rb
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,12 @@ | ||
# frozen_string_literal: true | ||
|
||
module Types | ||
module DunningCampaignThresholds | ||
class CreateInput < Types::BaseInputObject | ||
graphql_name "CreateDunningCampaignThresholdInput" | ||
|
||
argument :amount_cents, GraphQL::Types::BigInt, required: true | ||
argument :currency, Types::CurrencyEnum, required: true | ||
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
10 changes: 10 additions & 0 deletions
10
spec/graphql/types/dunning_campaign_thresholds/create_input_spec.rb
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,10 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe Types::DunningCampaignThresholds::CreateInput do | ||
subject { described_class } | ||
|
||
it { is_expected.to accept_argument(:amount_cents).of_type("BigInt!") } | ||
it { is_expected.to accept_argument(:currency).of_type("CurrencyEnum!") } | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe DunningCampaigns::CreateService, type: :service do | ||
subject(:create_service) { described_class.new(organization:, params:) } | ||
|
||
let(:membership) { create(:membership) } | ||
let(:organization) { membership.organization } | ||
let(:params) do | ||
{ | ||
name: "Dunning Campaign", | ||
code: "dunning-campaign", | ||
days_between_attempts: 1, | ||
max_attempts: 3, | ||
description: "Dunning Campaign Description", | ||
applied_to_organization: true, | ||
thresholds: | ||
} | ||
end | ||
|
||
let(:thresholds) do | ||
[ | ||
{ amount_cents: 10000, currency: "USD" }, | ||
{ amount_cents: 20000, currency: "EUR" } | ||
] | ||
end | ||
|
||
describe "#call" do | ||
it "creates a dunning campaign" do | ||
expect { create_service.call }.to change(DunningCampaign, :count).by(1) | ||
.and change(DunningCampaignThreshold, :count).by(2) | ||
end | ||
|
||
it "returns dunning campaign in the result" do | ||
result = create_service.call | ||
expect(result.dunning_campaign).to be_a(DunningCampaign) | ||
expect(result.dunning_campaign.thresholds.first).to be_a(DunningCampaignThreshold) | ||
end | ||
|
||
context "with validation error" do | ||
before { create(:dunning_campaign, organization: organization, code: "dunning-campaign") } | ||
|
||
it "returns an error" do | ||
result = create_service.call | ||
|
||
aggregate_failures do | ||
expect(result).not_to be_success | ||
expect(result.error).to be_a(BaseService::ValidationFailure) | ||
expect(result.error.messages[:code]).to eq(["value_already_exist"]) | ||
end | ||
end | ||
end | ||
end | ||
end |