소스 검색

test case remove hardcode Get with specific lead ID

master
Patrick Peng Sun 8 년 전
부모
커밋
93c688dc7d
1개의 변경된 파일13개의 추가작업 그리고 21개의 파일을 삭제
  1. +13
    -21
      crmEntity_test.go

+ 13
- 21
crmEntity_test.go 파일 보기

@@ -2,25 +2,10 @@ package main

import (
"encoding/json"
"log"
"testing"
"time"
)

func TestGetEntity(t *testing.T) {
SetupConfig()
leadID := "595071f8450974b72"
entity, err := crmGetEntity("Lead", leadID)
AssertEqual(t, err, nil, "get entity should return nil error")

lead, ok := entity.(crmdLead)
AssertEqual(t, ok, true, "type assertion should be true")
AssertEqual(t, leadID, lead.ID, "lead id mismatch")

lead1 := entity.(crmdLead)
AssertEqual(t, lead.ID, lead1.ID, "type casting should work")
}

func TestCreateEntity(t *testing.T) {
SetupConfig()
e := crmdLead{}
@@ -29,24 +14,27 @@ func TestCreateEntity(t *testing.T) {
e.Password = "pp"
e.Status = "New"
b, _ := json.Marshal(e)
log.Println(string(b))

//Create
entity, _ := createEntity("Lead", b)
lead1 := entity.(crmdLead)
log.Println(lead1)
lead1, ok := entity.(crmdLead)
AssertEqual(t, ok, true, "entity type should be crmdLead")

//Read
lead2, _ := crmGetLead(lead1.ID)
AssertEqual(t, lead2.ID, lead1.ID, "lead id should be equal")

//Update
e.Password = "newpass"
b, _ = json.Marshal(e)
entity, _ = updateEntity("Lead", lead2.ID, b)
lead3 := entity.(crmdLead)
log.Println(lead3)
AssertEqual(t, lead3.ID, lead1.ID, "should be same lead")
AssertEqual(t, lead3.Password, "newpass", "password should have been changed")
AssertEqual(t, lead1.Password, "pp", "old password should be PP")

//delete this test lead.
//Delete this test lead.
deleted, _ := deleteEntity("Lead", lead1.ID)
AssertEqual(t, deleted, true, "record should be deleted")

@@ -61,8 +49,12 @@ func TestCreateDuplicate(t *testing.T) {
e.Status = "New"
e.WechatHitxyID = "someopenid"
b, _ := json.Marshal(e)

//create
entity, _ := createEntity("Lead", b)
lead1 := entity.(crmdLead)

//Read
entity, _ = crmGetEntity("Lead", lead1.ID)
lead2 := entity.(crmdLead)
AssertEqual(t, lead1.ID, lead2.ID, "lead should have been created successfully")
@@ -70,7 +62,7 @@ func TestCreateDuplicate(t *testing.T) {
//try to create it again
entity, err := createEntity("Lead", b)
AssertEqual(t, err == nil, false, "should have error for duplicates")
AssertEqual(t, isErrIndicateDuplicate(err), true, "this should be duplicate error")
AssertEqual(t, isErrIndicateDuplicate(err), true, "the err should be duplicate error")
}

func TestCreateEntityServerNotFound(t *testing.T) {

Loading…
취소
저장