|
|
|
|
|
|
|
|
"time" |
|
|
"time" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func TestCreateEntity(t *testing.T) { |
|
|
|
|
|
|
|
|
func TestCrmCreateEntity(t *testing.T) { |
|
|
SetupConfig() |
|
|
SetupConfig() |
|
|
e := crmdLead{} |
|
|
e := crmdLead{} |
|
|
e.FirstName = "ff" + time.Now().Format("2006-jan-02 03:04:05") |
|
|
e.FirstName = "ff" + time.Now().Format("2006-jan-02 03:04:05") |
|
|
|
|
|
|
|
|
b, _ := json.Marshal(e) |
|
|
b, _ := json.Marshal(e) |
|
|
|
|
|
|
|
|
//Create |
|
|
//Create |
|
|
entity, _ := createEntity("Lead", b) |
|
|
|
|
|
|
|
|
entity, _ := crmCreateEntity("Lead", b) |
|
|
lead1, ok := entity.(crmdLead) |
|
|
lead1, ok := entity.(crmdLead) |
|
|
AssertEqual(t, ok, true, "entity type should be crmdLead") |
|
|
AssertEqual(t, ok, true, "entity type should be crmdLead") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Update |
|
|
//Update |
|
|
e.Password = "newpass" |
|
|
e.Password = "newpass" |
|
|
b, _ = json.Marshal(e) |
|
|
b, _ = json.Marshal(e) |
|
|
entity, _ = updateEntity("Lead", lead2.ID, b) |
|
|
|
|
|
|
|
|
entity, _ = crmUpdateEntity("Lead", lead2.ID, b) |
|
|
lead3 := entity.(crmdLead) |
|
|
lead3 := entity.(crmdLead) |
|
|
|
|
|
|
|
|
AssertEqual(t, lead3.ID, lead1.ID, "should be same lead") |
|
|
AssertEqual(t, lead3.ID, lead1.ID, "should be same lead") |
|
|
|
|
|
|
|
|
AssertEqual(t, lead1.Password, "pp", "old password should be PP") |
|
|
AssertEqual(t, lead1.Password, "pp", "old password should be PP") |
|
|
|
|
|
|
|
|
//Delete this test lead. |
|
|
//Delete this test lead. |
|
|
deleted, _ := deleteEntity("Lead", lead1.ID) |
|
|
|
|
|
|
|
|
deleted, _ := crmDeleteEntity("Lead", lead1.ID) |
|
|
AssertEqual(t, deleted, true, "record should be deleted") |
|
|
AssertEqual(t, deleted, true, "record should be deleted") |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
b, _ := json.Marshal(e) |
|
|
b, _ := json.Marshal(e) |
|
|
|
|
|
|
|
|
//create |
|
|
//create |
|
|
entity, _ := createEntity("Lead", b) |
|
|
|
|
|
|
|
|
entity, _ := crmCreateEntity("Lead", b) |
|
|
lead1 := entity.(crmdLead) |
|
|
lead1 := entity.(crmdLead) |
|
|
|
|
|
|
|
|
//Read |
|
|
//Read |
|
|
|
|
|
|
|
|
AssertEqual(t, lead1.ID, lead2.ID, "lead should have been created successfully") |
|
|
AssertEqual(t, lead1.ID, lead2.ID, "lead should have been created successfully") |
|
|
|
|
|
|
|
|
//try to create it again |
|
|
//try to create it again |
|
|
entity, err := createEntity("Lead", b) |
|
|
|
|
|
|
|
|
entity, err := crmCreateEntity("Lead", b) |
|
|
AssertEqual(t, err == nil, false, "should have error for duplicates") |
|
|
AssertEqual(t, err == nil, false, "should have error for duplicates") |
|
|
AssertEqual(t, isErrIndicateDuplicate(err), true, "the err should be duplicate error") |
|
|
AssertEqual(t, isErrIndicateDuplicate(err), true, "the err should be duplicate error") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func TestCreateEntityServerNotFound(t *testing.T) { |
|
|
|
|
|
|
|
|
func TestCrmCreateEntityServerNotFound(t *testing.T) { |
|
|
SetupConfig() |
|
|
SetupConfig() |
|
|
crmSite = "https://not-exist.hitxy.org.au/" // |
|
|
crmSite = "https://not-exist.hitxy.org.au/" // |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
e.Status = "New" |
|
|
e.Status = "New" |
|
|
e.WechatHitxyID = "someopenid" |
|
|
e.WechatHitxyID = "someopenid" |
|
|
b, _ := json.Marshal(e) |
|
|
b, _ := json.Marshal(e) |
|
|
entity, err := createEntity("Lead", b) |
|
|
|
|
|
|
|
|
entity, err := crmCreateEntity("Lead", b) |
|
|
AssertEqual(t, isErrIndicateDuplicate(err), false, "this should not be a duplicate error") |
|
|
AssertEqual(t, isErrIndicateDuplicate(err), false, "this should not be a duplicate error") |
|
|
AssertEqual(t, entity, nil, "should not be able to create entity, it should be nil") |
|
|
AssertEqual(t, entity, nil, "should not be able to create entity, it should be nil") |
|
|
|
|
|
|