-
Notifications
You must be signed in to change notification settings - Fork 18
/
intents_test.go
70 lines (62 loc) · 1.59 KB
/
intents_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright (c) 2014 Jason Goecke
// intents_test.go
package wit
import (
//"os"
"testing"
)
func TestWitIntentsParsing(t *testing.T) {
data := `
[ {
"id" : "1234",
"name" : "recover_password",
"doc" : "Recover password (which is different from Reset password).",
"metadata" : "password_23433253254"
}, {
"id" : "52bab833-9a1e-4bff-b659-99ee95e6c1f9",
"name" : "transfer",
"doc" : "Transfer some amount of money between two accounts."
}, {
"id" : "52bab833-3e23-4c67-9cfc-a0fed605bd77",
"name" : "show_movie",
"doc" : "Show a given movie."
} ]`
intents, err := parseIntents([]byte(data))
if err != nil {
t.Error(err.Error())
}
for cnt, intent := range *intents {
switch cnt {
case 0:
if intent.ID != "1234" {
t.Error("Intents JSON did not parse properly.")
}
case 1:
if intent.Name != "transfer" {
t.Error("Intents JSON did not parse properly.")
}
case 2:
if intent.Doc != "Show a given movie." {
t.Error("Intents JSON did not parse properly.")
}
}
}
}
// temporary: the "good_bye" intent is not added to new instances anymore.
// Wit.AI will soon add a POST /intent endpoint to add new intents, uncomment this test then.
// func TestWitIntents(t *testing.T) {
// client := NewClient(os.Getenv("WIT_ACCESS_TOKEN"))
// intents, err := client.Intents()
// if err != nil {
// t.Error("Did not fetch intents properly")
// }
// goodBye := false
// for _, value := range *intents {
// if value.Name == "good_bye" {
// goodBye = true
// }
// }
// if goodBye != true {
// t.Error("Intents returned not expected")
// }
// }