Refactor Get/Create Direct Channel into one function (#9867)

* refactor GetDirectChannel and CreateDirectChannel in one function

* remove CreateDirectChannel plugin api and update GetDirectChannel and GetGroupChannel plugin api

* update tests
Этот коммит содержится в:
Carlos Tadeu Panato Junior
2018-11-28 18:01:49 +01:00
коммит произвёл GitHub
родитель 09eae76c00
Коммит 1bcf08aa4b
18 изменённых файлов: 241 добавлений и 402 удалений

Просмотреть файл

@@ -1835,9 +1835,8 @@ func TestImportImportDirectChannel(t *testing.T) {
},
Header: ptrStr("Channel Header"),
}
if err := th.App.ImportDirectChannel(&data, true); err == nil {
t.Fatalf("Expected error due to invalid name.")
}
err := th.App.ImportDirectChannel(&data, true)
require.NotNil(t, err)
// Check that no more channels are in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount)
@@ -1848,9 +1847,8 @@ func TestImportImportDirectChannel(t *testing.T) {
model.NewId(),
model.NewId(),
}
if err := th.App.ImportDirectChannel(&data, true); err != nil {
t.Fatalf("Expected success as cannot validate existence of channel members in dry run mode.")
}
err = th.App.ImportDirectChannel(&data, true)
require.Nil(t, err)
// Check that no more channels are in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount)
@@ -1862,9 +1860,8 @@ func TestImportImportDirectChannel(t *testing.T) {
model.NewId(),
model.NewId(),
}
if err := th.App.ImportDirectChannel(&data, true); err != nil {
t.Fatalf("Expected success as cannot validate existence of channel members in dry run mode.")
}
err = th.App.ImportDirectChannel(&data, true)
require.Nil(t, err)
// Check that no more channels are in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount)
@@ -1874,9 +1871,8 @@ func TestImportImportDirectChannel(t *testing.T) {
data.Members = &[]string{
model.NewId(),
}
if err := th.App.ImportDirectChannel(&data, false); err == nil {
t.Fatalf("Expected error due to invalid member (apply mode).")
}
err = th.App.ImportDirectChannel(&data, false)
require.NotNil(t, err)
// Check that no more channels are in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount)
@@ -1887,18 +1883,16 @@ func TestImportImportDirectChannel(t *testing.T) {
th.BasicUser.Username,
th.BasicUser2.Username,
}
if err := th.App.ImportDirectChannel(&data, false); err != nil {
t.Fatalf("Expected success: %v", err.Error())
}
err = th.App.ImportDirectChannel(&data, false)
require.Nil(t, err)
// Check that one more DIRECT channel is in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount+1)
AssertChannelCount(t, th.App, model.CHANNEL_GROUP, groupChannelCount)
// Do the same DIRECT channel again.
if err := th.App.ImportDirectChannel(&data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectChannel(&data, false)
require.Nil(t, err)
// Check that no more channels are in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount+1)
@@ -1906,22 +1900,17 @@ func TestImportImportDirectChannel(t *testing.T) {
// Update the channel's HEADER
data.Header = ptrStr("New Channel Header 2")
if err := th.App.ImportDirectChannel(&data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectChannel(&data, false)
require.Nil(t, err)
// Check that no more channels are in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount+1)
AssertChannelCount(t, th.App, model.CHANNEL_GROUP, groupChannelCount)
// Get the channel to check that the header was updated.
if channel, err := th.App.createDirectChannel(th.BasicUser.Id, th.BasicUser2.Id); err == nil || err.Id != store.CHANNEL_EXISTS_ERROR {
t.Fatal("Should have got store.CHANNEL_EXISTS_ERROR")
} else {
if channel.Header != *data.Header {
t.Fatal("Channel header has not been updated successfully.")
}
}
channel, err := th.App.GetOrCreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
require.Nil(t, err)
require.Equal(t, channel.Header, *data.Header)
// Do a GROUP channel with an extra invalid member.
user3 := th.CreateUser()
@@ -1931,9 +1920,8 @@ func TestImportImportDirectChannel(t *testing.T) {
user3.Username,
model.NewId(),
}
if err := th.App.ImportDirectChannel(&data, false); err == nil {
t.Fatalf("Should have failed due to invalid member in list.")
}
err = th.App.ImportDirectChannel(&data, false)
require.NotNil(t, err)
// Check that no more channels are in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount+1)
@@ -1945,18 +1933,16 @@ func TestImportImportDirectChannel(t *testing.T) {
th.BasicUser2.Username,
user3.Username,
}
if err := th.App.ImportDirectChannel(&data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectChannel(&data, false)
require.Nil(t, err)
// Check that one more GROUP channel is in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount+1)
AssertChannelCount(t, th.App, model.CHANNEL_GROUP, groupChannelCount+1)
// Do the same DIRECT channel again.
if err := th.App.ImportDirectChannel(&data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectChannel(&data, false)
require.Nil(t, err)
// Check that no more channels are in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount+1)
@@ -1964,9 +1950,8 @@ func TestImportImportDirectChannel(t *testing.T) {
// Update the channel's HEADER
data.Header = ptrStr("New Channel Header 3")
if err := th.App.ImportDirectChannel(&data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectChannel(&data, false)
require.Nil(t, err)
// Check that no more channels are in the DB.
AssertChannelCount(t, th.App, model.CHANNEL_DIRECT, directChannelCount+1)
@@ -1978,13 +1963,9 @@ func TestImportImportDirectChannel(t *testing.T) {
th.BasicUser2.Id,
user3.Id,
}
if channel, err := th.App.createGroupChannel(userIds, th.BasicUser.Id); err.Id != store.CHANNEL_EXISTS_ERROR {
t.Fatal("Should have got store.CHANNEL_EXISTS_ERROR")
} else {
if channel.Header != *data.Header {
t.Fatal("Channel header has not been updated successfully.")
}
}
channel, err = th.App.createGroupChannel(userIds, th.BasicUser.Id)
require.Equal(t, err.Id, store.CHANNEL_EXISTS_ERROR)
require.Equal(t, channel.Header, *data.Header)
// Import a channel with some favorites.
data.Members = &[]string{
@@ -1995,16 +1976,14 @@ func TestImportImportDirectChannel(t *testing.T) {
th.BasicUser.Username,
th.BasicUser2.Username,
}
if err := th.App.ImportDirectChannel(&data, false); err != nil {
t.Fatal(err)
}
err = th.App.ImportDirectChannel(&data, false)
require.Nil(t, err)
channel, err = th.App.GetOrCreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
require.Nil(t, err)
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")
if channel, err := th.App.createDirectChannel(th.BasicUser.Id, th.BasicUser2.Id); err == nil || err.Id != store.CHANNEL_EXISTS_ERROR {
t.Fatal("Should have got store.CHANNEL_EXISTS_ERROR")
} else {
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")
}
}
func TestImportImportDirectPost(t *testing.T) {
@@ -2018,25 +1997,21 @@ func TestImportImportDirectPost(t *testing.T) {
th.BasicUser2.Username,
},
}
if err := th.App.ImportDirectChannel(&channelData, false); err != nil {
t.Fatalf("Expected success: %v", err.Error())
}
err := th.App.ImportDirectChannel(&channelData, false)
require.Nil(t, err)
// Get the channel.
var directChannel *model.Channel
if channel, err := th.App.createDirectChannel(th.BasicUser.Id, th.BasicUser2.Id); err.Id != store.CHANNEL_EXISTS_ERROR {
t.Fatal("Should have got store.CHANNEL_EXISTS_ERROR")
} else {
directChannel = channel
}
channel, err := th.App.GetOrCreateDirectChannel(th.BasicUser.Id, th.BasicUser2.Id)
require.Nil(t, err)
require.NotEmpty(t, channel)
directChannel = channel
// Get the number of posts in the system.
var initialPostCount int64
if result := <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false); result.Err != nil {
t.Fatal(result.Err)
} else {
initialPostCount = result.Data.(int64)
}
result := <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
require.Nil(t, result.Err)
initialPostCount = result.Data.(int64)
// Try adding an invalid post in dry run mode.
data := &DirectPostImportData{
@@ -2047,9 +2022,8 @@ func TestImportImportDirectPost(t *testing.T) {
User: ptrStr(th.BasicUser.Username),
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, true); err == nil {
t.Fatalf("Expected error.")
}
err = th.App.ImportDirectPost(data, true)
require.NotNil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 0, "")
// Try adding a valid post in dry run mode.
@@ -2062,9 +2036,8 @@ func TestImportImportDirectPost(t *testing.T) {
Message: ptrStr("Message"),
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, true); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, true)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 0, "")
// Try adding an invalid post in apply mode.
@@ -2077,9 +2050,8 @@ func TestImportImportDirectPost(t *testing.T) {
Message: ptrStr("Message"),
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, false); err == nil {
t.Fatalf("Expected error.")
}
err = th.App.ImportDirectPost(data, false)
require.NotNil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 0, "")
// Try adding a valid post in apply mode.
@@ -2092,82 +2064,69 @@ func TestImportImportDirectPost(t *testing.T) {
Message: ptrStr("Message"),
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success: %v", err.Error())
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
// Check the post values.
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt); result.Err != nil {
t.Fatal(result.Err.Error())
} else {
posts := result.Data.([]*model.Post)
if len(posts) != 1 {
t.Fatal("Unexpected number of posts found.")
}
post := posts[0]
if post.Message != *data.Message || post.CreateAt != *data.CreateAt || post.UserId != th.BasicUser.Id {
t.Fatal("Post properties not as expected")
}
}
result = <-th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
require.Nil(t, result.Err)
posts := result.Data.([]*model.Post)
require.Equal(t, len(posts), 1)
post := posts[0]
require.Equal(t, post.Message, *data.Message)
require.Equal(t, post.CreateAt, *data.CreateAt)
require.Equal(t, post.UserId, th.BasicUser.Id)
// Import the post again.
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
// Check the post values.
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt); result.Err != nil {
t.Fatal(result.Err.Error())
} else {
posts := result.Data.([]*model.Post)
if len(posts) != 1 {
t.Fatal("Unexpected number of posts found.")
}
post := posts[0]
if post.Message != *data.Message || post.CreateAt != *data.CreateAt || post.UserId != th.BasicUser.Id {
t.Fatal("Post properties not as expected")
}
}
result = <-th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
require.Nil(t, result.Err)
posts = result.Data.([]*model.Post)
require.Equal(t, len(posts), 1)
post = posts[0]
require.Equal(t, post.Message, *data.Message)
require.Equal(t, post.CreateAt, *data.CreateAt)
require.Equal(t, post.UserId, th.BasicUser.Id)
// Save the post with a different time.
data.CreateAt = ptrInt64(*data.CreateAt + 1)
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 2, "")
// Save the post with a different message.
data.Message = ptrStr("Message 2")
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 3, "")
// Test with hashtags
data.Message = ptrStr("Message 2 #hashtagmashupcity")
data.CreateAt = ptrInt64(*data.CreateAt + 1)
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 4, "")
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt); result.Err != nil {
t.Fatal(result.Err.Error())
} else {
posts := result.Data.([]*model.Post)
if len(posts) != 1 {
t.Fatal("Unexpected number of posts found.")
}
post := posts[0]
if post.Message != *data.Message || post.CreateAt != *data.CreateAt || post.UserId != th.BasicUser.Id {
t.Fatal("Post properties not as expected")
}
if post.Hashtags != "#hashtagmashupcity" {
t.Fatalf("Hashtags not as expected: %s", post.Hashtags)
}
}
result = <-th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
require.Nil(t, result.Err)
posts = result.Data.([]*model.Post)
require.Equal(t, len(posts), 1)
post = posts[0]
require.Equal(t, post.Message, *data.Message)
require.Equal(t, post.CreateAt, *data.CreateAt)
require.Equal(t, post.UserId, th.BasicUser.Id)
require.Equal(t, post.Hashtags, "#hashtagmashupcity")
// Test with some flags.
data = &DirectPostImportData{
@@ -2184,22 +2143,19 @@ func TestImportImportDirectPost(t *testing.T) {
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success: %v", err.Error())
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
// Check the post values.
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt); result.Err != nil {
t.Fatal(result.Err.Error())
} else {
posts := result.Data.([]*model.Post)
if len(posts) != 1 {
t.Fatal("Unexpected number of posts found.")
}
post := posts[0]
checkPreference(t, th.App, th.BasicUser.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
checkPreference(t, th.App, th.BasicUser2.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
}
result = <-th.App.Srv.Store.Post().GetPostsCreatedAt(directChannel.Id, *data.CreateAt)
require.Nil(t, result.Err)
posts = result.Data.([]*model.Post)
require.Equal(t, len(posts), 1)
post = posts[0]
checkPreference(t, th.App, th.BasicUser.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
checkPreference(t, th.App, th.BasicUser2.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
// ------------------ Group Channel -------------------------
@@ -2212,9 +2168,8 @@ func TestImportImportDirectPost(t *testing.T) {
user3.Username,
},
}
if err := th.App.ImportDirectChannel(&channelData, false); err != nil {
t.Fatalf("Expected success: %v", err.Error())
}
err = th.App.ImportDirectChannel(&channelData, false)
require.Nil(t, err)
// Get the channel.
var groupChannel *model.Channel
@@ -2223,18 +2178,14 @@ func TestImportImportDirectPost(t *testing.T) {
th.BasicUser2.Id,
user3.Id,
}
if channel, err := th.App.createGroupChannel(userIds, th.BasicUser.Id); err.Id != store.CHANNEL_EXISTS_ERROR {
t.Fatal("Should have got store.CHANNEL_EXISTS_ERROR")
} else {
groupChannel = channel
}
channel, err = th.App.createGroupChannel(userIds, th.BasicUser.Id)
require.Equal(t, err.Id, store.CHANNEL_EXISTS_ERROR)
groupChannel = channel
// Get the number of posts in the system.
if result := <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false); result.Err != nil {
t.Fatal(result.Err)
} else {
initialPostCount = result.Data.(int64)
}
result = <-th.App.Srv.Store.Post().AnalyticsPostCount("", false, false)
require.Nil(t, result.Err)
initialPostCount = result.Data.(int64)
// Try adding an invalid post in dry run mode.
data = &DirectPostImportData{
@@ -2246,9 +2197,8 @@ func TestImportImportDirectPost(t *testing.T) {
User: ptrStr(th.BasicUser.Username),
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, true); err == nil {
t.Fatalf("Expected error.")
}
err = th.App.ImportDirectPost(data, true)
require.NotNil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 0, "")
// Try adding a valid post in dry run mode.
@@ -2262,9 +2212,8 @@ func TestImportImportDirectPost(t *testing.T) {
Message: ptrStr("Message"),
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, true); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, true)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 0, "")
// Try adding an invalid post in apply mode.
@@ -2279,9 +2228,8 @@ func TestImportImportDirectPost(t *testing.T) {
Message: ptrStr("Message"),
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, false); err == nil {
t.Fatalf("Expected error.")
}
err = th.App.ImportDirectPost(data, false)
require.NotNil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 0, "")
// Try adding a valid post in apply mode.
@@ -2295,82 +2243,69 @@ func TestImportImportDirectPost(t *testing.T) {
Message: ptrStr("Message"),
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success: %v", err.Error())
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
// Check the post values.
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt); result.Err != nil {
t.Fatal(result.Err.Error())
} else {
posts := result.Data.([]*model.Post)
if len(posts) != 1 {
t.Fatal("Unexpected number of posts found.")
}
post := posts[0]
if post.Message != *data.Message || post.CreateAt != *data.CreateAt || post.UserId != th.BasicUser.Id {
t.Fatal("Post properties not as expected")
}
}
result = <-th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
require.Nil(t, result.Err)
posts = result.Data.([]*model.Post)
require.Equal(t, len(posts), 1)
post = posts[0]
require.Equal(t, post.Message, *data.Message)
require.Equal(t, post.CreateAt, *data.CreateAt)
require.Equal(t, post.UserId, th.BasicUser.Id)
// Import the post again.
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 1, "")
// Check the post values.
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt); result.Err != nil {
t.Fatal(result.Err.Error())
} else {
posts := result.Data.([]*model.Post)
if len(posts) != 1 {
t.Fatal("Unexpected number of posts found.")
}
post := posts[0]
if post.Message != *data.Message || post.CreateAt != *data.CreateAt || post.UserId != th.BasicUser.Id {
t.Fatal("Post properties not as expected")
}
}
result = <-th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
require.Nil(t, result.Err)
posts = result.Data.([]*model.Post)
require.Equal(t, len(posts), 1)
post = posts[0]
require.Equal(t, post.Message, *data.Message)
require.Equal(t, post.CreateAt, *data.CreateAt)
require.Equal(t, post.UserId, th.BasicUser.Id)
// Save the post with a different time.
data.CreateAt = ptrInt64(*data.CreateAt + 1)
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 2, "")
// Save the post with a different message.
data.Message = ptrStr("Message 2")
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 3, "")
// Test with hashtags
data.Message = ptrStr("Message 2 #hashtagmashupcity")
data.CreateAt = ptrInt64(*data.CreateAt + 1)
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success.")
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
AssertAllPostsCount(t, th.App, initialPostCount, 4, "")
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt); result.Err != nil {
t.Fatal(result.Err.Error())
} else {
posts := result.Data.([]*model.Post)
if len(posts) != 1 {
t.Fatal("Unexpected number of posts found.")
}
post := posts[0]
if post.Message != *data.Message || post.CreateAt != *data.CreateAt || post.UserId != th.BasicUser.Id {
t.Fatal("Post properties not as expected")
}
if post.Hashtags != "#hashtagmashupcity" {
t.Fatalf("Hashtags not as expected: %s", post.Hashtags)
}
}
result = <-th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
require.Nil(t, result.Err)
posts = result.Data.([]*model.Post)
require.Equal(t, len(posts), 1)
post = posts[0]
require.Equal(t, post.Message, *data.Message)
require.Equal(t, post.CreateAt, *data.CreateAt)
require.Equal(t, post.UserId, th.BasicUser.Id)
require.Equal(t, post.Hashtags, "#hashtagmashupcity")
// Test with some flags.
data = &DirectPostImportData{
@@ -2388,22 +2323,20 @@ func TestImportImportDirectPost(t *testing.T) {
CreateAt: ptrInt64(model.GetMillis()),
}
if err := th.App.ImportDirectPost(data, false); err != nil {
t.Fatalf("Expected success: %v", err.Error())
}
err = th.App.ImportDirectPost(data, false)
require.Nil(t, err)
// Check the post values.
if result := <-th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt); result.Err != nil {
t.Fatal(result.Err.Error())
} else {
posts := result.Data.([]*model.Post)
if len(posts) != 1 {
t.Fatal("Unexpected number of posts found.")
}
post := posts[0]
checkPreference(t, th.App, th.BasicUser.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
checkPreference(t, th.App, th.BasicUser2.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
}
result = <-th.App.Srv.Store.Post().GetPostsCreatedAt(groupChannel.Id, *data.CreateAt)
require.Nil(t, result.Err)
posts = result.Data.([]*model.Post)
require.Equal(t, len(posts), 1)
post = posts[0]
checkPreference(t, th.App, th.BasicUser.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
checkPreference(t, th.App, th.BasicUser2.Id, model.PREFERENCE_CATEGORY_FLAGGED_POST, post.Id, "true")
}
func TestImportImportEmoji(t *testing.T) {