Преглед изворни кода

added verification to openID and procedure

master
Patrick Peng Sun пре 8 година
родитељ
комит
e92374b938
2 измењених фајлова са 15 додато и 9 уклоњено
  1. +4
    -3
      chatState.go
  2. +11
    -6
      chatState_test.go

+ 4
- 3
chatState.go Прегледај датотеку



//chat state that we might be use for collecting infomation from user //chat state that we might be use for collecting infomation from user
type chatState struct { type chatState struct {
//back pointer style information
//back pointer style information, managed by general process
OpenID string `json:"OpenID"` //whom is this belongs to OpenID string `json:"OpenID"` //whom is this belongs to
Procedure string `json:"Procedure"` //which procedure this belongs to Procedure string `json:"Procedure"` //which procedure this belongs to
Sent bool `json:"Sent"` //whether the message has been sent or not
Received bool `json:"Received"` //whether the expected message has been received or not


//below is managed by individual procedure
//real state information //real state information
Name string `json:"Name"` //state name Name string `json:"Name"` //state name
Expire int32 `json:"Expire"` //unix timestamp when this state expire Expire int32 `json:"Expire"` //unix timestamp when this state expire
Send struct { //anything we need to send? Send struct { //anything we need to send?
Sent bool `json:"Sent"` //whether the message has been sent or not
Type string `json:"Type"` //what type of message Type string `json:"Type"` //what type of message
Message map[string]string `json:"Message"` //the message to be sent,key value pair to describe the message Message map[string]string `json:"Message"` //the message to be sent,key value pair to describe the message
} `json:"Send"` } `json:"Send"`


Receive struct { //anything we expect to receive Receive struct { //anything we expect to receive
Received bool `json:"Received"` //whether the expected message has been received or not
Validator string `json:"Validator"` Validator string `json:"Validator"`
Hint string `json:"Hint"` Hint string `json:"Hint"`
Message map[string]string `json:"Message"` //the description for receiving message Message map[string]string `json:"Message"` //the description for receiving message

+ 11
- 6
chatState_test.go Прегледај датотеку

) )


func TestChatState(t *testing.T) { func TestChatState(t *testing.T) {
openID := "id"
procedure := "getUserBasicProfile" procedure := "getUserBasicProfile"
s := chatState{} s := chatState{}
s.Name = "waiting for username" s.Name = "waiting for username"
s.Expire = int32(time.Now().Unix() + 200) s.Expire = int32(time.Now().Unix() + 200)
s.Send.Message = map[string]string{ s.Send.Message = map[string]string{
"txt": "What is your date of birth?", "txt": "What is your date of birth?",
"icon": "/mnt/data/abc.jpg"}
"icon": "/mnt/data/abc.jpg",
}
s.Send.Type = "text" s.Send.Type = "text"
s.Send.Sent = false
s.Sent = false
s.Received = false
s.Receive.Hint = "hint" s.Receive.Hint = "hint"
s.Receive.Received = false
s.Receive.Validator = "validator email" s.Receive.Validator = "validator email"
s.Receive.Message = map[string]string{ s.Receive.Message = map[string]string{
"rtxt": "should be 3 chars at least", "rtxt": "should be 3 chars at least",
"ricon": "icon path should be available"}
"ricon": "icon path should be available",
}


//save //save
n, err := setCurrentState("id", procedure, s) n, err := setCurrentState("id", procedure, s)
AssertEqual(t, m.Name, n.Name, "Name should be equal") AssertEqual(t, m.Name, n.Name, "Name should be equal")
AssertEqual(t, m.Expire, n.Expire, "Expire should be equal") AssertEqual(t, m.Expire, n.Expire, "Expire should be equal")
AssertEqual(t, m.Send.Type, n.Send.Type, "Send.Type should be equal") AssertEqual(t, m.Send.Type, n.Send.Type, "Send.Type should be equal")
AssertEqual(t, m.Receive.Received, false, "Receive.Received should be false")
AssertEqual(t, m.Send.Sent, false, "Send.Sent should be false")
AssertEqual(t, m.Received, false, "Receive.Received should be false")
AssertEqual(t, m.Sent, false, "Send.Sent should be false")
AssertEqual(t, m.OpenID, openID, "openID should be "+openID)
AssertEqual(t, m.Procedure, procedure, "procedure should be "+procedure)
AssertEqual(t, m.Send.Message["txt"], n.Send.Message["txt"], "Message[txt] should be equal") AssertEqual(t, m.Send.Message["txt"], n.Send.Message["txt"], "Message[txt] should be equal")
AssertEqual(t, m.Send.Message["icon"], n.Send.Message["icon"], "Message[icon] should be equal") AssertEqual(t, m.Send.Message["icon"], n.Send.Message["icon"], "Message[icon] should be equal")
AssertEqual(t, m.Receive.Message["rtxt"], n.Receive.Message["rtxt"], "Message[rtxt] should be equal") AssertEqual(t, m.Receive.Message["rtxt"], n.Receive.Message["rtxt"], "Message[rtxt] should be equal")

Loading…
Откажи
Сачувај