mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-8708 Remove api package (#8784)
* Remove api package * Remove api dependency from cmd package * Remove EnableAPIv3 setting * Update web tests * Add more websocket tests * Move some ws and oauth tests to api4 package * Move command tests into api4 package * Test fixes * Fix msg command test * Add some app file tests
This commit is contained in:
@@ -7,17 +7,17 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/cmd"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestJoinChannel(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
channel := th.CreateChannel(th.BasicClient, th.BasicTeam)
|
||||
channel := th.CreatePublicChannel()
|
||||
|
||||
cmd.CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
||||
|
||||
@@ -29,10 +29,10 @@ func TestJoinChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRemoveChannel(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
channel := th.CreateChannel(th.BasicClient, th.BasicTeam)
|
||||
channel := th.CreatePublicChannel()
|
||||
|
||||
cmd.CheckCommand(t, "channel", "add", th.BasicTeam.Name+":"+channel.Name, th.BasicUser2.Email)
|
||||
|
||||
@@ -46,12 +46,11 @@ func TestRemoveChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestMoveChannel(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
client := th.BasicClient
|
||||
team1 := th.BasicTeam
|
||||
team2 := th.CreateTeam(client)
|
||||
team2 := th.CreateTeam()
|
||||
user1 := th.BasicUser
|
||||
th.LinkUserToTeam(user1, team2)
|
||||
channel := th.BasicChannel
|
||||
@@ -73,11 +72,11 @@ func TestMoveChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListChannels(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
channel := th.CreateChannel(th.BasicClient, th.BasicTeam)
|
||||
th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id))
|
||||
channel := th.CreatePublicChannel()
|
||||
th.Client.Must(th.Client.DeleteChannel(channel.Id))
|
||||
|
||||
output := cmd.CheckCommand(t, "channel", "list", th.BasicTeam.Name)
|
||||
|
||||
@@ -91,11 +90,11 @@ func TestListChannels(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestRestoreChannel(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
channel := th.CreateChannel(th.BasicClient, th.BasicTeam)
|
||||
th.BasicClient.Must(th.BasicClient.DeleteChannel(channel.Id))
|
||||
channel := th.CreatePublicChannel()
|
||||
th.Client.Must(th.Client.DeleteChannel(channel.Id))
|
||||
|
||||
cmd.CheckCommand(t, "channel", "restore", th.BasicTeam.Name+":"+channel.Name)
|
||||
|
||||
@@ -104,7 +103,7 @@ func TestRestoreChannel(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateChannel(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
id := model.NewId()
|
||||
|
||||
@@ -6,13 +6,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/cmd"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
func TestAssignRole(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
cmd.CheckCommand(t, "roles", "system_admin", th.BasicUser.Email)
|
||||
|
||||
@@ -6,13 +6,13 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/cmd"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestSampledataBadParameters(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// should fail because you need at least 1 worker
|
||||
|
||||
@@ -11,7 +11,6 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/app"
|
||||
"github.com/mattermost/mattermost-server/cmd"
|
||||
@@ -104,8 +103,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan
|
||||
return serverErr
|
||||
}
|
||||
|
||||
api4.Init(a, a.Srv.Router, false)
|
||||
api3 := api.Init(a, a.Srv.Router)
|
||||
api := api4.Init(a, a.Srv.Router)
|
||||
wsapi.Init(a, a.Srv.WebSocketRouter)
|
||||
web.NewWeb(a, a.Srv.Router)
|
||||
|
||||
@@ -135,7 +133,7 @@ func runServer(configFileLocation string, disableConfigWatch bool, interruptChan
|
||||
|
||||
// If we allow testing then listen for manual testing URL hits
|
||||
if a.Config().ServiceSettings.EnableTesting {
|
||||
manualtesting.Init(api3)
|
||||
manualtesting.Init(api)
|
||||
}
|
||||
|
||||
a.EnsureDiagnosticId()
|
||||
|
||||
@@ -7,13 +7,13 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/cmd"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
)
|
||||
|
||||
func TestCreateTeam(t *testing.T) {
|
||||
th := api.Setup().InitSystemAdmin()
|
||||
th := api4.Setup().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
id := model.NewId()
|
||||
@@ -22,7 +22,7 @@ func TestCreateTeam(t *testing.T) {
|
||||
|
||||
cmd.CheckCommand(t, "team", "create", "--name", name, "--display_name", displayName)
|
||||
|
||||
found := th.SystemAdminClient.Must(th.SystemAdminClient.FindTeamByName(name)).Data.(bool)
|
||||
found := th.SystemAdminClient.Must(th.SystemAdminClient.TeamExists(name, "")).(bool)
|
||||
|
||||
if !found {
|
||||
t.Fatal("Failed to create Team")
|
||||
@@ -30,12 +30,12 @@ func TestCreateTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestJoinTeam(t *testing.T) {
|
||||
th := api.Setup().InitSystemAdmin().InitBasic()
|
||||
th := api4.Setup().InitSystemAdmin().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
cmd.CheckCommand(t, "team", "add", th.SystemAdminTeam.Name, th.BasicUser.Email)
|
||||
cmd.CheckCommand(t, "team", "add", th.BasicTeam.Name, th.BasicUser.Email)
|
||||
|
||||
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User)
|
||||
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
|
||||
|
||||
found := false
|
||||
|
||||
@@ -52,12 +52,12 @@ func TestJoinTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLeaveTeam(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
cmd.CheckCommand(t, "team", "remove", th.BasicTeam.Name, th.BasicUser.Email)
|
||||
|
||||
profiles := th.BasicClient.Must(th.BasicClient.GetProfilesInTeam(th.BasicTeam.Id, 0, 1000, "")).Data.(map[string]*model.User)
|
||||
profiles := th.Client.Must(th.Client.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
|
||||
|
||||
found := false
|
||||
|
||||
@@ -81,7 +81,7 @@ func TestLeaveTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestListTeams(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
id := model.NewId()
|
||||
|
||||
@@ -12,7 +12,6 @@ import (
|
||||
"os/signal"
|
||||
"syscall"
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/cmd"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
@@ -60,8 +59,7 @@ func webClientTestsCmdF(command *cobra.Command, args []string) error {
|
||||
return serverErr
|
||||
}
|
||||
|
||||
api4.Init(a, a.Srv.Router, false)
|
||||
api.Init(a, a.Srv.Router)
|
||||
api4.Init(a, a.Srv.Router)
|
||||
wsapi.Init(a, a.Srv.WebSocketRouter)
|
||||
a.UpdateConfig(setupClientTests)
|
||||
runWebClientTests()
|
||||
@@ -82,8 +80,7 @@ func serverForWebClientTestsCmdF(command *cobra.Command, args []string) error {
|
||||
return serverErr
|
||||
}
|
||||
|
||||
api4.Init(a, a.Srv.Router, false)
|
||||
api.Init(a, a.Srv.Router)
|
||||
api4.Init(a, a.Srv.Router)
|
||||
wsapi.Init(a, a.Srv.WebSocketRouter)
|
||||
a.UpdateConfig(setupClientTests)
|
||||
|
||||
|
||||
@@ -6,14 +6,14 @@ package commands
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/mattermost/mattermost-server/api"
|
||||
"github.com/mattermost/mattermost-server/api4"
|
||||
"github.com/mattermost/mattermost-server/cmd"
|
||||
"github.com/mattermost/mattermost-server/model"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestCreateUserWithTeam(t *testing.T) {
|
||||
th := api.Setup().InitSystemAdmin()
|
||||
th := api4.Setup().InitBasic().InitSystemAdmin()
|
||||
defer th.TearDown()
|
||||
|
||||
id := model.NewId()
|
||||
@@ -22,9 +22,9 @@ func TestCreateUserWithTeam(t *testing.T) {
|
||||
|
||||
cmd.CheckCommand(t, "user", "create", "--email", email, "--password", "mypassword1", "--username", username)
|
||||
|
||||
cmd.CheckCommand(t, "team", "add", th.SystemAdminTeam.Id, email)
|
||||
cmd.CheckCommand(t, "team", "add", th.BasicTeam.Id, email)
|
||||
|
||||
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetProfilesInTeam(th.SystemAdminTeam.Id, 0, 1000, "")).Data.(map[string]*model.User)
|
||||
profiles := th.SystemAdminClient.Must(th.SystemAdminClient.GetUsersInTeam(th.BasicTeam.Id, 0, 1000, "")).([]*model.User)
|
||||
|
||||
found := false
|
||||
|
||||
@@ -41,7 +41,7 @@ func TestCreateUserWithTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestCreateUserWithoutTeam(t *testing.T) {
|
||||
th := api.Setup()
|
||||
th := api4.Setup()
|
||||
defer th.TearDown()
|
||||
|
||||
id := model.NewId()
|
||||
@@ -61,18 +61,18 @@ func TestCreateUserWithoutTeam(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestResetPassword(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
cmd.CheckCommand(t, "user", "password", th.BasicUser.Email, "password2")
|
||||
|
||||
th.BasicClient.Logout()
|
||||
th.Client.Logout()
|
||||
th.BasicUser.Password = "password2"
|
||||
th.LoginBasic()
|
||||
}
|
||||
|
||||
func TestMakeUserActiveAndInactive(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
// first inactivate the user
|
||||
@@ -83,7 +83,7 @@ func TestMakeUserActiveAndInactive(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestChangeUserEmail(t *testing.T) {
|
||||
th := api.Setup().InitBasic()
|
||||
th := api4.Setup().InitBasic()
|
||||
defer th.TearDown()
|
||||
|
||||
newEmail := model.NewId() + "@mattermost-test.com"
|
||||
|
||||
Reference in New Issue
Block a user