Skip to content

Commit

Permalink
#9 fix context params / add+improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcossegovia committed Sep 2, 2017
2 parents 04b7feb + b2595e2 commit ff0b357
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 30 deletions.
6 changes: 3 additions & 3 deletions contexts.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import (
)

type Context struct {
Name string `json:"name"`
Lifespan int `json:"lifespan"`
Params map[string]string `json:"parameters"`
Name string `json:"name"`
Lifespan int `json:"lifespan"`
Params map[string]interface{} `json:"parameters"`
}

func (c *ApiClient) GetContexts(sessionId string) ([]Context, error) {
Expand Down
62 changes: 35 additions & 27 deletions contexts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,31 +28,39 @@ func TestGetContexts(t *testing.T) {
{
description: "api ai success, no errors",
responder: httpmock.NewStringResponder(200, `[
{
"name": "Play game",
"parameters": {
"any": "value",
"number": "1"
}
},
{
"name": "Coffee time",
"parameters": {
"temperature": "cold"
}
}
]`),
{
"name": "Play game",
"parameters": {
"any": "value",
"number": 1.5,
"duration": {
"amount": 30.0,
"units": "min"
}
}
},
{
"name": "Coffee time",
"parameters": {
"temperature": "cold"
}
}
]`),
expectedResponse: []Context{
{
Name: "Play game",
Params: map[string]string{
Params: map[string]interface{}{
"any": "value",
"number": "1",
"number": 1.5,
"duration": map[string]interface{}{
"amount": 30.0,
"units": "min",
},
},
},
{
Name: "Coffee time",
Params: map[string]string{
Params: map[string]interface{}{
"temperature": "cold",
},
},
Expand Down Expand Up @@ -98,17 +106,17 @@ func TestGetContext(t *testing.T) {
{
description: "api ai success, no errors",
responder: httpmock.NewStringResponder(200, `{
"name": "Coffee time",
"parameters": {
"type-1": "long",
"type-2": "short",
"temperature-1": "hot",
"temperature-2": "cold"
}
}`),
"name": "Coffee time",
"parameters": {
"type-1": "long",
"type-2": "short",
"temperature-1": "hot",
"temperature-2": "cold"
}
}`),
expectedResponse: &Context{
Name: "Coffee time",
Params: map[string]string{
Params: map[string]interface{}{
"type-1": "long",
"type-2": "short",
"temperature-1": "hot",
Expand Down Expand Up @@ -171,7 +179,7 @@ func TestCreateContext(t *testing.T) {

err := c.CreateContext(Context{
Name: "Coffee time",
Params: map[string]string{
Params: map[string]interface{}{
"type-1": "long",
"type-2": "short",
"temperature-1": "hot",
Expand Down

0 comments on commit ff0b357

Please sign in to comment.