diff --git a/crmEntityBase.go b/crmEntityBase.go new file mode 100644 index 0000000..98b2ba1 --- /dev/null +++ b/crmEntityBase.go @@ -0,0 +1,18 @@ +package main + +type crmdEntityBase struct { + AssignedUserID string `json:"assignedUserId,omitempty"` + AssignedUserName string `json:"assignedUsername,omitempty"` + CreatedAt string `json:"createdAt,omitempty"` + CreatedByID string `json:"createdById,omitempty"` + CreatedByName string `json:"createdByName,omitempty"` + Deleted bool `json:"deleted,omitempty"` + Description string `json:"description"` + ID string `json:"id,omitempty"` + ModifiedAt string `json:"modifiedAt,omitempty"` + ModifiedByID string `json:"modifiedById,omitempty"` + ModifiedByName string `json:"modifiedByName,omitempty"` + Name string `json:"name,omitEmpty"` + TeamsIDs []string `json:"teamsIds,omitempty"` + TeamsNames map[string]string `json:"teamsNames,omitEmpty"` +} diff --git a/crmEntityBase_test.go b/crmEntityBase_test.go new file mode 100644 index 0000000..c125073 --- /dev/null +++ b/crmEntityBase_test.go @@ -0,0 +1,51 @@ +package main + +import "testing" +import "encoding/json" + +func TestDecodeCrmEntityBaseJson(t *testing.T) { + msg := ` + { + "id": "5958874da01cc362f", + "name": "somename", + "deleted": false, + "description": null, + "createdAt": "2017-07-02 05:40:29", + "modifiedAt": "2017-07-02 06:23:20", + "openID": "someidea2", + "createdById": "1", + "createdByName": "Admin", + "modifiedById": "1", + "modifiedByName": "Admin", + "assignedUserId": "1", + "assignedUserName": "Admin", + "teamsIds": [ + "5958913a2479166db", + "59589145af954bc38" + ], + "teamsNames": { + "5958913a2479166db": "testteam1", + "59589145af954bc38": "testteam2" + } + }` + + e := crmdEntityBase{} + err := json.Unmarshal([]byte(msg), &e) + AssertEqual(t, err, nil, "decode json entity should be nil") + AssertEqual(t, e.ID, "5958874da01cc362f", "") + AssertEqual(t, e.Deleted, false, "") + AssertEqual(t, e.Description, "", "") + AssertEqual(t, e.CreatedAt, "2017-07-02 05:40:29", "") + AssertEqual(t, e.ModifiedAt, "2017-07-02 06:23:20", "") + //AssertEqual(t, e.OpenID, "someidea2", "") + AssertEqual(t, e.CreatedByID, "1", "") + AssertEqual(t, e.CreatedByName, "Admin", "") + AssertEqual(t, e.ModifiedByID, "1", "") + AssertEqual(t, e.ModifiedByName, "Admin", "") + AssertEqual(t, e.AssignedUserID, "1", "") + AssertEqual(t, e.AssignedUserName, "Admin", "") + AssertEqual(t, e.TeamsIDs[0], "5958913a2479166db", "") + AssertEqual(t, e.TeamsIDs[1], "59589145af954bc38", "") + AssertEqual(t, e.TeamsNames["5958913a2479166db"], "testteam1", "") + AssertEqual(t, e.TeamsNames["59589145af954bc38"], "testteam2", "") +} diff --git a/sample_data/crm_entity_subscribe.json b/sample_data/crm_entity_subscribe.json new file mode 100644 index 0000000..a4b3b22 --- /dev/null +++ b/sample_data/crm_entity_subscribe.json @@ -0,0 +1,23 @@ +{ + "id": "5958874da01cc362f", + "name": "somename", + "deleted": false, + "description": null, + "createdAt": "2017-07-02 05:40:29", + "modifiedAt": "2017-07-02 06:23:20", + "openID": "someidea2", + "createdById": "1", + "createdByName": "Admin", + "modifiedById": "1", + "modifiedByName": "Admin", + "assignedUserId": "1", + "assignedUserName": "Admin", + "teamsIds": [ + "5958913a2479166db", + "59589145af954bc38" + ], + "teamsNames": { + "5958913a2479166db": "testteam1", + "59589145af954bc38": "testteam2" + } +} \ No newline at end of file