mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* reduce cfg boilerplate * fix compile error * user test fix * another test fix * simplify diagnostics / testing
107 lines
2.9 KiB
Go
107 lines
2.9 KiB
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/mattermost/mattermost-server/model"
|
|
)
|
|
|
|
func TestPermanentDeleteChannel(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
defer th.TearDown()
|
|
|
|
th.App.UpdateConfig(func(cfg *model.Config) {
|
|
cfg.ServiceSettings.EnableIncomingWebhooks = true
|
|
cfg.ServiceSettings.EnableOutgoingWebhooks = true
|
|
})
|
|
|
|
channel, err := th.App.CreateChannel(&model.Channel{DisplayName: "deletion-test", Name: "deletion-test", Type: model.CHANNEL_OPEN, TeamId: th.BasicTeam.Id}, false)
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
defer func() {
|
|
th.App.PermanentDeleteChannel(channel)
|
|
}()
|
|
|
|
incoming, err := th.App.CreateIncomingWebhookForChannel(th.BasicUser.Id, channel, &model.IncomingWebhook{ChannelId: channel.Id})
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
defer th.App.DeleteIncomingWebhook(incoming.Id)
|
|
|
|
if incoming, err = th.App.GetIncomingWebhook(incoming.Id); incoming == nil || err != nil {
|
|
t.Fatal("unable to get new incoming webhook")
|
|
}
|
|
|
|
outgoing, err := th.App.CreateOutgoingWebhook(&model.OutgoingWebhook{
|
|
ChannelId: channel.Id,
|
|
TeamId: channel.TeamId,
|
|
CreatorId: th.BasicUser.Id,
|
|
CallbackURLs: []string{"http://foo"},
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
defer th.App.DeleteOutgoingWebhook(outgoing.Id)
|
|
|
|
if outgoing, err = th.App.GetOutgoingWebhook(outgoing.Id); outgoing == nil || err != nil {
|
|
t.Fatal("unable to get new outgoing webhook")
|
|
}
|
|
|
|
if err := th.App.PermanentDeleteChannel(channel); err != nil {
|
|
t.Fatal(err.Error())
|
|
}
|
|
|
|
if incoming, err = th.App.GetIncomingWebhook(incoming.Id); incoming != nil || err == nil {
|
|
t.Error("incoming webhook wasn't deleted")
|
|
}
|
|
|
|
if outgoing, err = th.App.GetOutgoingWebhook(outgoing.Id); outgoing != nil || err == nil {
|
|
t.Error("outgoing webhook wasn't deleted")
|
|
}
|
|
}
|
|
|
|
func TestMoveChannel(t *testing.T) {
|
|
th := Setup().InitBasic()
|
|
defer th.TearDown()
|
|
|
|
sourceTeam := th.CreateTeam()
|
|
targetTeam := th.CreateTeam()
|
|
channel1 := th.CreateChannel(sourceTeam)
|
|
defer func() {
|
|
th.App.PermanentDeleteChannel(channel1)
|
|
th.App.PermanentDeleteTeam(sourceTeam)
|
|
th.App.PermanentDeleteTeam(targetTeam)
|
|
}()
|
|
|
|
if _, err := th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser.Id, ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := th.App.AddUserToTeam(sourceTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if _, err := th.App.AddUserToTeam(targetTeam.Id, th.BasicUser.Id, ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if _, err := th.App.AddUserToChannel(th.BasicUser, channel1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if _, err := th.App.AddUserToChannel(th.BasicUser2, channel1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := th.App.MoveChannel(targetTeam, channel1); err == nil {
|
|
t.Fatal("Should have failed due to mismatched members.")
|
|
}
|
|
|
|
if _, err := th.App.AddUserToTeam(targetTeam.Id, th.BasicUser2.Id, ""); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if err := th.App.MoveChannel(targetTeam, channel1); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|