Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

88 lines
3.2KB

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