Skip to content
代码片段 群组 项目
未验证 提交 318753cf 编辑于 作者: Qingyu Zhao's avatar Qingyu Zhao 提交者: GitLab
浏览文件

AddOnPurchase process trial attribute

GitlabSubscriptions::AddOnPurchase introduced a new field `trial`. This
new field needs to be handled in API methods and update service:
- Update the add-on purchase for the namespace API accepts the
  `trial` as optional param
- Create an add-on purchase for the namespace API accepts the
  `trial` as optional param
- EE::API::Entities::GitlabSubscriptions::AddOnPurchase expose `trial`
- GitlabSubscriptions::AddOnPurchases::UpdateService updates `trial`

Changelog: added
EE: true
上级 67d16f92
No related branches found
No related tags found
无相关合并请求
显示 27 个添加10 个删除
......@@ -11,6 +11,7 @@ def initialize(namespace, add_on, params = {})
@quantity = params[:quantity]
@expires_on = params[:expires_on]
@purchase_xid = params[:purchase_xid]
@trial = params[:trial]
end
def execute
......@@ -19,7 +20,7 @@ def execute
private
attr_reader :namespace, :add_on, :quantity, :expires_on, :purchase_xid
attr_reader :namespace, :add_on, :quantity, :expires_on, :purchase_xid, :trial
# Override in derived class
def add_on_purchase
......
......@@ -34,7 +34,8 @@ def update_add_on_purchase
attributes = {
quantity: quantity,
expires_on: expires_on,
purchase_xid: purchase_xid
purchase_xid: purchase_xid,
trial: trial
}.compact
add_on_purchase.update(attributes)
......
......@@ -27,6 +27,7 @@ class AddOnPurchases < ::API::Base
requires :quantity, type: Integer, desc: 'The quantity of the purchase'
requires :expires_on, type: Date, desc: 'The date when purchase expires on'
requires :purchase_xid, type: String, desc: 'The purchase identifier (example: the subscription name)'
optional :trial, type: Boolean, desc: 'Whether the add-on is a trial'
end
post ":id/subscription_add_on_purchase/:add_on_name" do
result = ::GitlabSubscriptions::AddOnPurchases::CreateService.new(
......@@ -72,6 +73,7 @@ class AddOnPurchases < ::API::Base
requires :expires_on, type: Date, desc: 'The date when purchase expires on'
optional :quantity, type: Integer, desc: 'The quantity of the purchase'
optional :purchase_xid, type: String, desc: 'The purchase identifier (example: the subscription name)'
optional :trial, type: Boolean, desc: 'Whether the add-on is a trial'
end
put ":id/subscription_add_on_purchase/:add_on_name" do
result = ::GitlabSubscriptions::AddOnPurchases::UpdateService.new(
......
......@@ -11,6 +11,7 @@ class AddOnPurchase < Grape::Entity
expose :quantity, documentation: { type: 'integer', example: 10 }
expose :expires_on, documentation: { type: 'date', example: '2023-05-30' }
expose :purchase_xid, documentation: { type: 'string', example: 'A-S00000001' }
expose :trial, documentation: { type: 'boolean', example: 'false' }
def namespace_name
object.namespace.name
......
......@@ -7,6 +7,7 @@
quantity { 1 }
expires_on { 1.year.from_now.to_date }
purchase_xid { SecureRandom.hex(16) }
trial { false }
trait :active do
expires_on { 1.year.from_now.to_date }
......
......@@ -14,5 +14,6 @@
expect(entity[:quantity]).to eq add_on_purchase.quantity
expect(entity[:expires_on]).to eq add_on_purchase.expires_on
expect(entity[:purchase_xid]).to eq add_on_purchase.purchase_xid
expect(entity[:trial]).to eq add_on_purchase.trial
end
end
......@@ -211,7 +211,8 @@
'add_on' => add_on.name.titleize,
'quantity' => add_on_purchase.quantity,
'expires_on' => add_on_purchase.expires_on.to_s,
'purchase_xid' => add_on_purchase.purchase_xid
'purchase_xid' => add_on_purchase.purchase_xid,
'trial' => add_on_purchase.trial
)
end
end
......@@ -223,7 +224,8 @@
{
quantity: 10,
expires_on: (Date.current + 1.year).to_s,
purchase_xid: purchase_xid
purchase_xid: purchase_xid,
trial: true
}
end
......@@ -272,6 +274,7 @@
add_on_purchase.reload
end.to change { add_on_purchase.quantity }.from(5).to(10)
.and change { add_on_purchase.expires_on }.from(expires_on).to(params[:expires_on].to_date)
.and change { add_on_purchase.trial }.from(false).to(true)
expect(response).to have_gitlab_http_status(:success)
expect(json_response).to eq(
......@@ -280,7 +283,8 @@
'add_on' => add_on.name.titleize,
'quantity' => params[:quantity],
'expires_on' => params[:expires_on],
'purchase_xid' => params[:purchase_xid]
'purchase_xid' => params[:purchase_xid],
'trial' => params[:trial]
)
end
......@@ -301,7 +305,8 @@
'add_on' => add_on.name.titleize,
'quantity' => add_on_purchase.quantity,
'expires_on' => params[:expires_on],
'purchase_xid' => add_on_purchase.purchase_xid
'purchase_xid' => add_on_purchase.purchase_xid,
'trial' => add_on_purchase.trial
)
end
end
......
......@@ -11,7 +11,8 @@
{
quantity: 10,
expires_on: (Date.current + 1.year).to_s,
purchase_xid: 'S-A00000001'
purchase_xid: 'S-A00000001',
trial: false
}
end
......@@ -58,7 +59,8 @@ def add_on_purchase
add_on: add_on,
quantity: quantity,
expires_on: expires_on,
purchase_xid: purchase_xid
purchase_xid: purchase_xid,
trial: trial
)
end
end
......
......@@ -12,7 +12,8 @@
{
quantity: 10,
expires_on: (Date.current + 1.year).to_s,
purchase_xid: purchase_xid
purchase_xid: purchase_xid,
trial: true
}
end
......@@ -28,7 +29,8 @@
add_on: add_on,
quantity: 5,
expires_on: expires_on,
purchase_xid: purchase_xid
purchase_xid: purchase_xid,
trial: false
)
end
......@@ -44,6 +46,7 @@
add_on_purchase.reload
end.to change { add_on_purchase.quantity }.from(5).to(10)
.and change { add_on_purchase.expires_on }.from(expires_on).to(params[:expires_on].to_date)
.and change { add_on_purchase.trial }.from(false).to(true)
end
context 'when passing in the add-on purchase record' do
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册