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

fix (integrations): add possibility to filter bm and add-ons in graphql resolvers #2071

Merged
merged 1 commit into from
May 27, 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
10 changes: 9 additions & 1 deletion app/graphql/types/add_ons/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ class Object < Types::BaseObject

field :taxes, [Types::Taxes::Object]

field :integration_mappings, [Types::IntegrationMappings::Object], null: true
field :integration_mappings, [Types::IntegrationMappings::Object], null: true do
argument :integration_id, ID, required: false
end

def customers_count
object.applied_add_ons.select(:customer_id).distinct.count
Expand All @@ -34,6 +36,12 @@ def customers_count
def applied_add_ons_count
object.applied_add_ons.count
end

def integration_mappings(integration_id: nil)
mappings = object.integration_mappings
mappings = mappings.where(integration_id:) if integration_id
mappings
end
end
end
end
10 changes: 9 additions & 1 deletion app/graphql/types/billable_metrics/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ class Object < Types::BaseObject
field :deleted_at, GraphQL::Types::ISO8601DateTime, null: true
field :updated_at, GraphQL::Types::ISO8601DateTime, null: false

field :integration_mappings, [Types::IntegrationMappings::Object], null: true
field :integration_mappings, [Types::IntegrationMappings::Object], null: true do
argument :integration_id, ID, required: false
end

def subscriptions_count
object.plans.joins(:subscriptions).count
Expand All @@ -52,6 +54,12 @@ def draft_invoices_count
def plans_count
object.plans.distinct.count
end

def integration_mappings(integration_id: nil)
mappings = object.integration_mappings
mappings = mappings.where(integration_id:) if integration_id
mappings
end
end
end
end
4 changes: 2 additions & 2 deletions schema.graphql

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

26 changes: 24 additions & 2 deletions schema.json

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

46 changes: 46 additions & 0 deletions spec/graphql/resolvers/add_ons_resolver_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,50 @@
expect(add_ons_response['metadata']['totalCount']).to eq(1)
end
end

context 'with integration mappings' do
let(:integration) { create(:netsuite_integration, organization:) }
let(:netsuite_mapping) { create(:netsuite_mapping, integration:, mappable_type: 'AddOn', mappable_id: add_on.id) }
let(:netsuite_mapping2) { create(:netsuite_mapping, external_name: 'Bla') }
let(:query) do
<<~GQL
query($integrationId: ID) {
addOns(limit: 5) {
collection { id name integrationMappings(integrationId: $integrationId) { externalId externalName } }
metadata { currentPage, totalCount }
}
}
GQL
end

before do
integration
netsuite_mapping
netsuite_mapping2
end

it 'returns a list of add-ons' do
result = execute_graphql(
current_user: membership.user,
current_organization: organization,
permissions: required_permission,
query:,
variables: {integrationId: integration.id},
)

add_ons_response = result['data']['addOns']

aggregate_failures do
expect(add_ons_response['collection'].first['id']).to eq(add_on.id)
expect(add_ons_response['collection'].first['name']).to eq(add_on.name)

expect(add_ons_response['collection'].first['integrationMappings'].count).to eq(1)
expect(add_ons_response['collection'].first['integrationMappings'].first['externalName'])
.to eq('Credits and Discounts')

expect(add_ons_response['metadata']['currentPage']).to eq(1)
expect(add_ons_response['metadata']['totalCount']).to eq(1)
end
end
end
end
Loading