summaryrefslogtreecommitdiffstats
path: root/model/command_response_test.go
diff options
context:
space:
mode:
authorHarrison Healey <harrisonmhealey@gmail.com>2017-03-08 04:15:33 -0500
committerGeorge Goldberg <george@gberg.me>2017-03-08 09:15:33 +0000
commit5d62b3661bcf4b912e7809ca05082e364e2b34b1 (patch)
tree0221dc157810527bc98809489f03f29305bab008 /model/command_response_test.go
parentf3a266ee5d25bfff322acd3cc5eef91a6dce8954 (diff)
downloadchat-5d62b3661bcf4b912e7809ca05082e364e2b34b1.tar.gz
chat-5d62b3661bcf4b912e7809ca05082e364e2b34b1.tar.bz2
chat-5d62b3661bcf4b912e7809ca05082e364e2b34b1.zip
Added additional validation for slack attachment format on server (#5680)
Diffstat (limited to 'model/command_response_test.go')
-rw-r--r--model/command_response_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/model/command_response_test.go b/model/command_response_test.go
index 7aa3e984b..131d87789 100644
--- a/model/command_response_test.go
+++ b/model/command_response_test.go
@@ -17,3 +17,68 @@ func TestCommandResponseJson(t *testing.T) {
t.Fatal("Ids do not match")
}
}
+
+func TestCommandResponseFromJson(t *testing.T) {
+ json := `{
+ "response_type": "ephemeral",
+ "text": "response text",
+ "username": "response username",
+ "icon_url": "response icon url",
+ "goto_location": "response goto location",
+ "attachments": [{
+ "text": "attachment 1 text",
+ "pretext": "attachment 1 pretext"
+ },{
+ "text": "attachment 2 text",
+ "fields": [{
+ "title": "field 1",
+ "value": "value 1",
+ "short": true
+ },{
+ "title": "field 2",
+ "value": [],
+ "short": false
+ }]
+ }]
+ }`
+
+ response := CommandResponseFromJson(strings.NewReader(json))
+
+ if response == nil {
+ t.Fatal("should've received non-nil CommandResponse")
+ }
+
+ if response.ResponseType != "ephemeral" {
+ t.Fatal("should've received correct response type")
+ } else if response.Text != "response text" {
+ t.Fatal("should've received correct response text")
+ } else if response.Username != "response username" {
+ t.Fatal("should've received correct response username")
+ } else if response.IconURL != "response icon url" {
+ t.Fatal("should've received correct response icon url")
+ } else if response.GotoLocation != "response goto location" {
+ t.Fatal("should've received correct response goto location")
+ }
+
+ attachments := response.Attachments
+ if len(attachments) != 2 {
+ t.Fatal("should've received 2 attachments")
+ } else if attachments[0].Text != "attachment 1 text" {
+ t.Fatal("should've received correct first attachment text")
+ } else if attachments[0].Pretext != "attachment 1 pretext" {
+ t.Fatal("should've received correct first attachment pretext")
+ } else if attachments[1].Text != "attachment 2 text" {
+ t.Fatal("should've received correct second attachment text")
+ }
+
+ fields := attachments[1].Fields
+ if len(fields) != 2 {
+ t.Fatal("should've received 2 fields")
+ } else if fields[0].Value.(string) != "value 1" {
+ t.Fatal("should've received correct first attachment value")
+ } else if _, ok := fields[1].Value.(string); !ok {
+ t.Fatal("should've received second attachment value parsed as a string")
+ } else if fields[1].Value.(string) != "[]" {
+ t.Fatal("should've received correct second attachment value")
+ }
+}