|
|
|
@@ -0,0 +1,77 @@ |
|
|
|
package main |
|
|
|
|
|
|
|
import ( |
|
|
|
"encoding/json" |
|
|
|
"log" |
|
|
|
"testing" |
|
|
|
) |
|
|
|
|
|
|
|
func TestDecodeStream(t *testing.T) { |
|
|
|
msg := ` |
|
|
|
{ |
|
|
|
"id": "595072499036b8a52", |
|
|
|
"deleted": false, |
|
|
|
"post": "another stream", |
|
|
|
"data": {}, |
|
|
|
"type": "Post", |
|
|
|
"targetType": null, |
|
|
|
"number": 34, |
|
|
|
"isGlobal": false, |
|
|
|
"createdByGender": "", |
|
|
|
"isInternal": false, |
|
|
|
"createdAt": "2017-06-26 02:32:41", |
|
|
|
"modifiedAt": "2017-06-26 02:50:58", |
|
|
|
"parentId": "595071f8450974b72", |
|
|
|
"parentType": "Lead", |
|
|
|
"parentName": " \u5218\u5efa\u660e", |
|
|
|
"relatedId": null, |
|
|
|
"relatedType": null, |
|
|
|
"attachmentsIds": [ |
|
|
|
"5950769075cd82e67" |
|
|
|
], |
|
|
|
"attachmentsNames": { |
|
|
|
"5950769075cd82e67": "flag_gb.png" |
|
|
|
}, |
|
|
|
"createdById": "1", |
|
|
|
"createdByName": "Admin", |
|
|
|
"modifiedById": "1", |
|
|
|
"modifiedByName": "Admin", |
|
|
|
"superParentId": null, |
|
|
|
"superParentType": null, |
|
|
|
"attachmentsTypes": { |
|
|
|
"5950769075cd82e67": "image\/png" |
|
|
|
} |
|
|
|
} |
|
|
|
` |
|
|
|
s := crmdStream{} |
|
|
|
err := json.Unmarshal([]byte(msg), &s) |
|
|
|
if err != nil { |
|
|
|
log.Println(err) |
|
|
|
} |
|
|
|
AssertEqual(t, err, nil, "JsonDecode stream error should be nil ") |
|
|
|
AssertEqual(t, s.ID, "595072499036b8a52", "stream ID is not correct expect 595072499036b8a52") |
|
|
|
AssertEqual(t, s.Deleted, false, "deleted should be false") |
|
|
|
AssertEqual(t, s.Post, "another stream", "post content mismatch") |
|
|
|
AssertEqual(t, s.Type, "Post", "Type should be Post") |
|
|
|
AssertEqual(t, s.Number, 34, "Number should 34") |
|
|
|
AssertEqual(t, s.IsGlobal, false, "is global should be false") |
|
|
|
AssertEqual(t, s.CreatedByGender, "", "created by gender should be empty string") |
|
|
|
AssertEqual(t, s.IsInternal, false, "is internal should be false") |
|
|
|
AssertEqual(t, s.CreateAt, "2017-06-26 02:32:41", "time createdAt mismatch") |
|
|
|
AssertEqual(t, s.ModifiedAt, "2017-06-26 02:50:58", "time modifiedAt mismatch") |
|
|
|
AssertEqual(t, s.ParentID, "595071f8450974b72", "stream parent id mismatch") |
|
|
|
AssertEqual(t, s.ParentType, "Lead", "Parent type should be Lead") |
|
|
|
AssertEqual(t, s.ParentName, " \u5218\u5efa\u660e", "parent name should be [ \u5218\u5efa\u660e]") |
|
|
|
AssertEqual(t, s.RelatedID, "", "relatedID should be NULL") |
|
|
|
AssertEqual(t, s.RelatedType, "", "relatedType should be") |
|
|
|
AssertEqual(t, s.AttachmentsIDs[0], "5950769075cd82e67", "attachment id element[0] mismatch") |
|
|
|
AssertEqual(t, s.AttachmentsNames["5950769075cd82e67"], "flag_gb.png", "attachmentName mismatch") |
|
|
|
AssertEqual(t, s.CreatedByID, "1", "created by ID should be 1") |
|
|
|
AssertEqual(t, s.CreatedByName, "Admin", "CreatedBy name should be Admin") |
|
|
|
AssertEqual(t, s.ModifiedByID, "1", "modifiedById should be 1") |
|
|
|
AssertEqual(t, s.ModifiedByName, "Admin", "Modified By Name should be Admin") |
|
|
|
AssertEqual(t, s.SuperParentID, "", "SuperParentID should be empty") |
|
|
|
AssertEqual(t, s.SuperParentType, "", "SuperParentType should be empty") |
|
|
|
AssertEqual(t, s.AttachmentsTypes["5950769075cd82e67"], "image/png", "attachment mime type not match") |
|
|
|
|
|
|
|
} |