Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: T 979 api rename plan billing period into frequency #57

Merged
merged 2 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/graphql/mutations/plans/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Create < BaseMutation
argument :name, String, required: true
argument :code, String, required: true
argument :interval, Types::Plans::IntervalEnum, required: true
argument :billing_period, Types::Plans::BillingPeriodEnum, required: true
argument :frequency, Types::Plans::FrequencyEnum, required: true
argument :pro_rata, Boolean, required: true
argument :pay_in_advance, Boolean, required: true
argument :amount_cents, Integer, required: true
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/mutations/plans/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Update < BaseMutation
argument :name, String, required: true
argument :code, String, required: true
argument :interval, Types::Plans::IntervalEnum, required: true
argument :billing_period, Types::Plans::BillingPeriodEnum, required: true
argument :frequency, Types::Plans::FrequencyEnum, required: true
argument :pro_rata, Boolean, required: true
argument :pay_in_advance, Boolean, required: true
argument :amount_cents, Integer, required: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

module Types
module Plans
class BillingPeriodEnum < Types::BaseEnum
Plan::BILLING_PERIODS.each do |type|
class FrequencyEnum < Types::BaseEnum
Plan::FREQUENCIES.each do |type|
value type
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/graphql/types/plans/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Object < Types::BaseObject
field :name, String, null: false
field :code, String, null: false
field :interval, Types::Plans::IntervalEnum, null: false
field :billing_period, Types::Plans::BillingPeriodEnum, null: false
field :frequency, Types::Plans::FrequencyEnum, null: false
field :pro_rata, Boolean, null: false
field :pay_in_advance, Boolean, null: false
field :amount_cents, Integer, null: false
Expand Down
4 changes: 2 additions & 2 deletions app/models/plan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ class Plan < ApplicationRecord
yearly
].freeze

BILLING_PERIODS = %i[
FREQUENCIES = %i[
beginning_of_period
subscription_date
].freeze

enum interval: INTERVALS
enum billing_period: BILLING_PERIODS
enum frequency: FREQUENCIES

monetize :amount_cents

Expand Down
4 changes: 2 additions & 2 deletions app/services/plans_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def create(**args)
code: args[:code],
description: args[:description],
interval: args[:interval].to_sym,
billing_period: args[:billing_period].to_sym,
frequency: args[:frequency].to_sym,
pro_rata: args[:pro_rata],
pay_in_advance: args[:pay_in_advance],
amount_cents: args[:amount_cents],
Expand Down Expand Up @@ -43,7 +43,7 @@ def update(**args)
plan.code = args[:code]
plan.description = args[:description]
plan.interval = args[:interval].to_sym
plan.billing_period = args[:billing_period].to_sym
plan.frequency = args[:frequency].to_sym
plan.pro_rata = args[:pro_rata]
plan.pay_in_advance = args[:pay_in_advance]
plan.amount_cents = args[:amount_cents]
Expand Down
5 changes: 5 additions & 0 deletions db/migrate/20220406133642_rename_billing_period_on_plans.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class RenameBillingPeriodOnPlans < ActiveRecord::Migration[7.0]
def change
rename_column :plans, :billing_period, :frequency
end
end
4 changes: 2 additions & 2 deletions db/schema.rb

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

16 changes: 8 additions & 8 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,6 @@ type BillableMetricCollection {
metadata: CollectionMetadata!
}

enum BillingPeriodEnum {
beginning_of_period
subscription_date
}

type Charge {
amountCents: Int!
amountCurrency: CurrencyEnum!
Expand Down Expand Up @@ -98,7 +93,6 @@ Autogenerated input type of CreatePlan
input CreatePlanInput {
amountCents: Int!
amountCurrency: CurrencyEnum!
billingPeriod: BillingPeriodEnum!
charges: [ChargeInput!]!

"""
Expand All @@ -107,6 +101,7 @@ input CreatePlanInput {
clientMutationId: String
code: String!
description: String
frequency: FrequencyEnum!
interval: PlanInterval!
name: String!
payInAdvance: Boolean!
Expand Down Expand Up @@ -185,6 +180,11 @@ type DestroyPlanPayload {
id: ID
}

enum FrequencyEnum {
beginning_of_period
subscription_date
}

"""
An ISO 8601-encoded datetime
"""
Expand Down Expand Up @@ -319,7 +319,6 @@ type Organization {
type Plan {
amountCents: Int!
amountCurrency: CurrencyEnum!
billingPeriod: BillingPeriodEnum!

"""
Number of charges attached to a plan
Expand All @@ -334,6 +333,7 @@ type Plan {
"""
customerCount: Int!
description: String
frequency: FrequencyEnum!
id: ID!
interval: PlanInterval!
name: String!
Expand Down Expand Up @@ -452,7 +452,6 @@ Autogenerated input type of UpdatePlan
input UpdatePlanInput {
amountCents: Int!
amountCurrency: CurrencyEnum!
billingPeriod: BillingPeriodEnum!
charges: [ChargeInput!]!

"""
Expand All @@ -461,6 +460,7 @@ input UpdatePlanInput {
clientMutationId: String
code: String!
description: String
frequency: FrequencyEnum!
id: String!
interval: PlanInterval!
name: String!
Expand Down
90 changes: 45 additions & 45 deletions schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,29 +250,6 @@
"inputFields": null,
"enumValues": null
},
{
"kind": "ENUM",
"name": "BillingPeriodEnum",
"description": null,
"interfaces": null,
"possibleTypes": null,
"fields": null,
"inputFields": null,
"enumValues": [
{
"name": "beginning_of_period",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "subscription_date",
"description": null,
"isDeprecated": false,
"deprecationReason": null
}
]
},
{
"kind": "SCALAR",
"name": "Boolean",
Expand Down Expand Up @@ -927,14 +904,14 @@
"deprecationReason": null
},
{
"name": "billingPeriod",
"name": "frequency",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "BillingPeriodEnum",
"name": "FrequencyEnum",
"ofType": null
}
},
Expand Down Expand Up @@ -1440,6 +1417,29 @@
"inputFields": null,
"enumValues": null
},
{
"kind": "ENUM",
"name": "FrequencyEnum",
"description": null,
"interfaces": null,
"possibleTypes": null,
"fields": null,
"inputFields": null,
"enumValues": [
{
"name": "beginning_of_period",
"description": null,
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "subscription_date",
"description": null,
"isDeprecated": false,
"deprecationReason": null
}
]
},
{
"kind": "SCALAR",
"name": "ID",
Expand Down Expand Up @@ -2113,24 +2113,6 @@

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

]
},
{
"name": "chargeCount",
"description": "Number of charges attached to a plan",
Expand Down Expand Up @@ -2239,6 +2221,24 @@

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

]
},
{
"name": "id",
"description": null,
Expand Down Expand Up @@ -3223,14 +3223,14 @@
"deprecationReason": null
},
{
"name": "billingPeriod",
"name": "frequency",
"description": null,
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "ENUM",
"name": "BillingPeriodEnum",
"name": "FrequencyEnum",
"ofType": null
}
},
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/plan_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
name { Faker::TvShows::SiliconValley.app }
code { Faker::Name.name.underscore }
interval { 'monthly' }
billing_period { 'beginning_of_period' }
frequency { 'beginning_of_period' }
pro_rata { false }
pay_in_advance { false }
amount_cents { 100 }
Expand Down
10 changes: 5 additions & 5 deletions spec/graphql/mutations/plans/create_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
name,
code,
interval,
billingPeriod,
frequency,
proRata,
payInAdvance,
amountCents,
Expand All @@ -38,7 +38,7 @@
name: 'New Plan',
code: 'new_plan',
interval: 'monthly',
billingPeriod: 'beginning_of_period',
frequency: 'beginning_of_period',
proRata: false,
payInAdvance: false,
amountCents: 200,
Expand Down Expand Up @@ -73,7 +73,7 @@
expect(result_data['name']).to eq('New Plan')
expect(result_data['code']).to eq('new_plan')
expect(result_data['interval']).to eq('monthly')
expect(result_data['billingPeriod']).to eq('beginning_of_period')
expect(result_data['frequency']).to eq('beginning_of_period')
expect(result_data['proRata']).to eq(false)
expect(result_data['payInAdvance']).to eq(false)
expect(result_data['amountCents']).to eq(200)
Expand All @@ -92,7 +92,7 @@
name: 'New Plan',
code: 'new_plan',
interval: 'monthly',
billingPeriod: 'beginning_of_period',
frequency: 'beginning_of_period',
proRata: false,
payInAdvance: false,
amountCents: 200,
Expand All @@ -116,7 +116,7 @@
name: 'New Plan',
code: 'new_plan',
interval: 'monthly',
billingPeriod: 'beginning_of_period',
frequency: 'beginning_of_period',
proRata: false,
payInAdvance: false,
amountCents: 200,
Expand Down
Loading