diff options
author | Saturnino Abril <saturnino.abril@gmail.com> | 2017-03-24 21:17:46 +0900 |
---|---|---|
committer | Joram Wilander <jwawilander@gmail.com> | 2017-03-24 08:17:46 -0400 |
commit | d0af931e6e57b78432d5527b6e7b0be36c538144 (patch) | |
tree | 7196ec5e627fe27b539f982df4374e2d2d381f14 /api4/team_test.go | |
parent | 4c1eb7ff5575be07b8410e76da4cdaa964c2ef91 (diff) | |
download | chat-d0af931e6e57b78432d5527b6e7b0be36c538144.tar.gz chat-d0af931e6e57b78432d5527b6e7b0be36c538144.tar.bz2 chat-d0af931e6e57b78432d5527b6e7b0be36c538144.zip |
APIv4 put /teams/{team_id}/patch (#5860)
Diffstat (limited to 'api4/team_test.go')
-rw-r--r-- | api4/team_test.go | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/api4/team_test.go b/api4/team_test.go index 2076a8c1d..1f1e031b3 100644 --- a/api4/team_test.go +++ b/api4/team_test.go @@ -247,6 +247,75 @@ func TestUpdateTeam(t *testing.T) { CheckNoError(t, resp) } +func TestPatchTeam(t *testing.T) { + th := Setup().InitBasic().InitSystemAdmin() + defer TearDown() + Client := th.Client + + team := &model.Team{DisplayName: "Name", Description: "Some description", CompanyName: "Some company name", AllowOpenInvite: false, InviteId: "inviteid0", Name: "z-z-" + model.NewId() + "a", Email: "success+" + model.NewId() + "@simulator.amazonses.com", Type: model.TEAM_OPEN} + team, _ = Client.CreateTeam(team) + + patch := &model.TeamPatch{} + + patch.DisplayName = new(string) + *patch.DisplayName = "Other name" + patch.Description = new(string) + *patch.Description = "Other description" + patch.CompanyName = new(string) + *patch.CompanyName = "Other company name" + patch.InviteId = new(string) + *patch.InviteId = "inviteid1" + patch.AllowOpenInvite = new(bool) + *patch.AllowOpenInvite = true + + rteam, resp := Client.PatchTeam(team.Id, patch) + CheckNoError(t, resp) + CheckTeamSanitization(t, rteam) + + if rteam.DisplayName != "Other name" { + t.Fatal("DisplayName did not update properly") + } + if rteam.Description != "Other description" { + t.Fatal("Description did not update properly") + } + if rteam.CompanyName != "Other company name" { + t.Fatal("CompanyName did not update properly") + } + if rteam.InviteId != "inviteid1" { + t.Fatal("InviteId did not update properly") + } + if rteam.AllowOpenInvite != true { + t.Fatal("AllowOpenInvite did not update properly") + } + + _, resp = Client.PatchTeam("junk", patch) + CheckBadRequestStatus(t, resp) + + _, resp = Client.PatchTeam(GenerateTestId(), patch) + CheckForbiddenStatus(t, resp) + + if r, err := Client.DoApiPut("/teams/"+team.Id+"/patch", "garbage"); err == nil { + t.Fatal("should have errored") + } else { + if r.StatusCode != http.StatusBadRequest { + t.Log("actual: " + strconv.Itoa(r.StatusCode)) + t.Log("expected: " + strconv.Itoa(http.StatusBadRequest)) + t.Fatal("wrong status code") + } + } + + Client.Logout() + _, resp = Client.PatchTeam(team.Id, patch) + CheckUnauthorizedStatus(t, resp) + + th.LoginBasic2() + _, resp = Client.PatchTeam(team.Id, patch) + CheckForbiddenStatus(t, resp) + + _, resp = th.SystemAdminClient.PatchTeam(team.Id, patch) + CheckNoError(t, resp) +} + func TestGetAllTeams(t *testing.T) { th := Setup().InitBasic().InitSystemAdmin() defer TearDown() |