Przeglądaj źródła

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 lat temu
rodzic
commit
77a8bb4355
2 zmienionych plików z 11 dodań i 8 usunięć
  1. +5
    -6
      crmEntity.go
  2. +6
    -2
      crmEntity_test.go

+ 5
- 6
crmEntity.go Wyświetl plik

import "strings" import "strings"


//abstract CRUD operation for espoCRM Entity //abstract CRUD operation for espoCRM Entity
var crmSite = "https://c.hitxy.org.au/"


func crmCreateEntity(entityType string, jsonB []byte) (entity interface{}, err error) { 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()) jsonStr, err := postRAW(jsonB, url, crmBuildCommonAPIHeader())
if err != nil { if err != nil {
entity, _ = crmRescueDuplicateCreate(err, entityType) entity, _ = crmRescueDuplicateCreate(err, entityType)
} }


func crmUpdateEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { 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()) jsonStr, err := patchRAW(jsonB, url, crmBuildCommonAPIHeader())
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }


func crmReplaceEntity(entityType string, id string, jsonB []byte) (entity interface{}, err error) { 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()) jsonStr, err := putRAW(jsonB, url, crmBuildCommonAPIHeader())
if err != nil { if err != nil {
log.Println(err) log.Println(err)
} }


func crmDeleteEntity(entityType string, id string) (deleted bool, err error) { 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()) resp, err := deleteRAW(url, crmBuildCommonAPIHeader())
if err != nil { if err != nil {
log.Println(err) log.Println(err)


//give an id, return json //give an id, return json
func crmGetEntity(entityType string, id string) (entity interface{}, err error) { 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()) jsonStr, err := getRAW(url, crmBuildCommonAPIHeader())
if err != nil { if err != nil {
log.Println(err) log.Println(err)

+ 6
- 2
crmEntity_test.go Wyświetl plik

} }


func TestCrmCreateEntityServerNotFound(t *testing.T) { func TestCrmCreateEntityServerNotFound(t *testing.T) {
return
SetupConfig() SetupConfig()
crmSite = "https://not-exist.hitxy.org.au/" //


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")
e.Status = "New" e.Status = "New"
e.WechatHitxyID = "someopenid" e.WechatHitxyID = "someopenid"
b, _ := json.Marshal(e) 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) entity, err := crmCreateEntity("Lead", b)
CRMConfig.BaseURL = oldUrl

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



Ładowanie…
Anuluj
Zapisz