Selaa lähdekoodia

added verification to openID and procedure

master
Patrick Peng Sun 8 vuotta sitten
vanhempi
commit
e92374b938
2 muutettua tiedostoa jossa 15 lisäystä ja 9 poistoa
  1. +4
    -3
      chatState.go
  2. +11
    -6
      chatState_test.go

+ 4
- 3
chatState.go Näytä tiedosto

@@ -11,21 +11,22 @@ import (

//chat state that we might be use for collecting infomation from user
type chatState struct {
//back pointer style information
//back pointer style information, managed by general process
OpenID string `json:"OpenID"` //whom is 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
Name string `json:"Name"` //state name
Expire int32 `json:"Expire"` //unix timestamp when this state expire
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
Message map[string]string `json:"Message"` //the message to be sent,key value pair to describe the message
} `json:"Send"`

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

+ 11
- 6
chatState_test.go Näytä tiedosto

@@ -6,21 +6,24 @@ import (
)

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

//save
n, err := setCurrentState("id", procedure, s)
@@ -33,8 +36,10 @@ func TestChatState(t *testing.T) {
AssertEqual(t, m.Name, n.Name, "Name 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.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["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")

Loading…
Peruuta
Tallenna