-
Notifications
You must be signed in to change notification settings - Fork 1
/
querybuilder_test.go
97 lines (84 loc) · 2.43 KB
/
querybuilder_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
package redkeep_test
import (
. "github.com/manyminds/redkeep"
"gopkg.in/mgo.v2/bson"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Querybuilder tests", func() {
Context("Validate queries", func() {
var (
w Watch
)
BeforeEach(func() {
w = Watch{
TrackFields: []string{"username", "name", "invalid"},
TargetNormalizedField: "norm",
}
})
It("will generate simple updates correctly", func() {
command := map[string]interface{}{
"$set": map[string]interface{}{
"username": "nino",
},
}
expected := bson.M{"$set": bson.M{"norm.username": "nino"}}
actual := BuildUpdateQuery(w, command)
Expect(actual).To(Equal(expected))
})
It("will generate update only whitelisted fields", func() {
command := map[string]interface{}{
"$set": map[string]interface{}{
"username": "nino",
"otherField": "A",
},
}
expected := bson.M{"$set": bson.M{"norm.username": "nino"}}
actual := BuildUpdateQuery(w, command)
Expect(actual).To(Equal(expected))
})
/*
*
* It("whitelist only subset", func() {
* command := map[string]interface{}{
* "$set": map[string]interface{}{
* "oauth": map[string]interface{}{
* "userdata": map[string]interface{}{
* "name": map[string]interface{}{
* "firstName": "Naan",
* "lastName": "Waana",
* },
* },
* },
* },
* }
*
* expected := bson.M{"$set": bson.M{"norm.name": map[string]interface{}{"firstName": "nino"}}}
* actual := BuildUpdateQuery(w, command)
* Expect(actual).To(Equal(expected))
* })
*/
It("will generate nested updates correctly", func() {
command := map[string]interface{}{
"$set": map[string]interface{}{
"name": map[string]interface{}{
"firstName": "nino",
},
},
}
expected := bson.M{"$set": bson.M{"norm.name": map[string]interface{}{"firstName": "nino"}}}
actual := BuildUpdateQuery(w, command)
Expect(actual).To(Equal(expected))
})
It("will generate nested big updates correctly", func() {
command := map[string]interface{}{
"$set": map[string]interface{}{
"name.firstName": "nino",
},
}
expected := bson.M{"$set": bson.M{"norm.name.firstName": "nino"}}
actual := BuildUpdateQuery(w, command)
Expect(actual).To(Equal(expected))
})
})
})