From 8c1f69ef122071c330d479762bd6c5c8f61257b9 Mon Sep 17 00:00:00 2001 From: Patrick Peng Sun Date: Sat, 15 Jul 2017 18:35:25 +1000 Subject: [PATCH] decoding meeting test passed. --- crmMeeting_test.go | 179 ++++++++++++++++++++++++++++++++++ crmdMeeting.go | 40 ++++++++ sample_data/crmd_meeting.json | 105 ++++++++++++++++++++ 3 files changed, 324 insertions(+) create mode 100644 crmMeeting_test.go create mode 100644 crmdMeeting.go create mode 100644 sample_data/crmd_meeting.json diff --git a/crmMeeting_test.go b/crmMeeting_test.go new file mode 100644 index 0000000..e0a7205 --- /dev/null +++ b/crmMeeting_test.go @@ -0,0 +1,179 @@ +package main + +import "testing" +import "encoding/json" + +func TestDecodeMeetingJson(t *testing.T) { + msg := ` + { + "id": "595d064a6e372fc1f", + "name": "testmeting.", + "deleted": false, + "status": "Planned", + "dateStart": "2017-07-05 15:30:00", + "dateEnd": "2017-07-05 19:13:00", + "duration": 13380, + "reminders": [ + { + "seconds": 0, + "type": "Popup" + }, + { + "seconds": 18000, + "type": "Email" + } + ], + "description": "ddaadd", + "createdAt": "2017-07-05 15:31:22", + "modifiedAt": "2017-07-15 07:49:48", + "googleCalendarEventId": null, + "venue": "venue111", + "parentId": "5961bfac40e1b4e69", + "parentType": "Lead", + "parentName": "Anonymous User 127.0.0.1:49261", + "accountId": "aid", + "accountName": "aname", + "usersIds": [ + "1" + ], + "usersNames": { + "1": "Admin" + }, + "usersColumns": { + "1": { + "status": "Accepted" + } + }, + "contactsIds": [ + "595a292e87b0aa3a1" + ], + "contactsNames": { + "595a292e87b0aa3a1": "test name" + }, + "contactsColumns": { + "595a292e87b0aa3a1": { + "status": "None" + } + }, + "leadsIds": [ + "595a921c5032dbfa8", + "595a920924289575a", + "595a91074492662d9", + "595a9105b0d8630ab", + "595a91043fc61b85b", + "595a9102dab66349c" + ], + "leadsNames": { + "595a921c5032dbfa8": " \u9b54\u9053\u5b50", + "595a920924289575a": " HIT", + "595a91074492662d9": " yang", + "595a9105b0d8630ab": " \u5b59\u8fd0\u5377\u5b50", + "595a91043fc61b85b": " Iphy", + "595a9102dab66349c": " \u6668\u516e" + }, + "leadsColumns": { + "595a921c5032dbfa8": { + "status": "None1" + }, + "595a920924289575a": { + "status": "None2" + }, + "595a91074492662d9": { + "status": "None3" + }, + "595a9105b0d8630ab": { + "status": "None4" + }, + "595a91043fc61b85b": { + "status": "None5" + }, + "595a9102dab66349c": { + "status": "None6" + } + }, + "createdById": "1", + "createdByName": "Admin", + "modifiedById": "1", + "modifiedByName": "Admin", + "assignedUserId": "1", + "assignedUserName": "Admin", + "teamsIds": [ + "5958913a2479166db", + "59589145af954bc38" + ], + "teamsNames": { + "5958913a2479166db": "testteam1", + "59589145af954bc38": "testteam2" + }, + "googleCalendarId": null, + "googleCalendarName": null, + "coverId": "coverid", + "coverName": "covername" +} + ` + + e := crmdMeeting{} + err := json.Unmarshal([]byte(msg), &e) + + AssertEqual(t, err, nil, "decode json should be correct") + AssertEqual(t, e.ID, "595d064a6e372fc1f", "ID mismatch") + AssertEqual(t, e.Name, "testmeting.", "name mismatch") + AssertEqual(t, e.Deleted, false, "deleted should be false") + AssertEqual(t, e.DateStart, "2017-07-05 15:30:00", "dataStart wrong") + AssertEqual(t, e.DateEnd, "2017-07-05 19:13:00", "dateEnd wrong") + AssertEqual(t, e.Duration, 13380, "duration should be 13380") + AssertEqual(t, e.Reminders[0].Seconds, 0, "reminder[0] seconds expect 0") + AssertEqual(t, e.Reminders[0].Type, "Popup", "reminder[0] type expect popup") + AssertEqual(t, e.Reminders[1].Seconds, 18000, "reminder[1] seconds expect 18000") + AssertEqual(t, e.Reminders[1].Type, "Email", "reminder[1] type expect email") + AssertEqual(t, e.Description, "ddaadd", "description not right") + AssertEqual(t, e.CreatedAt, "2017-07-05 15:31:22", "createdAt wrong") + AssertEqual(t, e.ModifiedAt, "2017-07-15 07:49:48", "modifiedAt wrong") + AssertEqual(t, e.Venue, "venue111", "venu should be correct") + AssertEqual(t, e.ParentID, "5961bfac40e1b4e69", "parentID mismatch") + AssertEqual(t, e.ParentName, "Anonymous User 127.0.0.1:49261", "parentName mismatch") + AssertEqual(t, e.ParentType, "Lead", "parent type should be Lead") + AssertEqual(t, e.AccountID, "aid", "accountid should be aid") + AssertEqual(t, e.AccountName, "aname", "accountName should be aname") + AssertEqual(t, e.UsersIds[0], "1", "usersIDs[0] should be 1") + AssertEqual(t, e.UsersNames["1"], "Admin", "usersNames[1]!=Admin") + AssertEqual(t, e.UsersColumns["1"].Status, "Accepted", "status should be accepted") + AssertEqual(t, e.ContactsIds[0], "595a292e87b0aa3a1", "contactsids[0] wrong") + AssertEqual(t, e.ContactsNames["595a292e87b0aa3a1"], "test name", "contact name wrong") + AssertEqual(t, e.ContactsColumns["595a292e87b0aa3a1"].Status, "None", "contact status should be none") + + AssertEqual(t, e.LeadsIds[0], "595a921c5032dbfa8", "leadsIDs[0] wrong") + AssertEqual(t, e.LeadsIds[1], "595a920924289575a", "leadsIDs[1] wrong") + AssertEqual(t, e.LeadsIds[2], "595a91074492662d9", "leadsIDs[2] wrong") + AssertEqual(t, e.LeadsIds[3], "595a9105b0d8630ab", "leadsIDs[3] wrong") + AssertEqual(t, e.LeadsIds[4], "595a91043fc61b85b", "leadsIDs[4] wrong") + AssertEqual(t, e.LeadsIds[5], "595a9102dab66349c", "leadsIDs[5] wrong") + + AssertEqual(t, e.LeadsNames["595a921c5032dbfa8"], " \u9b54\u9053\u5b50", "leads[0] name wrong") + AssertEqual(t, e.LeadsNames["595a920924289575a"], " HIT", "leads[1] name wrong") + AssertEqual(t, e.LeadsNames["595a91074492662d9"], " yang", "leads[2] name wrong") + AssertEqual(t, e.LeadsNames["595a9105b0d8630ab"], " \u5b59\u8fd0\u5377\u5b50", "leads[3] name wrong") + AssertEqual(t, e.LeadsNames["595a91043fc61b85b"], " Iphy", "leads[4] name wrong") + AssertEqual(t, e.LeadsNames["595a9102dab66349c"], " \u6668\u516e", "leads[5] name wrong") + + AssertEqual(t, e.LeadsColumns["595a921c5032dbfa8"].Status, "None1", "") + AssertEqual(t, e.LeadsColumns["595a920924289575a"].Status, "None2", "") + AssertEqual(t, e.LeadsColumns["595a91074492662d9"].Status, "None3", "") + AssertEqual(t, e.LeadsColumns["595a9105b0d8630ab"].Status, "None4", "") + AssertEqual(t, e.LeadsColumns["595a91043fc61b85b"].Status, "None5", "") + AssertEqual(t, e.LeadsColumns["595a9102dab66349c"].Status, "None6", "") + + AssertEqual(t, e.CreatedByID, "1", "createdBy id wrong ") + AssertEqual(t, e.CreatedByName, "Admin", "createdByName") + AssertEqual(t, e.ModifiedByID, "1", "modified id !=1") + AssertEqual(t, e.ModifiedByName, "Admin", "modifiedByName wrong") + AssertEqual(t, e.AssignedUserID, "1", "assigned userid != 1") + AssertEqual(t, e.AssignedUserName, "Admin", "assigned name != Admin") + AssertEqual(t, e.TeamsIDs[0], "5958913a2479166db", "team[0] wrong") + AssertEqual(t, e.TeamsIDs[1], "59589145af954bc38", "team[1] wrong") + AssertEqual(t, e.TeamsNames["5958913a2479166db"], "testteam1", "") + AssertEqual(t, e.TeamsNames["59589145af954bc38"], "testteam2", "") + AssertEqual(t, e.CoverID, "coverid", "") + AssertEqual(t, e.CoverName, "covername", "") + +} diff --git a/crmdMeeting.go b/crmdMeeting.go new file mode 100644 index 0000000..b4aca41 --- /dev/null +++ b/crmdMeeting.go @@ -0,0 +1,40 @@ +package main + +type crmdMeetingAttendance struct { + Status string `json:"status,omitempty"` +} + +type crmdMeeting struct { + crmdEntityBase + Status string `json:"status,omitempty"` + DateStart string `json:"dateStart,omitempty"` + DateEnd string `json:"dateEnd,omitempty"` + Duration int `json:"duration,omitempty"` + Reminders []struct { + Seconds int `json:"seconds,omitempty"` + Type string `json:"type,omitempty"` + } `json:"reminders,omitempty"` + Venue string `json:"venue,omitempty"` + ParentID string `json:"parentId,omitempty"` + ParentType string `json:"parentType,omitempty"` + ParentName string `json:"parentName,omitempty"` + + AccountID string `json:"accountId,omitempty"` + AccountName string `json:"accountName,omitempty"` + + //users, attendance + UsersIds []string `json:"usersIds,omitempty"` + UsersNames map[string]string `json:"usersNames,omitempty"` + UsersColumns map[string]crmdMeetingAttendance `json:"usersColumns"` + //contacts, attendance + ContactsIds []string `json:"contactsIds,omitempty"` + ContactsNames map[string]string `json:"contactsNames,omitempty"` + ContactsColumns map[string]crmdMeetingAttendance `json:"contactsColumns,omitempty"` + //lead, attendance + LeadsIds []string `json:"leadsIds,omitempty"` + LeadsNames map[string]string `json:"leadsNames,omitempty"` + LeadsColumns map[string]crmdMeetingAttendance `json:"leadsColumns"` + //cover + CoverID string `json:"coverId,omitempty"` + CoverName string `json:"coverName,omitempty"` +} diff --git a/sample_data/crmd_meeting.json b/sample_data/crmd_meeting.json new file mode 100644 index 0000000..899a67a --- /dev/null +++ b/sample_data/crmd_meeting.json @@ -0,0 +1,105 @@ +{ + "id": "595d064a6e372fc1f", + "name": "testmeting.", + "deleted": false, + "status": "Planned", + "dateStart": "2017-07-05 15:30:00", + "dateEnd": "2017-07-05 19:13:00", + "duration": 13380, + "reminders": [ + { + "seconds": 0, + "type": "Popup" + }, + { + "seconds": 18000, + "type": "Email" + } + ], + "description": "", + "createdAt": "2017-07-05 15:31:22", + "modifiedAt": "2017-07-15 07:49:48", + "googleCalendarEventId": null, + "venue": null, + "parentId": "5961bfac40e1b4e69", + "parentType": "Lead", + "parentName": "Anonymous User 127.0.0.1:49261", + "accountId": null, + "accountName": null, + "usersIds": [ + "1" + ], + "usersNames": { + "1": "Admin" + }, + "usersColumns": { + "1": { + "status": "Accepted" + } + }, + "contactsIds": [ + "595a292e87b0aa3a1" + ], + "contactsNames": { + "595a292e87b0aa3a1": "test name" + }, + "contactsColumns": { + "595a292e87b0aa3a1": { + "status": "None" + } + }, + "leadsIds": [ + "595a921c5032dbfa8", + "595a920924289575a", + "595a91074492662d9", + "595a9105b0d8630ab", + "595a91043fc61b85b", + "595a9102dab66349c" + ], + "leadsNames": { + "595a921c5032dbfa8": " \u9b54\u9053\u5b50", + "595a920924289575a": " HIT", + "595a91074492662d9": " yang", + "595a9105b0d8630ab": " \u5b59\u8fd0\u5377\u5b50", + "595a91043fc61b85b": " Iphy", + "595a9102dab66349c": " \u6668\u516e" + }, + "leadsColumns": { + "595a921c5032dbfa8": { + "status": "None" + }, + "595a920924289575a": { + "status": "None" + }, + "595a91074492662d9": { + "status": "None" + }, + "595a9105b0d8630ab": { + "status": "None" + }, + "595a91043fc61b85b": { + "status": "None" + }, + "595a9102dab66349c": { + "status": "None" + } + }, + "createdById": "1", + "createdByName": "Admin", + "modifiedById": "1", + "modifiedByName": "Admin", + "assignedUserId": "1", + "assignedUserName": "Admin", + "teamsIds": [ + "5958913a2479166db", + "59589145af954bc38" + ], + "teamsNames": { + "5958913a2479166db": "testteam1", + "59589145af954bc38": "testteam2" + }, + "googleCalendarId": null, + "googleCalendarName": null, + "coverId": null, + "coverName": null +} \ No newline at end of file