Fix shadowed variables in app package: Part 3 of 3 (#10002)
Этот коммит содержится в:
@@ -57,9 +57,8 @@ func TestPermanentDeleteChannel(t *testing.T) {
|
|||||||
t.Fatal("unable to get new outgoing webhook")
|
t.Fatal("unable to get new outgoing webhook")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := th.App.PermanentDeleteChannel(channel); err != nil {
|
err = th.App.PermanentDeleteChannel(channel)
|
||||||
t.Fatal(err.Error())
|
require.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
if incoming, err = th.App.GetIncomingWebhook(incoming.Id); incoming != nil || err == nil {
|
if incoming, err = th.App.GetIncomingWebhook(incoming.Id); incoming != nil || err == nil {
|
||||||
t.Error("incoming webhook wasn't deleted")
|
t.Error("incoming webhook wasn't deleted")
|
||||||
@@ -790,7 +789,8 @@ func TestGetPublicChannelsForTeam(t *testing.T) {
|
|||||||
Type: model.CHANNEL_OPEN,
|
Type: model.CHANNEL_OPEN,
|
||||||
TeamId: team.Id,
|
TeamId: team.Id,
|
||||||
}
|
}
|
||||||
rchannel, err := th.App.CreateChannel(&channel, false)
|
var rchannel *model.Channel
|
||||||
|
rchannel, err = th.App.CreateChannel(&channel, false)
|
||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
require.NotNil(t, rchannel)
|
require.NotNil(t, rchannel)
|
||||||
defer th.App.PermanentDeleteChannel(rchannel)
|
defer th.App.PermanentDeleteChannel(rchannel)
|
||||||
|
|||||||
@@ -805,9 +805,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, true); err == nil {
|
err = th.App.ImportUser(&data, true)
|
||||||
t.Fatalf("Should have failed.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Test with an unknown team name & invalid channel membership in dry-run mode.
|
// Test with an unknown team name & invalid channel membership in dry-run mode.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -820,9 +819,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, true); err == nil {
|
err = th.App.ImportUser(&data, true)
|
||||||
t.Fatalf("Should have failed.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Test with a valid team & invalid channel membership in dry-run mode.
|
// Test with a valid team & invalid channel membership in dry-run mode.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -835,9 +833,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, true); err == nil {
|
err = th.App.ImportUser(&data, true)
|
||||||
t.Fatalf("Should have failed.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Test with a valid team & unknown channel name in dry-run mode.
|
// Test with a valid team & unknown channel name in dry-run mode.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -850,9 +847,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, true); err != nil {
|
err = th.App.ImportUser(&data, true)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Test with a valid team & valid channel name in dry-run mode.
|
// Test with a valid team & valid channel name in dry-run mode.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -865,22 +861,17 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, true); err != nil {
|
err = th.App.ImportUser(&data, true)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Check no new member objects were created because dry run mode.
|
// Check no new member objects were created because dry run mode.
|
||||||
if tmc, err := th.App.GetTeamMembers(team.Id, 0, 1000); err != nil {
|
tmc, err := th.App.GetTeamMembers(team.Id, 0, 1000)
|
||||||
t.Fatalf("Failed to get Team Member Count")
|
require.Nil(t, err, "Failed to get Team Member Count")
|
||||||
} else if len(tmc) != teamMemberCount {
|
require.Len(t, tmc, teamMemberCount, "Number of team members not as expected")
|
||||||
t.Fatalf("Number of team members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmc, err := th.App.GetChannelMemberCount(channel.Id); err != nil {
|
cmc, err := th.App.GetChannelMemberCount(channel.Id)
|
||||||
t.Fatalf("Failed to get Channel Member Count")
|
require.Nil(t, err, "Failed to get Channel Member Count")
|
||||||
} else if cmc != channelMemberCount {
|
require.Equal(t, channelMemberCount, cmc, "Number of channel members not as expected")
|
||||||
t.Fatalf("Number of channel members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test with an invalid team & channel membership in apply mode.
|
// Test with an invalid team & channel membership in apply mode.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -893,9 +884,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err == nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have failed.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Test with an unknown team name & invalid channel membership in apply mode.
|
// Test with an unknown team name & invalid channel membership in apply mode.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -908,9 +898,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err == nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have failed.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Test with a valid team & invalid channel membership in apply mode.
|
// Test with a valid team & invalid channel membership in apply mode.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -923,22 +912,17 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err == nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have failed.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Check no new member objects were created because all tests should have failed so far.
|
// Check no new member objects were created because all tests should have failed so far.
|
||||||
if tmc, err := th.App.GetTeamMembers(team.Id, 0, 1000); err != nil {
|
tmc, err = th.App.GetTeamMembers(team.Id, 0, 1000)
|
||||||
t.Fatalf("Failed to get Team Member Count")
|
require.Nil(t, err, "Failed to get Team Member Count")
|
||||||
} else if len(tmc) != teamMemberCount {
|
require.Len(t, tmc, teamMemberCount)
|
||||||
t.Fatalf("Number of team members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmc, err := th.App.GetChannelMemberCount(channel.Id); err != nil {
|
cmc, err = th.App.GetChannelMemberCount(channel.Id)
|
||||||
t.Fatalf("Failed to get Channel Member Count")
|
require.Nil(t, err, "Failed to get Channel Member Count")
|
||||||
} else if cmc != channelMemberCount {
|
require.Equal(t, channelMemberCount, cmc)
|
||||||
t.Fatalf("Number of channel members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Test with a valid team & unknown channel name in apply mode.
|
// Test with a valid team & unknown channel name in apply mode.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -951,33 +935,27 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err == nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have failed.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Check only new team member object created because dry run mode.
|
// Check only new team member object created because dry run mode.
|
||||||
if tmc, err := th.App.GetTeamMembers(team.Id, 0, 1000); err != nil {
|
tmc, err = th.App.GetTeamMembers(team.Id, 0, 1000)
|
||||||
t.Fatalf("Failed to get Team Member Count")
|
require.Nil(t, err, "Failed to get Team Member Count")
|
||||||
} else if len(tmc) != teamMemberCount+1 {
|
require.Len(t, tmc, teamMemberCount+1)
|
||||||
t.Fatalf("Number of team members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmc, err := th.App.GetChannelMemberCount(channel.Id); err != nil {
|
cmc, err = th.App.GetChannelMemberCount(channel.Id)
|
||||||
t.Fatalf("Failed to get Channel Member Count")
|
require.Nil(t, err, "Failed to get Channel Member Count")
|
||||||
} else if cmc != channelMemberCount {
|
require.Equal(t, channelMemberCount, cmc)
|
||||||
t.Fatalf("Number of channel members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check team member properties.
|
// Check team member properties.
|
||||||
user, err := th.App.GetUserByUsername(username)
|
user, err := th.App.GetUserByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to get user from database.")
|
t.Fatalf("Failed to get user from database.")
|
||||||
}
|
}
|
||||||
if teamMember, err := th.App.GetTeamMember(team.Id, user.Id); err != nil {
|
|
||||||
t.Fatalf("Failed to get team member from database.")
|
teamMember, err := th.App.GetTeamMember(team.Id, user.Id)
|
||||||
} else if teamMember.Roles != "team_user" {
|
require.Nil(t, err, "Failed to get team member from database.")
|
||||||
t.Fatalf("Team member properties not as expected")
|
require.Equal(t, "team_user", teamMember.Roles)
|
||||||
}
|
|
||||||
|
|
||||||
// Test with a valid team & valid channel name in apply mode.
|
// Test with a valid team & valid channel name in apply mode.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -990,29 +968,25 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Check only new channel member object created because dry run mode.
|
// Check only new channel member object created because dry run mode.
|
||||||
if tmc, err := th.App.GetTeamMembers(team.Id, 0, 1000); err != nil {
|
tmc, err = th.App.GetTeamMembers(team.Id, 0, 1000)
|
||||||
t.Fatalf("Failed to get Team Member Count")
|
require.Nil(t, err, "Failed to get Team Member Count")
|
||||||
} else if len(tmc) != teamMemberCount+1 {
|
require.Len(t, tmc, teamMemberCount+1, "Number of team members not as expected")
|
||||||
t.Fatalf("Number of team members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmc, err := th.App.GetChannelMemberCount(channel.Id); err != nil {
|
cmc, err = th.App.GetChannelMemberCount(channel.Id)
|
||||||
t.Fatalf("Failed to get Channel Member Count")
|
require.Nil(t, err, "Failed to get Channel Member Count")
|
||||||
} else if cmc != channelMemberCount+1 {
|
require.Equal(t, channelMemberCount+1, cmc, "Number of channel members not as expected")
|
||||||
t.Fatalf("Number of channel members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check channel member properties.
|
// Check channel member properties.
|
||||||
if channelMember, err := th.App.GetChannelMember(channel.Id, user.Id); err != nil {
|
channelMember, err := th.App.GetChannelMember(channel.Id, user.Id)
|
||||||
t.Fatalf("Failed to get channel member from database.")
|
require.Nil(t, err, "Failed to get channel member from database.")
|
||||||
} else if channelMember.Roles != "channel_user" || channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP] != "default" || channelMember.NotifyProps[model.PUSH_NOTIFY_PROP] != "default" || channelMember.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] != "all" {
|
assert.Equal(t, "channel_user", channelMember.Roles)
|
||||||
t.Fatalf("Channel member properties not as expected")
|
assert.Equal(t, "default", channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP])
|
||||||
}
|
assert.Equal(t, "default", channelMember.NotifyProps[model.PUSH_NOTIFY_PROP])
|
||||||
|
assert.Equal(t, "all", channelMember.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||||
|
|
||||||
// Test with the properties of the team and channel membership changed.
|
// Test with the properties of the team and channel membership changed.
|
||||||
data.Teams = &[]UserTeamImportData{
|
data.Teams = &[]UserTeamImportData{
|
||||||
@@ -1034,38 +1008,32 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Check both member properties.
|
// Check both member properties.
|
||||||
if teamMember, err := th.App.GetTeamMember(team.Id, user.Id); err != nil {
|
teamMember, err = th.App.GetTeamMember(team.Id, user.Id)
|
||||||
t.Fatalf("Failed to get team member from database.")
|
require.Nil(t, err, "Failed to get team member from database.")
|
||||||
} else if teamMember.Roles != "team_user team_admin" {
|
require.Equal(t, "team_user team_admin", teamMember.Roles)
|
||||||
t.Fatalf("Team member properties not as expected: %v", teamMember.Roles)
|
|
||||||
}
|
|
||||||
|
|
||||||
if channelMember, err := th.App.GetChannelMember(channel.Id, user.Id); err != nil {
|
channelMember, err = th.App.GetChannelMember(channel.Id, user.Id)
|
||||||
t.Fatalf("Failed to get channel member Desktop from database.")
|
require.Nil(t, err, "Failed to get channel member Desktop from database.")
|
||||||
} else if channelMember.Roles != "channel_user channel_admin" || channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP] != model.USER_NOTIFY_MENTION || channelMember.NotifyProps[model.PUSH_NOTIFY_PROP] != model.USER_NOTIFY_MENTION || channelMember.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP] != model.USER_NOTIFY_MENTION {
|
assert.Equal(t, "channel_user channel_admin", channelMember.Roles)
|
||||||
t.Fatalf("Channel member properties not as expected")
|
assert.Equal(t, model.USER_NOTIFY_MENTION, channelMember.NotifyProps[model.DESKTOP_NOTIFY_PROP])
|
||||||
}
|
assert.Equal(t, model.USER_NOTIFY_MENTION, channelMember.NotifyProps[model.PUSH_NOTIFY_PROP])
|
||||||
|
assert.Equal(t, model.USER_NOTIFY_MENTION, channelMember.NotifyProps[model.MARK_UNREAD_NOTIFY_PROP])
|
||||||
|
|
||||||
checkPreference(t, th.App, user.Id, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id, "true")
|
checkPreference(t, th.App, user.Id, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id, "true")
|
||||||
checkPreference(t, th.App, user.Id, model.PREFERENCE_CATEGORY_THEME, team.Id, *(*data.Teams)[0].Theme)
|
checkPreference(t, th.App, user.Id, model.PREFERENCE_CATEGORY_THEME, team.Id, *(*data.Teams)[0].Theme)
|
||||||
|
|
||||||
// No more new member objects.
|
// No more new member objects.
|
||||||
if tmc, err := th.App.GetTeamMembers(team.Id, 0, 1000); err != nil {
|
tmc, err = th.App.GetTeamMembers(team.Id, 0, 1000)
|
||||||
t.Fatalf("Failed to get Team Member Count")
|
require.Nil(t, err, "Failed to get Team Member Count")
|
||||||
} else if len(tmc) != teamMemberCount+1 {
|
require.Len(t, tmc, teamMemberCount+1, "Number of team members not as expected")
|
||||||
t.Fatalf("Number of team members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
if cmc, err := th.App.GetChannelMemberCount(channel.Id); err != nil {
|
cmc, err = th.App.GetChannelMemberCount(channel.Id)
|
||||||
t.Fatalf("Failed to get Channel Member Count")
|
require.Nil(t, err, "Failed to get Channel Member Count")
|
||||||
} else if cmc != channelMemberCount+1 {
|
require.Equal(t, channelMemberCount+1, cmc, "Number of channel members not as expected")
|
||||||
t.Fatalf("Number of channel members not as expected")
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add a user with some preferences.
|
// Add a user with some preferences.
|
||||||
username = model.NewId()
|
username = model.NewId()
|
||||||
@@ -1083,9 +1051,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
ShowUnreadSection: ptrStr("true"),
|
ShowUnreadSection: ptrStr("true"),
|
||||||
EmailInterval: ptrStr("immediately"),
|
EmailInterval: ptrStr("immediately"),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Check their values.
|
// Check their values.
|
||||||
user, err = th.App.GetUserByUsername(username)
|
user, err = th.App.GetUserByUsername(username)
|
||||||
@@ -1116,9 +1083,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
TutorialStep: ptrStr("2"),
|
TutorialStep: ptrStr("2"),
|
||||||
EmailInterval: ptrStr("hour"),
|
EmailInterval: ptrStr("hour"),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
// Check their values again.
|
// Check their values again.
|
||||||
checkPreference(t, th.App, user.Id, model.PREFERENCE_CATEGORY_THEME, "", *data.Theme)
|
checkPreference(t, th.App, user.Id, model.PREFERENCE_CATEGORY_THEME, "", *data.Theme)
|
||||||
@@ -1140,9 +1106,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
CommentsTrigger: ptrStr(model.COMMENTS_NOTIFY_ROOT),
|
CommentsTrigger: ptrStr(model.COMMENTS_NOTIFY_ROOT),
|
||||||
MentionKeys: ptrStr("valid,misc"),
|
MentionKeys: ptrStr("valid,misc"),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
user, err = th.App.GetUserByUsername(username)
|
user, err = th.App.GetUserByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1169,9 +1134,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
CommentsTrigger: ptrStr(model.COMMENTS_NOTIFY_ANY),
|
CommentsTrigger: ptrStr(model.COMMENTS_NOTIFY_ANY),
|
||||||
MentionKeys: ptrStr("misc"),
|
MentionKeys: ptrStr("misc"),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
user, err = th.App.GetUserByUsername(username)
|
user, err = th.App.GetUserByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1204,9 +1168,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
MentionKeys: ptrStr("misc"),
|
MentionKeys: ptrStr("misc"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := th.App.ImportUser(&data, false); err != nil {
|
err = th.App.ImportUser(&data, false)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
user, err = th.App.GetUserByUsername(username)
|
user, err = th.App.GetUserByUsername(username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -1256,9 +1219,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
Description: ptrStr("description"),
|
Description: ptrStr("description"),
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := th.App.ImportScheme(teamSchemeData, false); err != nil {
|
err = th.App.ImportScheme(teamSchemeData, false)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
var teamScheme *model.Scheme
|
var teamScheme *model.Scheme
|
||||||
if res := <-th.App.Srv.Store.Scheme().GetByName(*teamSchemeData.Name); res.Err != nil {
|
if res := <-th.App.Srv.Store.Scheme().GetByName(*teamSchemeData.Name); res.Err != nil {
|
||||||
@@ -1275,9 +1237,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
AllowOpenInvite: ptrBool(true),
|
AllowOpenInvite: ptrBool(true),
|
||||||
Scheme: &teamScheme.Name,
|
Scheme: &teamScheme.Name,
|
||||||
}
|
}
|
||||||
if err := th.App.ImportTeam(teamData, false); err != nil {
|
err = th.App.ImportTeam(teamData, false)
|
||||||
t.Fatalf("Import should have succeeded: %v", err.Error())
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
team, err = th.App.GetTeamByName(teamName)
|
team, err = th.App.GetTeamByName(teamName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to get team from database.")
|
t.Fatalf("Failed to get team from database.")
|
||||||
@@ -1291,9 +1252,8 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
Header: ptrStr("Channe Header"),
|
Header: ptrStr("Channe Header"),
|
||||||
Purpose: ptrStr("Channel Purpose"),
|
Purpose: ptrStr("Channel Purpose"),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportChannel(channelData, false); err != nil {
|
err = th.App.ImportChannel(channelData, false)
|
||||||
t.Fatalf("Import should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
channel, err = th.App.GetChannelByName(*channelData.Name, team.Id, false)
|
channel, err = th.App.GetChannelByName(*channelData.Name, team.Id, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to get channel from database: %v", err.Error())
|
t.Fatalf("Failed to get channel from database: %v", err.Error())
|
||||||
@@ -1316,16 +1276,15 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := th.App.ImportUser(userData, false); err != nil {
|
err = th.App.ImportUser(userData, false)
|
||||||
t.Fatalf("Should have succeeded.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
user, err = th.App.GetUserByUsername(*userData.Username)
|
user, err = th.App.GetUserByUsername(*userData.Username)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to get user from database.")
|
t.Fatalf("Failed to get user from database.")
|
||||||
}
|
}
|
||||||
|
|
||||||
teamMember, err := th.App.GetTeamMember(team.Id, user.Id)
|
teamMember, err = th.App.GetTeamMember(team.Id, user.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to get the team member")
|
t.Fatalf("Failed to get the team member")
|
||||||
}
|
}
|
||||||
@@ -1333,7 +1292,7 @@ func TestImportImportUser(t *testing.T) {
|
|||||||
assert.True(t, teamMember.SchemeUser)
|
assert.True(t, teamMember.SchemeUser)
|
||||||
assert.Equal(t, "", teamMember.ExplicitRoles)
|
assert.Equal(t, "", teamMember.ExplicitRoles)
|
||||||
|
|
||||||
channelMember, err := th.App.GetChannelMember(channel.Id, user.Id)
|
channelMember, err = th.App.GetChannelMember(channel.Id, user.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("Failed to get the channel member")
|
t.Fatalf("Failed to get the channel member")
|
||||||
}
|
}
|
||||||
@@ -1356,7 +1315,6 @@ func TestImportUserDefaultNotifyProps(t *testing.T) {
|
|||||||
Email: ptrStr("false"),
|
Email: ptrStr("false"),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
require.Nil(t, th.App.ImportUser(&data, false))
|
require.Nil(t, th.App.ImportUser(&data, false))
|
||||||
|
|
||||||
user, err := th.App.GetUserByUsername(username)
|
user, err := th.App.GetUserByUsername(username)
|
||||||
@@ -1436,9 +1394,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Channel: &channelName,
|
Channel: &channelName,
|
||||||
User: &username,
|
User: &username,
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, true); err == nil {
|
err = th.App.ImportPost(data, true)
|
||||||
t.Fatalf("Expected error.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
||||||
|
|
||||||
// Try adding a valid post in dry run mode.
|
// Try adding a valid post in dry run mode.
|
||||||
@@ -1449,9 +1406,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Message: ptrStr("Hello"),
|
Message: ptrStr("Hello"),
|
||||||
CreateAt: ptrInt64(model.GetMillis()),
|
CreateAt: ptrInt64(model.GetMillis()),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, true); err != nil {
|
err = th.App.ImportPost(data, true)
|
||||||
t.Fatalf("Expected success.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
||||||
|
|
||||||
// Try adding an invalid post in apply mode.
|
// Try adding an invalid post in apply mode.
|
||||||
@@ -1461,9 +1417,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
User: &username,
|
User: &username,
|
||||||
CreateAt: ptrInt64(model.GetMillis()),
|
CreateAt: ptrInt64(model.GetMillis()),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, false); err == nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected error.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
||||||
|
|
||||||
// Try adding a valid post with invalid team in apply mode.
|
// Try adding a valid post with invalid team in apply mode.
|
||||||
@@ -1474,9 +1429,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Message: ptrStr("Message"),
|
Message: ptrStr("Message"),
|
||||||
CreateAt: ptrInt64(model.GetMillis()),
|
CreateAt: ptrInt64(model.GetMillis()),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, false); err == nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected error.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
||||||
|
|
||||||
// Try adding a valid post with invalid channel in apply mode.
|
// Try adding a valid post with invalid channel in apply mode.
|
||||||
@@ -1487,9 +1441,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Message: ptrStr("Message"),
|
Message: ptrStr("Message"),
|
||||||
CreateAt: ptrInt64(model.GetMillis()),
|
CreateAt: ptrInt64(model.GetMillis()),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, false); err == nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected error.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
||||||
|
|
||||||
// Try adding a valid post with invalid user in apply mode.
|
// Try adding a valid post with invalid user in apply mode.
|
||||||
@@ -1500,9 +1453,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Message: ptrStr("Message"),
|
Message: ptrStr("Message"),
|
||||||
CreateAt: ptrInt64(model.GetMillis()),
|
CreateAt: ptrInt64(model.GetMillis()),
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, false); err == nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected error.")
|
assert.NotNil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 0, team.Id)
|
||||||
|
|
||||||
// Try adding a valid post in apply mode.
|
// Try adding a valid post in apply mode.
|
||||||
@@ -1514,9 +1466,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Message: ptrStr("Message"),
|
Message: ptrStr("Message"),
|
||||||
CreateAt: &time,
|
CreateAt: &time,
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, false); err != nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected success.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
||||||
|
|
||||||
// Check the post values.
|
// Check the post values.
|
||||||
@@ -1541,9 +1492,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Message: ptrStr("Message"),
|
Message: ptrStr("Message"),
|
||||||
CreateAt: &time,
|
CreateAt: &time,
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, false); err != nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected success.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 1, team.Id)
|
||||||
|
|
||||||
// Check the post values.
|
// Check the post values.
|
||||||
@@ -1569,9 +1519,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Message: ptrStr("Message"),
|
Message: ptrStr("Message"),
|
||||||
CreateAt: &newTime,
|
CreateAt: &newTime,
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, false); err != nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected success.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 2, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 2, team.Id)
|
||||||
|
|
||||||
// Save the post with a different message.
|
// Save the post with a different message.
|
||||||
@@ -1582,9 +1531,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Message: ptrStr("Message 2"),
|
Message: ptrStr("Message 2"),
|
||||||
CreateAt: &time,
|
CreateAt: &time,
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, false); err != nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected success.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 3, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 3, team.Id)
|
||||||
|
|
||||||
// Test with hashtags
|
// Test with hashtags
|
||||||
@@ -1596,9 +1544,8 @@ func TestImportImportPost(t *testing.T) {
|
|||||||
Message: ptrStr("Message 2 #hashtagmashupcity"),
|
Message: ptrStr("Message 2 #hashtagmashupcity"),
|
||||||
CreateAt: &hashtagTime,
|
CreateAt: &hashtagTime,
|
||||||
}
|
}
|
||||||
if err := th.App.ImportPost(data, false); err != nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected success.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
AssertAllPostsCount(t, th.App, initialPostCount, 4, team.Id)
|
AssertAllPostsCount(t, th.App, initialPostCount, 4, team.Id)
|
||||||
|
|
||||||
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(channel.Id, hashtagTime); result.Err != nil {
|
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(channel.Id, hashtagTime); result.Err != nil {
|
||||||
@@ -1983,7 +1930,6 @@ func TestImportImportDirectChannel(t *testing.T) {
|
|||||||
require.Nil(t, err)
|
require.Nil(t, err)
|
||||||
checkPreference(t, th.App, th.BasicUser.Id, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id, "true")
|
checkPreference(t, th.App, th.BasicUser.Id, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id, "true")
|
||||||
checkPreference(t, th.App, th.BasicUser2.Id, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id, "true")
|
checkPreference(t, th.App, th.BasicUser2.Id, model.PREFERENCE_CATEGORY_FAVORITE_CHANNEL, channel.Id, "true")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestImportImportDirectPost(t *testing.T) {
|
func TestImportImportDirectPost(t *testing.T) {
|
||||||
@@ -2008,10 +1954,9 @@ func TestImportImportDirectPost(t *testing.T) {
|
|||||||
directChannel = channel
|
directChannel = channel
|
||||||
|
|
||||||
// Get the number of posts in the system.
|
// Get the number of posts in the system.
|
||||||
var initialPostCount int64
|
|
||||||
result := <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
result := <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
|
||||||
require.Nil(t, result.Err)
|
require.Nil(t, result.Err)
|
||||||
initialPostCount = result.Data.(int64)
|
initialPostCount := result.Data.(int64)
|
||||||
|
|
||||||
// Try adding an invalid post in dry run mode.
|
// Try adding an invalid post in dry run mode.
|
||||||
data := &DirectPostImportData{
|
data := &DirectPostImportData{
|
||||||
@@ -2473,9 +2418,8 @@ func TestImportPostAndRepliesWithAttachments(t *testing.T) {
|
|||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := th.App.ImportPost(data, false); err != nil {
|
err = th.App.ImportPost(data, false)
|
||||||
t.Fatalf("Expected success.")
|
assert.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
attachments := GetAttachments(user3.Id, th, t)
|
attachments := GetAttachments(user3.Id, th, t)
|
||||||
assert.Equal(t, len(attachments), 2)
|
assert.Equal(t, len(attachments), 2)
|
||||||
|
|||||||
@@ -339,9 +339,8 @@ func TestPermanentDeleteTeam(t *testing.T) {
|
|||||||
t.Fatal("unable to get new command")
|
t.Fatal("unable to get new command")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := th.App.PermanentDeleteTeam(team); err != nil {
|
err = th.App.PermanentDeleteTeam(team)
|
||||||
t.Fatal(err.Error())
|
require.Nil(t, err)
|
||||||
}
|
|
||||||
|
|
||||||
if command, err = th.App.GetCommand(command.Id); command != nil || err == nil {
|
if command, err = th.App.GetCommand(command.Id); command != nil || err == nil {
|
||||||
t.Fatal("command wasn't deleted")
|
t.Fatal("command wasn't deleted")
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user