Skip to content

Add Query.addOnPurchase field

Bishwa Hang Rai requested to merge 432209-add-on-purchase-self-managed into master

What does this MR do and why?

For the existing query: Query.namespace.addOnPurchase, that is scoped to namespace, the existing logic for it has been moved to new files under namespace module:

  1. Resolver: ee/app/graphql/resolvers/namespaces/add_on_purchase_resolver.rb
  2. For spec: ee/spec/requests/api/graphql/namespace/add_on_purchase_spec.rb

We have added new query: 'Query.addOnPurchase', which is not scoped to any namespace. This is used in context of self-managed instance to fetch the AddOnPurchase information for given add-on type. Namespace scope does not exists on AddOnPurchase in context of 'self-managed'. It is only associated with 'SaaS (gitlab.com)'.

The existing files:

  1. Resolver:ee/app/graphql/resolvers/gitlab_subscriptions/add_on_purchase_resolver.rb
  2. Spec:ee/spec/requests/api/graphql/gitlab_subscriptions/add_on_purchase_spec.rb

were refactored to work for self-managed instance, without requiring namespace.

Screenshots or screen recordings

Screen_Recording_2023-11-22_at_15.40.27

How to set up and validate locally

Setting up the seed records

  1. Make sure that GDK is run as self-managed instance, i.e., GITLAB_SIMULATE_SAAS=0
  2. Open up a rails console GITLAB_SIMULATE_SAAS=0 gdk rails c
  3. Create a new AddOnPurchase record for testing:
# cleanup any existing old test records
::GitlabSubscriptions::AddOnPurchase.destroy_all
# create a add_on record if not already created
add_on = GitlabSubscriptions::AddOn.find_or_create_by!(name: "code_suggestions") {|e| e.description = "Test"}
# create a add_on_purchase record without the namespace, mimicking SM instance
GitlabSubscriptions::AddOnPurchase.create!(add_on: add_on, expires_on: 1.year.from_now, quantity: 10, purchase_xid: 'A-12345')

Testing in graphql

{
  addOnPurchase(addOnType: CODE_SUGGESTIONS) {
    id
    assignedQuantity
    purchasedQuantity
    name
  }
}
  1. Go to http://gdk.test:3000/-/graphql-explorer, logged in as admin
  2. Enter the query above, it should return correct response
  3. Log out as admin, and log in as owner of some group
  4. Hard reset (CMD + SHIFT + R) the http://gdk.test:3000/-/graphql-explorer page to set correct cookies for newly logged user.
  5. The query should return null as owner doesn't have access.

Testing previous Query.namespace.addOnPurchase works as expected

Please refer to the testing process in this MR.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #432209

Edited by Bishwa Hang Rai

Merge request reports