Add Add-on purchase API services
What does this MR do and why?
Part of https://gitlab.com/gitlab-org/gitlab/-/issues/414605+
New API endpoints to sync Add-on purchases are going to be added in another iteration. These endpoints allow to create, get and update an Add-on purchase. In this change, two new service to create and update an Add-on purchase are added that will later be used by the endpoints.
The endpoints will be added in Add API endpoints to sync add-on purchases (!123382 - merged).
How to set up and validate locally
-
Create the code suggestions add-on in the rails console (note: This record will be added as a post migration or lazy creation in another MR):
add_on = GitlabSubscriptions::AddOn.create(name: :code_suggestions, description: 'Add-on for code suggestions')
-
Load a namespace and user to use:
namespace = Namespace.find(<NAMESPACE_ID>) user = User.find(<USER_ID>)
-
Test the service for creation.
Test scenarios
- With a validation error:
params = { quantity: 0, expires_on: Date.current + 1.month, purchase_xid: '1a2b3c' } GitlabSubscriptions::AddOnPurchases::CreateService.new( user, namespace, add_on, params ).execute
- With a success:
params = { quantity: 1, expires_on: Date.current + 1.month, purchase_xid: '1a2b3c' } GitlabSubscriptions::AddOnPurchases::CreateService.new( user, namespace, add_on, params ).execute
- With an error when the purchase already exists:
params = { quantity: 1, expires_on: Date.current + 1.month, purchase_xid: '1a2b3c' } GitlabSubscriptions::AddOnPurchases::CreateService.new( user, namespace, add_on, params ).execute
- With a validation error:
-
Test the service to update an add-on purchase record.
Test scenarios
- With a validation error:
params = { quantity: 0, expires_on: Date.current + 2.months, purchase_xid: '1a2b3c' } GitlabSubscriptions::AddOnPurchases::UpdateService.new( user, namespace, add_on, params ).execute
- With a success:
params = { quantity: 2, expires_on: Date.current + 2.months, purchase_xid: '1a2b3c' } GitlabSubscriptions::AddOnPurchases::UpdateService.new( user, namespace, add_on, params ).execute
- With an error when the purchase does not exist:
namespace = Namespace.find(<ANOTHER_NAMESPACE_ID>) params = { quantity: 2, expires_on: Date.current + 2.months, purchase_xid: '1a2b3c' } GitlabSubscriptions::AddOnPurchases::UpdateService.new( user, namespace, add_on, params ).execute
- With a validation error:
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.