Просмотр исходного кода

search by attribute tested.

master
Patrick Peng Sun 8 лет назад
Родитель
Сommit
dc652aac3c
2 измененных файлов: 59 добавлений и 2 удалений
  1. +24
    -2
      crmEntity.go
  2. +35
    -0
      crmEntity_test.go

+ 24
- 2
crmEntity.go Просмотреть файл



req.URL.RawQuery = q.Encode() req.URL.RawQuery = q.Encode()


debugDumpHTTPRequest(req)
//debugDumpHTTPRequest(req)


client := &http.Client{} client := &http.Client{}
r, err := client.Do(req) r, err := client.Do(req)


debugDumpHTTPResponse(r)
//debugDumpHTTPResponse(r)


if err != nil { if err != nil {
return return
} }
return return
} }

func crmFindEntityByAttr(entityType, attribute, value string) (total int, list interface{}, err error) {
filters := []crmdSearchFilter{
{attribute, "equals", value},
}

cs, err := crmSearchEntity(entityType, filters)
if err != nil || cs.Total < 1 {
return
}
total = cs.Total
switch entityType {
case "Lead":
e := []crmdLead{}
err = json.Unmarshal(*cs.List, &e)
list = e
case "Account":
return

}
return
}

+ 35
- 0
crmEntity_test.go Просмотреть файл



import ( import (
"encoding/json" "encoding/json"
"fmt"
"log" "log"
"testing" "testing"
"time" "time"
AssertEqual(t, deleted, false, "deleting non-exist record should be false") AssertEqual(t, deleted, false, "deleting non-exist record should be false")


} }

func TestSearchByAttr(t *testing.T) {
ids := []string{}

for i := 0; i < 10; i++ {
e := crmdLead{}
e.FirstName = fmt.Sprintf("%s-%d-%s", "ff", i, time.Now().Format("2006-Jan-02 03:04:05"))
e.LastName = fmt.Sprintf("%s-%d", "ll", i)
e.Password = fmt.Sprintf("%s-pp-%d", "pp", i)
e.Status = "New"
e.EmailAddress = fmt.Sprintf("abc%d@gmail.com", i)
e.WechatHitxyID = fmt.Sprintf("someopenid-%d", i)
b, _ := json.Marshal(e)
entity, _ := crmCreateEntity("Lead", b)
ids = append(ids, entity.(crmdLead).ID)
log.Printf("creating %s", ids[i])
}

//search
for i := 0; i < 10; i++ {
log.Printf("trying to match %d , %s", i, ids[i])
total, list, err := crmFindEntityByAttr("Lead", "emailAddress", fmt.Sprintf("abc%d@gmail.com", i))
result := list.([]crmdLead)
AssertEqual(t, err, nil, "find by attr should have no error")
AssertEqual(t, total, 1, "should have found 1 and only 1")
AssertEqual(t, len(result), 1, "list should be 1 ")
AssertEqual(t, result[0].ID, ids[i], "the id should be correct.")
}

for i := 0; i < 10; i++ {
crmDeleteEntity("Lead", ids[i])
log.Printf("deleting %s", ids[i])
}
}

Загрузка…
Отмена
Сохранить