| import ( | import ( | ||||
| "encoding/json" | "encoding/json" | ||||
| "log" | |||||
| "testing" | "testing" | ||||
| "time" | "time" | ||||
| ) | ) | ||||
| e.FirstName = "ff" + time.Now().Format("2006-jan-02 03:04:05") | e.FirstName = "ff" + time.Now().Format("2006-jan-02 03:04:05") | ||||
| e.LastName = "ll" | e.LastName = "ll" | ||||
| e.Password = "pp" | e.Password = "pp" | ||||
| e.EmailAddress = "abc@gmail.com" | |||||
| e.Status = "New" | e.Status = "New" | ||||
| e.WechatHitxyID = "someopenid" | e.WechatHitxyID = "someopenid" | ||||
| b, _ := json.Marshal(e) | b, _ := json.Marshal(e) | ||||
| } | } | ||||
| func TestCrmCreateEntityServerNotFound(t *testing.T) { | func TestCrmCreateEntityServerNotFound(t *testing.T) { | ||||
| return | |||||
| SetupConfig() | SetupConfig() | ||||
| crmSite = "https://not-exist.hitxy.org.au/" // | crmSite = "https://not-exist.hitxy.org.au/" // | ||||
| func TestCrmReplaceEntity(t *testing.T) { | func TestCrmReplaceEntity(t *testing.T) { | ||||
| SetupConfig() | SetupConfig() | ||||
| e := crmdLead{} | e := crmdLead{} | ||||
| e.FirstName = "ff" + time.Now().Format("2006-jan-02 03:04:05") | |||||
| e.LastName = "ll" | |||||
| e.FirstName = "ff1" + time.Now().Format("2006-jan-02 03:04:05") | |||||
| e.LastName = "ll1" | |||||
| e.Password = "pp" | e.Password = "pp" | ||||
| e.Status = "New" | e.Status = "New" | ||||
| e.EmailAddress = "abc@gmail.com" | |||||
| e.WechatHitxyID = "someopenid" | e.WechatHitxyID = "someopenid" | ||||
| b, _ := json.Marshal(e) | b, _ := json.Marshal(e) | ||||
| entity, err := crmCreateEntity("Lead", b) | entity, err := crmCreateEntity("Lead", b) | ||||
| if err != nil { | |||||
| log.Println("--------------") | |||||
| log.Println(err) | |||||
| log.Println("--------------") | |||||
| } | |||||
| AssertEqual(t, err, nil, "create record should be successful") | |||||
| AssertEqual(t, isErrIndicateDuplicate(err), false, "this should not be a duplicate error") | AssertEqual(t, isErrIndicateDuplicate(err), false, "this should not be a duplicate error") | ||||
| id := entity.(crmdLead).ID | id := entity.(crmdLead).ID | ||||
| AssertEqual(t, err, nil, "put should have no error") | AssertEqual(t, err, nil, "put should have no error") | ||||
| AssertEqual(t, entity.(crmdLead).WechatHitxyID, "newid", "wechat_hitxy_id should be updated") | AssertEqual(t, entity.(crmdLead).WechatHitxyID, "newid", "wechat_hitxy_id should be updated") | ||||
| AssertEqual(t, entity.(crmdLead).Password, "newpass", "password should have been changed to newpass") | AssertEqual(t, entity.(crmdLead).Password, "newpass", "password should have been changed to newpass") | ||||
| return | |||||
| //delete | |||||
| deleted, _ := crmDeleteEntity("Lead", id) | |||||
| AssertEqual(t, deleted, true, "test record should have been deleted.") | |||||
| } | } |