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(cp-improve): Customer portal update customer's customer_type #2666

Merged
merged 4 commits into from
Oct 10, 2024
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
7 changes: 7 additions & 0 deletions app/graphql/types/customer_portal/customers/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Object < Types::BaseObject

field :applicable_timezone, Types::TimezoneEnum, null: false
field :currency, Types::CurrencyEnum, null: true
field :customer_type, Types::Customers::CustomerTypeEnum
field :display_name, String, null: false
field :email, String, null: true
field :firstname, String
Expand All @@ -31,12 +32,18 @@ class Object < Types::BaseObject

field :shipping_address, Types::Customers::Address, null: true

field :premium, Boolean, null: false

def billing_configuration
{
id: "#{object&.id}-c0nf",
document_locale: object&.document_locale
}
end

def premium
License.premium?
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class UpdateInput < BaseInputObject
graphql_name "UpdateCustomerPortalCustomerInput"
description "Customer Portal Customer Update input arguments"

argument :customer_type, Types::Customers::CustomerTypeEnum, required: false
argument :document_locale, String, required: false
argument :email, String, required: false
argument :firstname, String, required: false
Expand Down
2 changes: 2 additions & 0 deletions app/graphql/types/customer_portal/wallets/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class Object < Types::BaseObject
field :ongoing_balance_cents, GraphQL::Types::BigInt, null: false
field :ongoing_usage_balance_cents, GraphQL::Types::BigInt, null: false
field :rate_amount, GraphQL::Types::Float, null: false

field :last_balance_sync_at, GraphQL::Types::ISO8601DateTime, null: true
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/services/customer_portal/customer_update_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def call
return result.not_found_failure!(resource: "customer") unless customer

ActiveRecord::Base.transaction do
customer.customer_type = args[:customer_type] if args.key?(:customer_type)
customer.name = args[:name] if args.key?(:name)
customer.firstname = args[:firstname] if args.key?(:firstname)
customer.lastname = args[:lastname] if args.key?(:lastname)
Expand Down
4 changes: 4 additions & 0 deletions schema.graphql

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

58 changes: 58 additions & 0 deletions schema.json

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

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<<~GQL
mutation($input: UpdateCustomerPortalCustomerInput!) {
updateCustomerPortalCustomer(input: $input) {
customerType
name
firstname
lastname
Expand Down Expand Up @@ -49,6 +50,7 @@

let(:input) do
{
customerType: "company",
name: "Updated customer name",
firstname: "Updated customer firstname",
lastname: "Updated customer lastname",
Expand Down Expand Up @@ -78,6 +80,7 @@
it "updates a customer", :aggregate_failures do
result_data = result["data"]["updateCustomerPortalCustomer"]

expect(result_data["customerType"]).to eq(input[:customerType])
expect(result_data["name"]).to eq(input[:name])
expect(result_data["firstname"]).to eq(input[:firstname])
expect(result_data["lastname"]).to eq(input[:lastname])
Expand Down
4 changes: 4 additions & 0 deletions spec/graphql/types/customer_portal/customers/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
it { is_expected.to have_field(:id).of_type("ID!") }

it { is_expected.to have_field(:applicable_timezone).of_type("TimezoneEnum!") }
it { is_expected.to have_field(:currency).of_type("CurrencyEnum") }
it { is_expected.to have_field(:customer_type).of_type("CustomerTypeEnum") }
it { is_expected.to have_field(:display_name).of_type("String!") }
it { is_expected.to have_field(:firstname).of_type("String") }
it { is_expected.to have_field(:lastname).of_type("String") }
Expand All @@ -27,4 +29,6 @@
it { is_expected.to have_field(:shipping_address).of_type("CustomerAddress") }

it { is_expected.to have_field(:billing_configuration).of_type('CustomerBillingConfiguration') }

it { is_expected.to have_field(:premium).of_type("Boolean!") }
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
RSpec.describe Types::CustomerPortal::Customers::UpdateInput do
subject { described_class }

it { is_expected.to accept_argument(:customer_type).of_type("CustomerTypeEnum") }
it { is_expected.to accept_argument(:document_locale).of_type("String") }
it { is_expected.to accept_argument(:email).of_type("String") }
it { is_expected.to accept_argument(:firstname).of_type("String") }
Expand Down
1 change: 1 addition & 0 deletions spec/graphql/types/customer_portal/wallets/object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@
it { is_expected.to have_field(:ongoing_balance_cents).of_type("BigInt!") }
it { is_expected.to have_field(:ongoing_usage_balance_cents).of_type("BigInt!") }
it { is_expected.to have_field(:rate_amount).of_type("Float!") }
it { is_expected.to have_field(:last_balance_sync_at).of_type('ISO8601DateTime') }
end
2 changes: 2 additions & 0 deletions spec/services/customer_portal/customer_update_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

let(:update_args) do
{
customer_type: "individual",
document_locale: "es",
name: "Updated customer name",
firstname: "Updated customer firstname",
Expand Down Expand Up @@ -38,6 +39,7 @@

updated_customer = result.customer

expect(updated_customer.customer_type).to eq(update_args[:customer_type])
expect(updated_customer.name).to eq(update_args[:name])
expect(updated_customer.firstname).to eq(update_args[:firstname])
expect(updated_customer.lastname).to eq(update_args[:lastname])
Expand Down