MM-44863 - update trial details in product menu (#20534)
* MM-44863 - update trial details in product menu * update the test to reflect the initial returned subscription Co-authored-by: Pablo Velez Vidal <pablo.velez@mattermost.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
411e4d979c
Коммит
78e2d457f8
@@ -57,17 +57,32 @@ func getSubscription(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionSysconsoleReadBilling) {
|
|
||||||
c.SetPermissionError(model.PermissionSysconsoleReadBilling)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
subscription, err := c.App.Cloud().GetSubscription(c.AppContext.Session().UserId)
|
subscription, err := c.App.Cloud().GetSubscription(c.AppContext.Session().UserId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if it is an end user, return basic subscription data without sensitive information
|
||||||
|
if !c.App.SessionHasPermissionTo(*c.AppContext.Session(), model.PermissionSysconsoleReadBilling) {
|
||||||
|
subscription = &model.Subscription{
|
||||||
|
ID: subscription.ID,
|
||||||
|
ProductID: subscription.ProductID,
|
||||||
|
IsFreeTrial: subscription.IsFreeTrial,
|
||||||
|
TrialEndAt: subscription.TrialEndAt,
|
||||||
|
CustomerID: "",
|
||||||
|
AddOns: []string{},
|
||||||
|
StartAt: 0,
|
||||||
|
EndAt: 0,
|
||||||
|
CreateAt: 0,
|
||||||
|
Seats: 0,
|
||||||
|
Status: "",
|
||||||
|
DNS: "",
|
||||||
|
IsPaidTier: "",
|
||||||
|
LastInvoice: &model.Invoice{},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
json, err := json.Marshal(subscription)
|
json, err := json.Marshal(subscription)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
c.Err = model.NewAppError("Api4.getSubscription", "api.cloud.request_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
|
|||||||
@@ -111,6 +111,90 @@ func Test_getCloudLimits(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func Test_GetSubscription(t *testing.T) {
|
||||||
|
subscription := &model.Subscription{
|
||||||
|
ID: "MySubscriptionID",
|
||||||
|
CustomerID: "MyCustomer",
|
||||||
|
ProductID: "SomeProductId",
|
||||||
|
AddOns: []string{},
|
||||||
|
StartAt: 1000000000,
|
||||||
|
EndAt: 2000000000,
|
||||||
|
CreateAt: 1000000000,
|
||||||
|
Seats: 10,
|
||||||
|
IsFreeTrial: "true",
|
||||||
|
DNS: "some.dns.server",
|
||||||
|
IsPaidTier: "false",
|
||||||
|
TrialEndAt: 2000000000,
|
||||||
|
LastInvoice: &model.Invoice{},
|
||||||
|
}
|
||||||
|
|
||||||
|
userFacingSubscription := &model.Subscription{
|
||||||
|
ID: "MySubscriptionID",
|
||||||
|
CustomerID: "",
|
||||||
|
ProductID: "SomeProductId",
|
||||||
|
AddOns: []string{},
|
||||||
|
StartAt: 0,
|
||||||
|
EndAt: 0,
|
||||||
|
CreateAt: 0,
|
||||||
|
Seats: 0,
|
||||||
|
IsFreeTrial: "true",
|
||||||
|
DNS: "",
|
||||||
|
IsPaidTier: "",
|
||||||
|
TrialEndAt: 2000000000,
|
||||||
|
LastInvoice: &model.Invoice{},
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Run("NON Admin users receive the user facing subscription", func(t *testing.T) {
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||||
|
|
||||||
|
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||||
|
|
||||||
|
cloud := mocks.CloudInterface{}
|
||||||
|
|
||||||
|
cloud.Mock.On("GetSubscription", mock.Anything).Return(subscription, nil)
|
||||||
|
|
||||||
|
cloudImpl := th.App.Srv().Cloud
|
||||||
|
defer func() {
|
||||||
|
th.App.Srv().Cloud = cloudImpl
|
||||||
|
}()
|
||||||
|
th.App.Srv().Cloud = &cloud
|
||||||
|
|
||||||
|
subscriptionReturned, r, err := th.Client.GetSubscription()
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, subscriptionReturned, userFacingSubscription)
|
||||||
|
require.Equal(t, http.StatusOK, r.StatusCode, "Status OK")
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("Admin users receive the full subscription information", func(t *testing.T) {
|
||||||
|
th := Setup(t).InitBasic()
|
||||||
|
defer th.TearDown()
|
||||||
|
|
||||||
|
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
|
||||||
|
|
||||||
|
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
|
||||||
|
|
||||||
|
cloud := mocks.CloudInterface{}
|
||||||
|
|
||||||
|
cloud.Mock.On("GetSubscription", mock.Anything).Return(subscription, nil)
|
||||||
|
|
||||||
|
cloudImpl := th.App.Srv().Cloud
|
||||||
|
defer func() {
|
||||||
|
th.App.Srv().Cloud = cloudImpl
|
||||||
|
}()
|
||||||
|
th.App.Srv().Cloud = &cloud
|
||||||
|
|
||||||
|
subscriptionReturned, r, err := th.SystemAdminClient.GetSubscription()
|
||||||
|
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, subscriptionReturned, subscription)
|
||||||
|
require.Equal(t, http.StatusOK, r.StatusCode, "Status OK")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
func Test_requestTrial(t *testing.T) {
|
func Test_requestTrial(t *testing.T) {
|
||||||
subscription := &model.Subscription{
|
subscription := &model.Subscription{
|
||||||
ID: "MySubscriptionID",
|
ID: "MySubscriptionID",
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user