You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
3.0KB

  1. package main
  2. import (
  3. "encoding/json"
  4. "log"
  5. "testing"
  6. )
  7. func TestDecodeStream(t *testing.T) {
  8. msg := `
  9. {
  10. "id": "595072499036b8a52",
  11. "deleted": false,
  12. "post": "another stream",
  13. "data": {},
  14. "type": "Post",
  15. "targetType": null,
  16. "number": 34,
  17. "isGlobal": false,
  18. "createdByGender": "",
  19. "isInternal": false,
  20. "createdAt": "2017-06-26 02:32:41",
  21. "modifiedAt": "2017-06-26 02:50:58",
  22. "parentId": "595071f8450974b72",
  23. "parentType": "Lead",
  24. "parentName": " \u5218\u5efa\u660e",
  25. "relatedId": null,
  26. "relatedType": null,
  27. "attachmentsIds": [
  28. "5950769075cd82e67"
  29. ],
  30. "attachmentsNames": {
  31. "5950769075cd82e67": "flag_gb.png"
  32. },
  33. "createdById": "1",
  34. "createdByName": "Admin",
  35. "modifiedById": "1",
  36. "modifiedByName": "Admin",
  37. "superParentId": null,
  38. "superParentType": null,
  39. "attachmentsTypes": {
  40. "5950769075cd82e67": "image\/png"
  41. }
  42. }
  43. `
  44. s := crmdStream{}
  45. err := json.Unmarshal([]byte(msg), &s)
  46. if err != nil {
  47. log.Println(err)
  48. }
  49. AssertEqual(t, err, nil, "JsonDecode stream error should be nil ")
  50. AssertEqual(t, s.ID, "595072499036b8a52", "stream ID is not correct expect 595072499036b8a52")
  51. AssertEqual(t, s.Deleted, false, "deleted should be false")
  52. AssertEqual(t, s.Post, "another stream", "post content mismatch")
  53. AssertEqual(t, s.Type, "Post", "Type should be Post")
  54. AssertEqual(t, s.Number, 34, "Number should 34")
  55. AssertEqual(t, s.IsGlobal, false, "is global should be false")
  56. AssertEqual(t, s.CreatedByGender, "", "created by gender should be empty string")
  57. AssertEqual(t, s.IsInternal, false, "is internal should be false")
  58. AssertEqual(t, s.CreateAt, "2017-06-26 02:32:41", "time createdAt mismatch")
  59. AssertEqual(t, s.ModifiedAt, "2017-06-26 02:50:58", "time modifiedAt mismatch")
  60. AssertEqual(t, s.ParentID, "595071f8450974b72", "stream parent id mismatch")
  61. AssertEqual(t, s.ParentType, "Lead", "Parent type should be Lead")
  62. AssertEqual(t, s.ParentName, " \u5218\u5efa\u660e", "parent name should be [ \u5218\u5efa\u660e]")
  63. AssertEqual(t, s.RelatedID, "", "relatedID should be NULL")
  64. AssertEqual(t, s.RelatedType, "", "relatedType should be")
  65. AssertEqual(t, s.AttachmentsIDs[0], "5950769075cd82e67", "attachment id element[0] mismatch")
  66. AssertEqual(t, s.AttachmentsNames["5950769075cd82e67"], "flag_gb.png", "attachmentName mismatch")
  67. AssertEqual(t, s.CreatedByID, "1", "created by ID should be 1")
  68. AssertEqual(t, s.CreatedByName, "Admin", "CreatedBy name should be Admin")
  69. AssertEqual(t, s.ModifiedByID, "1", "modifiedById should be 1")
  70. AssertEqual(t, s.ModifiedByName, "Admin", "Modified By Name should be Admin")
  71. AssertEqual(t, s.SuperParentID, "", "SuperParentID should be empty")
  72. AssertEqual(t, s.SuperParentType, "", "SuperParentType should be empty")
  73. AssertEqual(t, s.AttachmentsTypes["5950769075cd82e67"], "image/png", "attachment mime type not match")
  74. }