Procházet zdrojové kódy

decode crmStream (tested with Lead Entity)

master
Patrick Peng Sun před 8 roky
rodič
revize
0544f01925
2 změnil soubory, kde provedl 162 přidání a 0 odebrání
  1. +85
    -0
      crmLeadStream.go
  2. +77
    -0
      crmLeadStream_test.go

+ 85
- 0
crmLeadStream.go Zobrazit soubor

@@ -0,0 +1,85 @@
package main

// {
// "id": "595072499036b8a52",
// "deleted": false,
// "post": "another stream",
// "data": {},
// "type": "Post",
// "isInternal": false,
// "createdAt": "2017-06-26 02:32:41",
// "modifiedAt": "2017-06-26 02:32:41",
// "parentId": "595071f8450974b72",
// "parentType": "Lead",
// "attachmentsIds": [],
// "createdById": "1"
// }

// {
// "id": "595072499036b8a52",
// "deleted": false,
// "post": "another stream",
// "data": {},
// "type": "Post",
// "targetType": null,
// "number": 34,
// "isGlobal": false,
// "createdByGender": "",
// "isInternal": false,
// "createdAt": "2017-06-26 02:32:41",
// "modifiedAt": "2017-06-26 02:50:58",
// "parentId": "595071f8450974b72",
// "parentType": "Lead",
// "parentName": " \u5218\u5efa\u660e",
// "relatedId": null,
// "relatedType": null,
// "attachmentsIds": [
// "5950769075cd82e67"
// ],
// "attachmentsNames": {
// "5950769075cd82e67": "flag_gb.png"
// },
// "createdById": "1",
// "createdByName": "Admin",
// "modifiedById": "1",
// "modifiedByName": "Admin",
// "superParentId": null,
// "superParentType": null,
// "attachmentsTypes": {
// "5950769075cd82e67": "image\/png"
// }
// }

type crmdStream struct {
ID string `json:"id"`
Deleted bool `json:"deleted"`
Post string `json:"post"`
//Data passed
Type string `json:"type"`
//targetType unknown, why null
Number int `json:"number,omitempty"`
IsGlobal bool `json:"isGlobal,omitempty"`
CreatedByGender string `json:"createdByGender,omitempty"`
IsInternal bool `json:"isInternal"`
CreateAt string `json:"createdAt"`
ModifiedAt string `json:"modifiedAt"`
ParentID string `json:"parentId"`
ParentType string `json:"parentType"`
ParentName string `json:"parentName,omitempty"`
RelatedID string `json:"relatedId,omitempty"`
RelatedType string `json:"relatedType,omitempty"`
AttachmentsIDs []string `json:"attachmentsIds"`
AttachmentsNames map[string]string `json:"attachmentsNames,omitempty"`
AttachmentsTypes map[string]string `json:"attachmentsTypes,omitempty"`
CreatedByID string `json:"createdById"`
CreatedByName string `json:"createdByName,omitempty"`
ModifiedByID string `json:"modifiedById,omitempty"`
ModifiedByName string `json:"modifiedByName,omitempty"`
SuperParentID string `json:"superParentId,omitempty"`
SuperParentType string `json:"superParentType,omitempty"`
}

//add note
func add2Stream() {
//url := "https://c.hitxy.org.au/api/v1/Note"
}

+ 77
- 0
crmLeadStream_test.go Zobrazit soubor

@@ -0,0 +1,77 @@
package main

import (
"encoding/json"
"log"
"testing"
)

func TestDecodeStream(t *testing.T) {
msg := `
{
"id": "595072499036b8a52",
"deleted": false,
"post": "another stream",
"data": {},
"type": "Post",
"targetType": null,
"number": 34,
"isGlobal": false,
"createdByGender": "",
"isInternal": false,
"createdAt": "2017-06-26 02:32:41",
"modifiedAt": "2017-06-26 02:50:58",
"parentId": "595071f8450974b72",
"parentType": "Lead",
"parentName": " \u5218\u5efa\u660e",
"relatedId": null,
"relatedType": null,
"attachmentsIds": [
"5950769075cd82e67"
],
"attachmentsNames": {
"5950769075cd82e67": "flag_gb.png"
},
"createdById": "1",
"createdByName": "Admin",
"modifiedById": "1",
"modifiedByName": "Admin",
"superParentId": null,
"superParentType": null,
"attachmentsTypes": {
"5950769075cd82e67": "image\/png"
}
}
`
s := crmdStream{}
err := json.Unmarshal([]byte(msg), &s)
if err != nil {
log.Println(err)
}
AssertEqual(t, err, nil, "JsonDecode stream error should be nil ")
AssertEqual(t, s.ID, "595072499036b8a52", "stream ID is not correct expect 595072499036b8a52")
AssertEqual(t, s.Deleted, false, "deleted should be false")
AssertEqual(t, s.Post, "another stream", "post content mismatch")
AssertEqual(t, s.Type, "Post", "Type should be Post")
AssertEqual(t, s.Number, 34, "Number should 34")
AssertEqual(t, s.IsGlobal, false, "is global should be false")
AssertEqual(t, s.CreatedByGender, "", "created by gender should be empty string")
AssertEqual(t, s.IsInternal, false, "is internal should be false")
AssertEqual(t, s.CreateAt, "2017-06-26 02:32:41", "time createdAt mismatch")
AssertEqual(t, s.ModifiedAt, "2017-06-26 02:50:58", "time modifiedAt mismatch")
AssertEqual(t, s.ParentID, "595071f8450974b72", "stream parent id mismatch")
AssertEqual(t, s.ParentType, "Lead", "Parent type should be Lead")
AssertEqual(t, s.ParentName, " \u5218\u5efa\u660e", "parent name should be [ \u5218\u5efa\u660e]")
AssertEqual(t, s.RelatedID, "", "relatedID should be NULL")
AssertEqual(t, s.RelatedType, "", "relatedType should be")
AssertEqual(t, s.AttachmentsIDs[0], "5950769075cd82e67", "attachment id element[0] mismatch")
AssertEqual(t, s.AttachmentsNames["5950769075cd82e67"], "flag_gb.png", "attachmentName mismatch")
AssertEqual(t, s.CreatedByID, "1", "created by ID should be 1")
AssertEqual(t, s.CreatedByName, "Admin", "CreatedBy name should be Admin")
AssertEqual(t, s.ModifiedByID, "1", "modifiedById should be 1")
AssertEqual(t, s.ModifiedByName, "Admin", "Modified By Name should be Admin")
AssertEqual(t, s.SuperParentID, "", "SuperParentID should be empty")
AssertEqual(t, s.SuperParentType, "", "SuperParentType should be empty")
AssertEqual(t, s.AttachmentsTypes["5950769075cd82e67"], "image/png", "attachment mime type not match")

}

Načítá se…
Zrušit
Uložit