package main

import "testing"
import "encoding/json"

func TestXStatusReason(t *testing.T) {
	msg := `{"reason":"Duplicate","data":{"5960f0bd705b46936":{"id":"5960f0bd705b46936","name":"Anonymous User","deleted":false,"salutationName":null,"firstName":"Anonymous","lastName":"User","title":null,"status":"Anonymous","source":"","industry":"","opportunityAmount":null,"website":null,"addressStreet":null,"addressCity":null,"addressState":null,"addressCountry":null,"addressPostalCode":null,"emailAddress":null,"phoneNumber":null,"doNotCall":false,"description":"","createdAt":"2017-07-08 14:48:29","modifiedAt":"2017-07-08 14:48:29","accountName":null,"password":"Password","wechatOpenID":null,"opportunityAmountCurrency":null,"opportunityAmountConverted":null,"createdById":"58ef420cac3cf6c95","createdByName":"wechat robot","modifiedById":null,"modifiedByName":null,"assignedUserId":null,"assignedUserName":null,"campaignId":null,"createdAccountId":null,"createdContactId":null,"createdOpportunityId":null,"avatarId":null,"avatarName":null}}}`
	reason := crmdReason{}
	err := json.Unmarshal([]byte(msg), &reason)
	AssertEqual(t, err, nil, "")

	entity, err := reason.Data2Entity("Lead")
	lead, ok := entity.(crmdLead)

	AssertEqual(t, ok, true, "")
	AssertEqual(t, err, nil, "Data2Entity should have no error")
	AssertEqual(t, lead.ID, "5960f0bd705b46936", "recovered lead should have correct ID")
}
