Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

crmEntitySubscribe_test.go 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package main
  2. import (
  3. "encoding/json"
  4. "testing"
  5. )
  6. func TestDecodeSubscribed(t *testing.T) {
  7. msg := `
  8. {
  9. "id": "5958874da01cc362f",
  10. "name": "somename",
  11. "deleted": false,
  12. "description": null,
  13. "createdAt": "2017-07-02 05:40:29",
  14. "modifiedAt": "2017-07-02 06:23:20",
  15. "openID": "someidea2",
  16. "createdById": "1",
  17. "createdByName": "Admin",
  18. "modifiedById": "1",
  19. "modifiedByName": "Admin",
  20. "assignedUserId": "1",
  21. "assignedUserName": "Admin",
  22. "subscribed": false,
  23. "teamsIds": [
  24. "5958913a2479166db",
  25. "59589145af954bc38"
  26. ],
  27. "teamsNames": {
  28. "5958913a2479166db": "testteam1",
  29. "59589145af954bc38": "testteam2"
  30. }
  31. }`
  32. e := crmdSubscribe{}
  33. err := json.Unmarshal([]byte(msg), &e)
  34. AssertEqual(t, err, nil, "decode json entity should be nil")
  35. AssertEqual(t, e.ID, "5958874da01cc362f", "")
  36. AssertEqual(t, e.Deleted, false, "")
  37. AssertEqual(t, e.Description, "", "")
  38. AssertEqual(t, e.CreatedAt, "2017-07-02 05:40:29", "")
  39. AssertEqual(t, e.ModifiedAt, "2017-07-02 06:23:20", "")
  40. AssertEqual(t, e.OpenID, "someidea2", "") /// special field
  41. AssertEqual(t, e.Subscribed, false, "") /// special field
  42. AssertEqual(t, e.CreatedByID, "1", "")
  43. AssertEqual(t, e.CreatedByName, "Admin", "")
  44. AssertEqual(t, e.ModifiedByID, "1", "")
  45. AssertEqual(t, e.ModifiedByName, "Admin", "")
  46. AssertEqual(t, e.AssignedUserID, "1", "")
  47. AssertEqual(t, e.AssignedUserName, "Admin", "")
  48. AssertEqual(t, e.TeamsIDs[0], "5958913a2479166db", "")
  49. AssertEqual(t, e.TeamsIDs[1], "59589145af954bc38", "")
  50. AssertEqual(t, e.TeamsNames["5958913a2479166db"], "testteam1", "")
  51. AssertEqual(t, e.TeamsNames["59589145af954bc38"], "testteam2", "")
  52. //test createAt function
  53. AssertEqual(t, e.getCreatedAt().Format(getCrmTimeLayout()), e.CreatedAt, "time formating should be correct")
  54. AssertEqual(t, e.getModifiedAt().Format(getCrmTimeLayout()), e.ModifiedAt, "time formating should be correct")
  55. }