diff --git a/crmEntity.go b/crmEntity.go index 78a7d57..87dc983 100644 --- a/crmEntity.go +++ b/crmEntity.go @@ -5,10 +5,9 @@ import "encoding/json" import "strings" //abstract CRUD operation for espoCRM Entity -var crmSite = "https://c.hitxy.org.au/" func crmCreateEntity(entityType string, jsonB []byte) (entity interface{}, err error) { - url := crmSite + "api/v1/" + entityType + url := CRMConfig.BaseURL + "api/v1/" + entityType jsonStr, err := postRAW(jsonB, url, crmBuildCommonAPIHeader()) if err != nil { entity, _ = crmRescueDuplicateCreate(err, entityType) @@ -18,7 +17,7 @@ func crmCreateEntity(entityType string, jsonB []byte) (entity interface{}, err e } func crmUpdateEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { - url := crmSite + "api/v1/" + entityType + "/" + id + url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id jsonStr, err := patchRAW(jsonB, url, crmBuildCommonAPIHeader()) if err != nil { log.Println(err) @@ -28,7 +27,7 @@ func crmUpdateEntity(entityType string, id string, jsonB []byte) (entity interfa } func crmReplaceEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { - url := crmSite + "api/v1/" + entityType + "/" + id + url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id jsonStr, err := putRAW(jsonB, url, crmBuildCommonAPIHeader()) if err != nil { log.Println(err) @@ -38,7 +37,7 @@ func crmReplaceEntity(entityType string, id string, jsonB []byte) (entity interf } func crmDeleteEntity(entityType string, id string) (deleted bool, err error) { - url := crmSite + "api/v1/" + entityType + "/" + id + url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id resp, err := deleteRAW(url, crmBuildCommonAPIHeader()) if err != nil { log.Println(err) @@ -50,7 +49,7 @@ func crmDeleteEntity(entityType string, id string) (deleted bool, err error) { //give an id, return json func crmGetEntity(entityType string, id string) (entity interface{}, err error) { - url := crmSite + "api/v1/" + entityType + "/" + id + url := CRMConfig.BaseURL + "api/v1/" + entityType + "/" + id jsonStr, err := getRAW(url, crmBuildCommonAPIHeader()) if err != nil { log.Println(err) diff --git a/crmEntity_test.go b/crmEntity_test.go index 4fc0e41..f8e9f72 100644 --- a/crmEntity_test.go +++ b/crmEntity_test.go @@ -72,9 +72,7 @@ func TestCreateDuplicate(t *testing.T) { } func TestCrmCreateEntityServerNotFound(t *testing.T) { - return SetupConfig() - crmSite = "https://not-exist.hitxy.org.au/" // e := crmdLead{} e.FirstName = "ff" + time.Now().Format("2006-jan-02 03:04:05") @@ -83,7 +81,13 @@ func TestCrmCreateEntityServerNotFound(t *testing.T) { e.Status = "New" e.WechatHitxyID = "someopenid" b, _ := json.Marshal(e) + + //quickly temporarily change base url + oldUrl := CRMConfig.BaseURL + CRMConfig.BaseURL = "https://not-exist.hitxy.org.au/" // entity, err := crmCreateEntity("Lead", b) + CRMConfig.BaseURL = oldUrl + 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")