From 50323fd5910616cc22ad78f318c8f91638bf2c64 Mon Sep 17 00:00:00 2001 From: Vincent Pochet Date: Tue, 12 Apr 2022 10:06:44 +0200 Subject: [PATCH] feat: Attach plan and subscription to Invoice GraphQL object --- app/graphql/types/invoices/object.rb | 4 ++- schema.graphql | 2 ++ schema.json | 28 +++++++++++++++++++ .../resolvers/customer_resolver_spec.rb | 9 ++++-- 4 files changed, 40 insertions(+), 3 deletions(-) diff --git a/app/graphql/types/invoices/object.rb b/app/graphql/types/invoices/object.rb index 58c10429bf8..61e31b0e960 100644 --- a/app/graphql/types/invoices/object.rb +++ b/app/graphql/types/invoices/object.rb @@ -19,7 +19,9 @@ class Object < Types::BaseObject field :created_at, GraphQL::Types::ISO8601DateTime, null: false field :updated_at, GraphQL::Types::ISO8601DateTime, null: false + + field :subscription, Types::Subscriptions::Object + field :plan, Types::Plans::Object end end end - diff --git a/schema.graphql b/schema.graphql index bac0dcbc15a..60878f13988 100644 --- a/schema.graphql +++ b/schema.graphql @@ -224,6 +224,8 @@ type Invoice { fromDate: ISO8601Date! id: ID! issuingDate: ISO8601Date! + plan: Plan + subscription: Subscription toDate: ISO8601Date! totalAmountCents: Int! totalAmountCurrency: CurrencyEnum! diff --git a/schema.json b/schema.json index 6c7fd05acbc..1f15d4c455b 100644 --- a/schema.json +++ b/schema.json @@ -1795,6 +1795,34 @@ ] }, + { + "name": "plan", + "description": null, + "type": { + "kind": "OBJECT", + "name": "Plan", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + }, + { + "name": "subscription", + "description": null, + "type": { + "kind": "OBJECT", + "name": "Subscription", + "ofType": null + }, + "isDeprecated": false, + "deprecationReason": null, + "args": [ + + ] + }, { "name": "toDate", "description": null, diff --git a/spec/graphql/resolvers/customer_resolver_spec.rb b/spec/graphql/resolvers/customer_resolver_spec.rb index bc5fa61ec28..3a36117d18b 100644 --- a/spec/graphql/resolvers/customer_resolver_spec.rb +++ b/spec/graphql/resolvers/customer_resolver_spec.rb @@ -20,6 +20,11 @@ let(:customer) do create(:customer, organization: organization) end + let(:subscription) { create(:subscription, customer: customer) } + + before do + create_list(:invoice, 2, subscription: subscription) + end it 'returns a single of customer' do result = execute_graphql( @@ -35,8 +40,8 @@ aggregate_failures do expect(customer_response['id']).to eq(customer.id) - expect(customer_response['subscriptions'].count).to eq(0) - expect(customer_response['invoices'].count).to eq(0) + expect(customer_response['subscriptions'].count).to eq(1) + expect(customer_response['invoices'].count).to eq(2) end end