Sfoglia il codice sorgente

crmSite using global config. change global config should be restored and should be quickly as much as possible.

there is still a  chance for 'non-exist' global config sneak into other tests.
master
Patrick Peng Sun 8 anni fa
parent
commit
77a8bb4355
2 ha cambiato i file con 11 aggiunte e 8 eliminazioni
  1. +5
    -6
      crmEntity.go
  2. +6
    -2
      crmEntity_test.go

+ 5
- 6
crmEntity.go Vedi File

@@ -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)

+ 6
- 2
crmEntity_test.go Vedi File

@@ -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")


Loading…
Annulla
Salva