diff --git a/api4/license_test.go b/api4/license_test.go index bec61798cb..a3955b065d 100644 --- a/api4/license_test.go +++ b/api4/license_test.go @@ -111,3 +111,32 @@ func TestRemoveLicenseFile(t *testing.T) { require.True(t, ok) }) } + +func TestRequestTrialLicense(t *testing.T) { + th := Setup(t) + defer th.TearDown() + + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "http://localhost:8065/" }) + + t.Run("permission denied", func(t *testing.T) { + ok, resp := th.Client.RequestTrialLicense(1000) + CheckForbiddenStatus(t, resp) + require.False(t, ok) + }) + + t.Run("blank site url", func(t *testing.T) { + th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "" }) + defer th.App.UpdateConfig(func(cfg *model.Config) { *cfg.ServiceSettings.SiteURL = "http://localhost:8065/" }) + ok, resp := th.SystemAdminClient.RequestTrialLicense(1000) + CheckBadRequestStatus(t, resp) + require.Equal(t, "api.license.request_trial_license.no-site-url.app_error", resp.Error.Id) + require.False(t, ok) + }) + + t.Run("trial license user count less than current users", func(t *testing.T) { + ok, resp := th.SystemAdminClient.RequestTrialLicense(1) + CheckBadRequestStatus(t, resp) + require.Equal(t, "api.license.add_license.unique_users.app_error", resp.Error.Id) + require.False(t, ok) + }) +} diff --git a/model/client4.go b/model/client4.go index 75738d1394..77cb654dbc 100644 --- a/model/client4.go +++ b/model/client4.go @@ -5805,7 +5805,7 @@ func (c *Client4) GetChannelMemberCountsByGroup(channelID string, includeTimezon // RequestTrialLicense will request a trial license and install it in the server func (c *Client4) RequestTrialLicense(users int) (bool, *Response) { - b, _ := json.Marshal(map[string]int{"users": users}) + b, _ := json.Marshal(map[string]interface{}{"users": users, "terms_accepted": true}) r, err := c.DoApiPost("/trial-license", string(b)) if err != nil { return false, BuildErrorResponse(r, err) diff --git a/model/license.go b/model/license.go index e180a356d2..6823b5ffdd 100644 --- a/model/license.go +++ b/model/license.go @@ -31,6 +31,7 @@ type License struct { Features *Features `json:"features"` SkuName string `json:"sku_name"` SkuShortName string `json:"sku_short_name"` + IsTrial bool `json:"is_trial"` } type Customer struct { diff --git a/model/license_test.go b/model/license_test.go index c85b500e58..c3d893d325 100644 --- a/model/license_test.go +++ b/model/license_test.go @@ -158,6 +158,7 @@ func TestLicenseToFromJson(t *testing.T) { Company: NewId(), }, Features: &f, + IsTrial: true, } j := l.ToJson() @@ -169,6 +170,7 @@ func TestLicenseToFromJson(t *testing.T) { CheckInt64(t, l1.IssuedAt, l.IssuedAt) CheckInt64(t, l1.StartsAt, l.StartsAt) CheckInt64(t, l1.ExpiresAt, l.ExpiresAt) + CheckBool(t, l1.IsTrial, l.IsTrial) CheckString(t, l1.Customer.Id, l.Customer.Id) CheckString(t, l1.Customer.Name, l.Customer.Name)