Fix tests, flip login for cloud check.
Этот коммит содержится в:
@@ -313,7 +313,7 @@ func requestTrueUpReview(c *Context, w http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if c.App.Cloud() == nil {
|
if c.App.Cloud() != nil {
|
||||||
c.Err = model.NewAppError("cloudTrueUpReviewNotAllowed", "app.job.true_up_review_not_allowd", nil, "", http.StatusNotImplemented)
|
c.Err = model.NewAppError("cloudTrueUpReviewNotAllowed", "app.job.true_up_review_not_allowd", nil, "", http.StatusNotImplemented)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ package api4
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"testing"
|
"testing"
|
||||||
@@ -336,51 +335,25 @@ func TestRequestTrueUpReview(t *testing.T) {
|
|||||||
th := Setup(t)
|
th := Setup(t)
|
||||||
defer th.TearDown()
|
defer th.TearDown()
|
||||||
|
|
||||||
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",
|
|
||||||
TrialEndAt: 2000000000,
|
|
||||||
LastInvoice: &model.Invoice{},
|
|
||||||
}
|
|
||||||
|
|
||||||
th.App.Srv().SetLicense(model.NewTestLicense())
|
th.App.Srv().SetLicense(model.NewTestLicense())
|
||||||
|
|
||||||
t.Run("returns status 200 when telemetry data sent", func(t *testing.T) {
|
t.Run("returns status 200 when telemetry data sent", func(t *testing.T) {
|
||||||
cloud := mocks.CloudInterface{}
|
|
||||||
cloud.Mock.On("GetSubscription", mock.Anything).Return(subscription, nil)
|
|
||||||
|
|
||||||
th.App.Srv().Cloud = &cloud
|
|
||||||
cloudImpl := th.App.Srv().Cloud
|
|
||||||
defer func() {
|
|
||||||
th.App.Srv().Cloud = cloudImpl
|
|
||||||
}()
|
|
||||||
|
|
||||||
resp, err := th.SystemAdminClient.DoAPIPost("/license/review", "")
|
resp, err := th.SystemAdminClient.DoAPIPost("/license/review", "")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
require.Equal(t, http.StatusOK, resp.StatusCode)
|
require.Equal(t, http.StatusOK, resp.StatusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("returns 500 when data extraction fails", func(t *testing.T) {
|
t.Run("returns 501 when ran by cloud user", func(t *testing.T) {
|
||||||
cloud := mocks.CloudInterface{}
|
cloud := mocks.CloudInterface{}
|
||||||
cloud.Mock.On("GetSubscription", mock.Anything).Return(nil, errors.New("Could not get subscription"))
|
|
||||||
|
|
||||||
th.App.Srv().Cloud = &cloud
|
|
||||||
cloudImpl := th.App.Srv().Cloud
|
cloudImpl := th.App.Srv().Cloud
|
||||||
|
th.App.Srv().Cloud = &cloud
|
||||||
defer func() {
|
defer func() {
|
||||||
th.App.Srv().Cloud = cloudImpl
|
th.App.Srv().Cloud = cloudImpl
|
||||||
}()
|
}()
|
||||||
|
|
||||||
resp, err := th.SystemAdminClient.DoAPIPost("/license/review", "")
|
resp, err := th.SystemAdminClient.DoAPIPost("/license/review", "")
|
||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, http.StatusInternalServerError, resp.StatusCode)
|
require.Equal(t, http.StatusNotImplemented, resp.StatusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("returns 403 when user does not have permissions", func(t *testing.T) {
|
t.Run("returns 403 when user does not have permissions", func(t *testing.T) {
|
||||||
@@ -388,4 +361,12 @@ func TestRequestTrueUpReview(t *testing.T) {
|
|||||||
require.Error(t, err)
|
require.Error(t, err)
|
||||||
require.Equal(t, http.StatusForbidden, resp.StatusCode)
|
require.Equal(t, http.StatusForbidden, resp.StatusCode)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
t.Run("returns 400 when license is nil", func(t *testing.T) {
|
||||||
|
th.App.Srv().SetLicense(nil)
|
||||||
|
|
||||||
|
resp, err := th.SystemAdminClient.DoAPIPost("/license/review", "")
|
||||||
|
require.Error(t, err)
|
||||||
|
require.Equal(t, http.StatusBadRequest, resp.StatusCode)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user