summaryrefslogtreecommitdiffstats
path: root/api4/reaction_test.go
diff options
context:
space:
mode:
authorSaturnino Abril <saturnino.abril@gmail.com>2017-04-19 05:15:15 +0900
committerJoram Wilander <jwawilander@gmail.com>2017-04-18 16:15:15 -0400
commitd2b86f1b8de4784baf578b611cf80779ccfa722a (patch)
tree076d56f2522c0d9580e04061db3cce99facce67b /api4/reaction_test.go
parent8aab290d10cc7cdd864cebbd463044abfa2d2aea (diff)
downloadchat-d2b86f1b8de4784baf578b611cf80779ccfa722a.tar.gz
chat-d2b86f1b8de4784baf578b611cf80779ccfa722a.tar.bz2
chat-d2b86f1b8de4784baf578b611cf80779ccfa722a.zip
APIv4 POST /reactions (#6092)
* APIv4 POST /reactions * update corresponding V3 endpoint
Diffstat (limited to 'api4/reaction_test.go')
-rw-r--r--api4/reaction_test.go106
1 files changed, 106 insertions, 0 deletions
diff --git a/api4/reaction_test.go b/api4/reaction_test.go
index 9e0847c2d..980a96d68 100644
--- a/api4/reaction_test.go
+++ b/api4/reaction_test.go
@@ -4,6 +4,7 @@
package api4
import (
+ "strings"
"testing"
"reflect"
@@ -12,6 +13,111 @@ import (
"github.com/mattermost/platform/model"
)
+func TestSaveReaction(t *testing.T) {
+ th := Setup().InitBasic().InitSystemAdmin()
+ defer TearDown()
+ Client := th.Client
+ userId := th.BasicUser.Id
+ postId := th.BasicPost.Id
+
+ reaction := &model.Reaction{
+ UserId: userId,
+ PostId: postId,
+ EmojiName: "smile",
+ }
+
+ rr, resp := Client.SaveReaction(reaction)
+ CheckNoError(t, resp)
+
+ if rr.UserId != reaction.UserId {
+ t.Fatal("UserId did not match")
+ }
+
+ if rr.PostId != reaction.PostId {
+ t.Fatal("PostId did not match")
+ }
+
+ if rr.EmojiName != reaction.EmojiName {
+ t.Fatal("EmojiName did not match")
+ }
+
+ if rr.CreateAt == 0 {
+ t.Fatal("CreateAt should exist")
+ }
+
+ if reactions, err := app.GetReactionsForPost(postId); err != nil && len(reactions) != 1 {
+ t.Fatal("didn't save reaction correctly")
+ }
+
+ // saving a duplicate reaction
+ rr, resp = Client.SaveReaction(reaction)
+ CheckNoError(t, resp)
+
+ if reactions, err := app.GetReactionsForPost(postId); err != nil && len(reactions) != 1 {
+ t.Fatal("should have not save duplicated reaction")
+ }
+
+ reaction.EmojiName = "sad"
+
+ rr, resp = Client.SaveReaction(reaction)
+ CheckNoError(t, resp)
+
+ if rr.EmojiName != reaction.EmojiName {
+ t.Fatal("EmojiName did not match")
+ }
+
+ if reactions, err := app.GetReactionsForPost(postId); err != nil && len(reactions) != 2 {
+ t.Fatal("should have save multiple reactions")
+ }
+
+ reaction.PostId = GenerateTestId()
+
+ _, resp = Client.SaveReaction(reaction)
+ CheckForbiddenStatus(t, resp)
+
+ reaction.PostId = "junk"
+
+ _, resp = Client.SaveReaction(reaction)
+ CheckBadRequestStatus(t, resp)
+
+ reaction.PostId = postId
+ reaction.UserId = GenerateTestId()
+
+ _, resp = Client.SaveReaction(reaction)
+ CheckForbiddenStatus(t, resp)
+
+ reaction.UserId = "junk"
+
+ _, resp = Client.SaveReaction(reaction)
+ CheckBadRequestStatus(t, resp)
+
+ reaction.UserId = userId
+ reaction.EmojiName = ""
+
+ _, resp = Client.SaveReaction(reaction)
+ CheckBadRequestStatus(t, resp)
+
+ reaction.EmojiName = strings.Repeat("a", 65)
+
+ _, resp = Client.SaveReaction(reaction)
+ CheckBadRequestStatus(t, resp)
+
+ reaction.EmojiName = "smile"
+ otherUser := th.CreateUser()
+ Client.Logout()
+ Client.Login(otherUser.Email, otherUser.Password)
+
+ _, resp = Client.SaveReaction(reaction)
+ CheckForbiddenStatus(t, resp)
+
+ Client.Logout()
+ _, resp = Client.SaveReaction(reaction)
+ CheckUnauthorizedStatus(t, resp)
+
+ _, resp = th.SystemAdminClient.SaveReaction(reaction)
+ CheckForbiddenStatus(t, resp)
+}
+
func TestGetReactions(t *testing.T) {
th := Setup().InitBasic().InitSystemAdmin()
defer TearDown()