summaryrefslogtreecommitdiffstats
path: root/api4/apitestlib.go
diff options
context:
space:
mode:
Diffstat (limited to 'api4/apitestlib.go')
-rw-r--r--api4/apitestlib.go100
1 files changed, 100 insertions, 0 deletions
diff --git a/api4/apitestlib.go b/api4/apitestlib.go
index ffeeb32fa..64d3f22b2 100644
--- a/api4/apitestlib.go
+++ b/api4/apitestlib.go
@@ -38,6 +38,37 @@ type TestHelper struct {
SystemAdminUser *model.User
}
+func SetupEnterprise() *TestHelper {
+ if app.Srv == nil {
+ utils.TranslationsPreInit()
+ utils.LoadConfig("config.json")
+ utils.InitTranslations(utils.Cfg.LocalizationSettings)
+ utils.Cfg.TeamSettings.MaxUsersPerTeam = 50
+ *utils.Cfg.RateLimitSettings.Enable = false
+ utils.Cfg.EmailSettings.SendEmailNotifications = true
+ utils.Cfg.EmailSettings.SMTPServer = "dockerhost"
+ utils.Cfg.EmailSettings.SMTPPort = "2500"
+ utils.Cfg.EmailSettings.FeedbackEmail = "test@example.com"
+ utils.DisableDebugLogForTest()
+ utils.License.Features.SetDefaults()
+ app.NewServer()
+ app.InitStores()
+ InitRouter()
+ app.StartServer()
+ utils.InitHTML()
+ InitApi(true)
+ utils.EnableDebugLogForTest()
+ app.Srv.Store.MarkSystemRanUnitTests()
+
+ *utils.Cfg.TeamSettings.EnableOpenServer = true
+ }
+
+ th := &TestHelper{}
+ th.Client = th.CreateClient()
+ th.SystemAdminClient = th.CreateClient()
+ return th
+}
+
func Setup() *TestHelper {
if app.Srv == nil {
utils.TranslationsPreInit()
@@ -441,6 +472,14 @@ func CheckNotImplementedStatus(t *testing.T, resp *model.Response) {
}
}
+func CheckOKStatus(t *testing.T, resp *model.Response) {
+ CheckNoError(t, resp)
+
+ if resp.StatusCode != http.StatusOK {
+ t.Fatalf("wrong status code. expected %d got %d", http.StatusOK, resp.StatusCode)
+ }
+}
+
func CheckErrorMessage(t *testing.T, resp *model.Response, errorId string) {
if resp.Error == nil {
debug.PrintStack()
@@ -456,6 +495,21 @@ func CheckErrorMessage(t *testing.T, resp *model.Response, errorId string) {
}
}
+func CheckInternalErrorStatus(t *testing.T, resp *model.Response) {
+ if resp.Error == nil {
+ debug.PrintStack()
+ t.Fatal("should have errored with status:" + strconv.Itoa(http.StatusNotImplemented))
+ return
+ }
+
+ if resp.StatusCode != http.StatusInternalServerError {
+ debug.PrintStack()
+ t.Log("actual: " + strconv.Itoa(resp.StatusCode))
+ t.Log("expected: " + strconv.Itoa(http.StatusNotImplemented))
+ t.Fatal("wrong status code")
+ }
+}
+
func readTestFile(name string) ([]byte, error) {
path := utils.FindDir("tests")
file, err := os.Open(path + "/" + name)
@@ -518,3 +572,49 @@ func cleanupTestFile(info *model.FileInfo) error {
return nil
}
+
+func MakeUserChannelAdmin(user *model.User, channel *model.Channel) {
+ utils.DisableDebugLogForTest()
+
+ if cmr := <-app.Srv.Store.Channel().GetMember(channel.Id, user.Id); cmr.Err == nil {
+ cm := cmr.Data.(*model.ChannelMember)
+ cm.Roles = "channel_admin channel_user"
+ if sr := <-app.Srv.Store.Channel().UpdateMember(cm); sr.Err != nil {
+ utils.EnableDebugLogForTest()
+ panic(sr.Err)
+ }
+ } else {
+ utils.EnableDebugLogForTest()
+ panic(cmr.Err)
+ }
+
+ utils.EnableDebugLogForTest()
+}
+
+func UpdateUserToTeamAdmin(user *model.User, team *model.Team) {
+ utils.DisableDebugLogForTest()
+
+ tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_USER.Id + " " + model.ROLE_TEAM_ADMIN.Id}
+ if tmr := <-app.Srv.Store.Team().UpdateMember(tm); tmr.Err != nil {
+ utils.EnableDebugLogForTest()
+ l4g.Error(tmr.Err.Error())
+ l4g.Close()
+ time.Sleep(time.Second)
+ panic(tmr.Err)
+ }
+ utils.EnableDebugLogForTest()
+}
+
+func UpdateUserToNonTeamAdmin(user *model.User, team *model.Team) {
+ utils.DisableDebugLogForTest()
+
+ tm := &model.TeamMember{TeamId: team.Id, UserId: user.Id, Roles: model.ROLE_TEAM_USER.Id}
+ if tmr := <-app.Srv.Store.Team().UpdateMember(tm); tmr.Err != nil {
+ utils.EnableDebugLogForTest()
+ l4g.Error(tmr.Err.Error())
+ l4g.Close()
+ time.Sleep(time.Second)
+ panic(tmr.Err)
+ }
+ utils.EnableDebugLogForTest()
+}