Add Query.addOnPurchase field
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:
- Resolver:
ee/app/graphql/resolvers/namespaces/add_on_purchase_resolver.rb
- 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:
- Resolver:
ee/app/graphql/resolvers/gitlab_subscriptions/add_on_purchase_resolver.rb
- 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
- Make sure that GDK is run as self-managed instance, i.e.,
GITLAB_SIMULATE_SAAS=0
- Open up a rails console
GITLAB_SIMULATE_SAAS=0 gdk rails c
- 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
}
}
- Go to
http://gdk.test:3000/-/graphql-explorer
, logged in asadmin
- Enter the query above, it should return correct response
- Log out as
admin
, and log in asowner
of some group - Hard reset
(CMD + SHIFT + R)
thehttp://gdk.test:3000/-/graphql-explorer
page to set correct cookies for newly logged user. - The query should return
null
asowner
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.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #432209