-
Notifications
You must be signed in to change notification settings - Fork 1
/
parse_test.go
132 lines (122 loc) · 2.54 KB
/
parse_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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package parse
import (
"fmt"
"math/rand"
"testing"
"time"
)
var parseClient = NewClient()
func init() {
parseClient.AppId = ""
parseClient.AppKey = ""
parseClient.DebugRequest = true
rand.Seed(time.Now().UnixNano())
}
func randString() string {
return fmt.Sprintf("abc%d", rand.Int())
}
func TestObject(t *testing.T) {
className := "TestClass"
o1 := NewObject()
o1.Set("key", "value")
err := o1.Save(parseClient, className, true)
if err != nil {
t.Fatal(err)
}
if o1.ObjectId() == "" {
t.Fatal("null objectId")
}
o1.Set("updatekey", "updatevalue")
err = o1.Update(parseClient, className)
if err != nil {
t.Fatal(err)
}
o2, err := FetchObject(parseClient, className, o1.ObjectId(), "")
if err != nil {
t.Fatal(err)
}
err = o2.Delete(parseClient, className)
if err != nil {
t.Fatal(err)
}
}
func TestDate(t *testing.T) {
className := "TestClass"
o1 := NewObject()
d := FormatDate(time.Now())
o1.Set("keydate", d)
err := o1.Save(parseClient, className, true)
if err != nil {
t.Fatal(err)
}
err = o1.Delete(parseClient, className)
if err != nil {
t.Fatal(err)
}
}
func TestUser(t *testing.T) {
u1 := NewUser()
email := fmt.Sprintf("%[email protected]", randString())
phone := fmt.Sprintf("1386818%0d%0d", rand.Intn(99), rand.Intn(99))
t.Log(phone)
username := randString()
password := "password"
r1, err := u1.Register(parseClient, username, password, email, phone)
if err != nil {
t.Fatal(r1, err)
}
r2, err := u1.Login(parseClient, username, password)
if err != nil {
t.Fatal(r2, err)
}
}
func TestCloudFunction(t *testing.T) {
//param := parse.NewParams()
//param["key"] = "value"
//r, err := CallFunction(parseClient, "functionName", param.Encode())
//if err != nil {
//t.Fatal(err, r)
//}
}
func TestQueryObjectsBasic(t *testing.T) {
opt := QueryOptions{
Class: "PS",
Limit: DefaultLimit,
Skip: 0,
Order: "-createdAt'",
Keys: "",
Include: "",
Count: false,
}
r, err := QueryObjects(parseClient, opt)
if err != nil {
t.Fatal(err)
}
objs, _ := r.GetResults()
for _, o := range objs {
t.Log(o.ObjectId())
}
}
func TestQueryObjectsWhere(t *testing.T) {
where := NewWhere()
where.AddEqualTo("objectId", "abcd")
where.Add("someKey", OpLessThanOrEqualTo, 100)
opt := QueryOptions{
Class: "PS",
Limit: DefaultLimit,
Skip: 0,
Order: "-createdAt'",
Keys: "",
Include: "",
Count: false,
Where: where,
}
r, err := QueryObjects(parseClient, opt)
if err != nil {
t.Fatal(err)
}
objs, _ := r.GetResults()
for _, o := range objs {
t.Log(o.ObjectId())
}
}