Этот коммит содержится в:
Nathaniel Allred
2022-06-17 11:13:22 -05:00
коммит произвёл GitHub
родитель 18c8a2bb53
Коммит d43c06ea75
11 изменённых файлов: 9 добавлений и 146 удалений

Просмотреть файл

@@ -7,7 +7,6 @@ import (
"errors"
"net/http"
"net/http/httptest"
"os"
"testing"
"github.com/stretchr/testify/mock"
@@ -18,31 +17,10 @@ import (
)
func Test_getCloudLimits(t *testing.T) {
t.Run("feature flag off returns empty limits", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "false")
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
th.App.ReloadConfig()
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
limits, r, err := th.Client.GetProductLimits()
require.NoError(t, err)
require.Equal(t, limits, &model.ProductLimits{})
require.Equal(t, http.StatusOK, r.StatusCode, "Expected 200 OK")
})
t.Run("no license returns not implemented", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
th.App.ReloadConfig()
th.App.Srv().RemoveLicense()
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
@@ -57,10 +35,6 @@ func Test_getCloudLimits(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
th.App.ReloadConfig()
th.App.Srv().SetLicense(model.NewTestLicense())
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
@@ -75,9 +49,6 @@ func Test_getCloudLimits(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
th.App.ReloadConfig()
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
cloud := &mocks.CloudInterface{}
@@ -109,13 +80,10 @@ func Test_getCloudLimits(t *testing.T) {
require.Equal(t, http.StatusUnauthorized, r.StatusCode, "Expected 401 Unauthorized")
})
t.Run("good request with cloud server and feature flag returns response", func(t *testing.T) {
t.Run("good request with cloud server", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
th.App.ReloadConfig()
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
cloud := &mocks.CloudInterface{}
@@ -163,10 +131,6 @@ func Test_requestTrial(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
th.App.ReloadConfig()
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
@@ -188,44 +152,10 @@ func Test_requestTrial(t *testing.T) {
require.Equal(t, http.StatusForbidden, r.StatusCode, "403 Forbidden")
})
t.Run("cloudFree feature flag FALSE and Admin user are UNABLE to request the trial", func(t *testing.T) {
t.Run("ADMIN user are ABLE to request the trial", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "false")
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
th.App.ReloadConfig()
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)
cloud.Mock.On("RequestCloudTrial", mock.Anything, mock.Anything, "").Return(subscription, nil)
cloudImpl := th.App.Srv().Cloud
defer func() {
th.App.Srv().Cloud = cloudImpl
}()
th.App.Srv().Cloud = &cloud
subscriptionChanged, r, err := th.SystemAdminClient.RequestCloudTrial(&newValidBusinessEmail)
require.Error(t, err)
require.Nil(t, subscriptionChanged)
require.Equal(t, http.StatusInternalServerError, r.StatusCode, "Expected 500 Internal Server Error")
})
t.Run("cloudFree feature flag TRUE and ADMIN user are ABLE to request the trial", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
th.App.ReloadConfig()
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))
@@ -248,17 +178,13 @@ func Test_requestTrial(t *testing.T) {
require.Equal(t, http.StatusOK, r.StatusCode, "Status OK")
})
t.Run("cloudFree feature flag TRUE and ADMIN user are ABLE to request the trial with valid business email", func(t *testing.T) {
t.Run("ADMIN user are ABLE to request the trial with valid business email", func(t *testing.T) {
th := Setup(t).InitBasic()
defer th.TearDown()
// patch the customer with the additional contact updated with the valid business email
newValidBusinessEmail.Email = *model.NewString("valid.email@mattermost.com")
os.Setenv("MM_FEATUREFLAGS_CLOUDFREE", "true")
defer os.Unsetenv("MM_FEATUREFLAGS_CLOUDFREE")
th.App.ReloadConfig()
th.Client.Login(th.BasicUser.Email, th.BasicUser.Password)
th.App.Srv().SetLicense(model.NewTestLicense("cloud"))