Skip to content

Commit

Permalink
feat: #89 Remove frequency from charge
Browse files Browse the repository at this point in the history
  • Loading branch information
vincent-pochet committed Apr 21, 2022
1 parent a5fe95a commit 4df09f1
Show file tree
Hide file tree
Showing 17 changed files with 13 additions and 113 deletions.
13 changes: 0 additions & 13 deletions app/graphql/types/charges/frequency_enum.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/graphql/types/charges/input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Input < Types::BaseInputObject
argument :billable_metric_id, ID, required: true
argument :amount_cents, Integer, required: true
argument :amount_currency, Types::CurrencyEnum, required: true
argument :frequency, Types::Charges::FrequencyEnum, required: true
argument :charge_model, Types::Charges::ChargeModelEnum, required: true
argument :pro_rata, Boolean, required: true
argument :vat_rate, Float, required: false
Expand Down
1 change: 0 additions & 1 deletion app/graphql/types/charges/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class Object < Types::BaseObject
field :billable_metric, Types::BillableMetrics::Object, null: false
field :amount_cents, Integer, null: false
field :amount_currency, Types::CurrencyEnum, null: false
field :frequency, Types::Charges::FrequencyEnum, null: false
field :charge_model, Types::Charges::ChargeModelEnum, null: false
field :pro_rata, Boolean, null: false
field :vat_rate, Float
Expand Down
6 changes: 0 additions & 6 deletions app/models/charge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,10 @@ class Charge < ApplicationRecord

has_many :fees

FREQUENCIES = %i[
one_time
recurring
].freeze

CHARGE_MODELS = %i[
standard
].freeze

enum frequency: FREQUENCIES
enum charge_model: CHARGE_MODELS

monetize :amount_cents
Expand Down
3 changes: 1 addition & 2 deletions app/services/plans_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,14 @@ def create_charge(plan, args)
billable_metric_id: args[:billable_metric_id],
amount_cents: args[:amount_cents],
amount_currency: args[:amount_currency],
frequency: args[:frequency].to_sym,
pro_rata: args[:pro_rata],
vat_rate: args[:vat_rate],
charge_model: args[:charge_model].to_sym,
)
end

def sanitize_charges(plan, args_charges, created_charges_ids)
args_charges_ids = args_charges.select { |c| c[:id] != nil }.map { |c| c[:id] }
args_charges_ids = args_charges.reject { |c| c[:id].nil? }.map { |c| c[:id] }
charges_ids = plan.charges.pluck(:id) - args_charges_ids - created_charges_ids
charges_ids.each do |charge_id|
Charge.find_by(id: charge_id).destroy!
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20220421150849_remove_charges_frequency.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class RemoveChargesFrequency < ActiveRecord::Migration[7.0]
def change
remove_column :charges, :frequency
end
end
3 changes: 1 addition & 2 deletions db/schema.rb

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

7 changes: 0 additions & 7 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,17 @@ type Charge {
billableMetric: BillableMetric!
chargeModel: ChargeModelEnum!
createdAt: ISO8601DateTime!
frequency: ChargeFrequency!
id: ID!
proRata: Boolean!
updatedAt: ISO8601DateTime!
vatRate: Float
}

enum ChargeFrequency {
one_time
recurring
}

input ChargeInput {
amountCents: Int!
amountCurrency: CurrencyEnum!
billableMetricId: ID!
chargeModel: ChargeModelEnum!
frequency: ChargeFrequency!
id: ID
proRata: Boolean!
vatRate: Float
Expand Down
57 changes: 0 additions & 57 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -572,24 +572,6 @@

]
},
{
"name": "frequency",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "ChargeFrequency",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null,
"args": [

]
},
{
"name": "id",
"description": null,
Expand Down Expand Up @@ -662,29 +644,6 @@
"inputFields": null,
"enumValues": null
},
{
"kind": "ENUM",
"name": "ChargeFrequency",
"description": null,
"interfaces": null,
"possibleTypes": null,
"fields": null,
"inputFields": null,
"enumValues": [
{
"name": "one_time",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "recurring",
"description": null,
"isDeprecated": false,
"deprecationReason": null
}
]
},
{
"kind": "INPUT_OBJECT",
"name": "ChargeInput",
Expand Down Expand Up @@ -753,22 +712,6 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "frequency",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "ChargeFrequency",
"ofType": null
}
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "chargeModel",
"description": null,
Expand Down
8 changes: 0 additions & 8 deletions spec/factories/charge_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,5 @@

pro_rata { false }
charge_model { 'standard' }

factory :one_time_charge do
frequency { :one_time }
end

factory :recurring_charge do
frequency { :recurring }
end
end
end
2 changes: 0 additions & 2 deletions spec/graphql/mutations/plans/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,13 @@
billableMetricId: billable_metrics.first.id,
amountCents: 100,
amountCurrency: 'USD',
frequency: 'recurring',
proRata: false,
chargeModel: 'standard',
},
{
billableMetricId: billable_metrics.last.id,
amountCents: 300,
amountCurrency: 'EUR',
frequency: 'one_time',
proRata: true,
vatRate: 10.5,
chargeModel: 'standard',
Expand Down
2 changes: 0 additions & 2 deletions spec/graphql/mutations/plans/update_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,13 @@
billableMetricId: billable_metrics.first.id,
amountCents: 100,
amountCurrency: 'USD',
frequency: 'recurring',
proRata: false,
chargeModel: 'standard',
},
{
billableMetricId: billable_metrics.last.id,
amountCents: 300,
amountCurrency: 'EUR',
frequency: 'one_time',
proRata: true,
vatRate: 10.5,
chargeModel: 'standard',
Expand Down
2 changes: 1 addition & 1 deletion spec/services/billable_metrics_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
let(:subscription) { create(:subscription) }

before do
create(:one_time_charge, plan: subscription.plan, billable_metric: billable_metric)
create(:charge, plan: subscription.plan, billable_metric: billable_metric)
end

it 'returns an error' do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

let(:charge) do
create(
:one_time_charge,
:charge,
amount_cents: 500,
charge_model: 'standard',
)
Expand Down
2 changes: 1 addition & 1 deletion spec/services/fees/charge_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
let(:billable_metric) { create(:billable_metric, aggregation_type: 'count_agg') }
let(:charge) do
create(
:one_time_charge,
:charge,
plan: subscription.plan,
charge_model: 'standard',
billable_metric: billable_metric,
Expand Down
2 changes: 1 addition & 1 deletion spec/services/invoices/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
let(:billable_metric) { create(:billable_metric, aggregation_type: 'count_agg') }

before do
create(:one_time_charge, plan: subscription.plan, charge_model: 'standard')
create(:charge, plan: subscription.plan, charge_model: 'standard')
end

context 'when billed monthly' do
Expand Down
8 changes: 0 additions & 8 deletions spec/services/plans_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@
billable_metric_id: billable_metrics.first.id,
amount_cents: 100,
amount_currency: 'USD',
frequency: 'recurring',
pro_rata: false,
charge_model: 'standard',
},
{
billable_metric_id: billable_metrics.last.id,
amount_cents: 300,
amount_currency: 'EUR',
frequency: 'one_time',
pro_rata: true,
vat_rate: 10.5,
charge_model: 'standard',
Expand Down Expand Up @@ -96,15 +94,13 @@
billable_metric_id: billable_metrics.first.id,
amount_cents: 100,
amount_currency: 'USD',
frequency: 'recurring',
pro_rata: false,
charge_model: 'standard',
},
{
billable_metric_id: billable_metrics.last.id,
amount_cents: 300,
amount_currency: 'EUR',
frequency: 'one_time',
pro_rata: true,
vat_rate: 10.5,
charge_model: 'standard',
Expand Down Expand Up @@ -153,7 +149,6 @@
billable_metric_id: billable_metrics.first.id,
amount_cents: 300,
amount_currency: 'USD',
frequency: 'recurring',
pro_rata: false,
charge_model: 'standard',
)
Expand All @@ -174,15 +169,13 @@
billable_metric_id: billable_metrics.first.id,
amount_cents: 100,
amount_currency: 'USD',
frequency: 'recurring',
pro_rata: false,
charge_model: 'standard',
},
{
billable_metric_id: billable_metrics.last.id,
amount_cents: 300,
amount_currency: 'EUR',
frequency: 'one_time',
pro_rata: true,
vat_rate: 10.5,
charge_model: 'standard',
Expand All @@ -205,7 +198,6 @@
billable_metric_id: billable_metrics.first.id,
amount_cents: 300,
amount_currency: 'USD',
frequency: 'recurring',
pro_rata: false,
charge_model: 'standard',
)
Expand Down

0 comments on commit 4df09f1

Please sign in to comment.