-
Notifications
You must be signed in to change notification settings - Fork 89
/
properties_test.go
71 lines (63 loc) · 2.64 KB
/
properties_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
package analytics
import (
"reflect"
"testing"
)
func TestPropertiesSimple(t *testing.T) {
text := "ABC"
number := 0.5
products := []Product{
Product{
ID: "1",
SKU: "1",
Name: "A",
Price: 42.0,
},
Product{
ID: "2",
SKU: "2",
Name: "B",
Price: 100.0,
},
}
tests := map[string]struct {
ref Properties
run func(Properties)
}{
"revenue": {Properties{"revenue": number}, func(p Properties) { p.SetRevenue(number) }},
"currency": {Properties{"currency": text}, func(p Properties) { p.SetCurrency(text) }},
"value": {Properties{"value": number}, func(p Properties) { p.SetValue(number) }},
"path": {Properties{"path": text}, func(p Properties) { p.SetPath(text) }},
"referrer": {Properties{"referrer": text}, func(p Properties) { p.SetReferrer(text) }},
"title": {Properties{"title": text}, func(p Properties) { p.SetTitle(text) }},
"url": {Properties{"url": text}, func(p Properties) { p.SetURL(text) }},
"name": {Properties{"name": text}, func(p Properties) { p.SetName(text) }},
"category": {Properties{"category": text}, func(p Properties) { p.SetCategory(text) }},
"sku": {Properties{"sku": text}, func(p Properties) { p.SetSKU(text) }},
"price": {Properties{"price": number}, func(p Properties) { p.SetPrice(number) }},
"id": {Properties{"id": text}, func(p Properties) { p.SetProductId(text) }},
"orderId": {Properties{"orderId": text}, func(p Properties) { p.SetOrderId(text) }},
"total": {Properties{"total": number}, func(p Properties) { p.SetTotal(number) }},
"subtotal": {Properties{"subtotal": number}, func(p Properties) { p.SetSubtotal(number) }},
"shipping": {Properties{"shipping": number}, func(p Properties) { p.SetShipping(number) }},
"tax": {Properties{"tax": number}, func(p Properties) { p.SetTax(number) }},
"discount": {Properties{"discount": number}, func(p Properties) { p.SetDiscount(number) }},
"coupon": {Properties{"coupon": text}, func(p Properties) { p.SetCoupon(text) }},
"products": {Properties{"products": products}, func(p Properties) { p.SetProducts(products...) }},
"repeat": {Properties{"repeat": true}, func(p Properties) { p.SetRepeat(true) }},
}
for name, test := range tests {
prop := NewProperties()
test.run(prop)
if !reflect.DeepEqual(prop, test.ref) {
t.Errorf("%s: invalid properties produced: %#v\n", name, prop)
}
}
}
func TestPropertiesMulti(t *testing.T) {
p0 := Properties{"title": "A", "value": 0.5}
p1 := NewProperties().SetTitle("A").SetValue(0.5)
if !reflect.DeepEqual(p0, p1) {
t.Errorf("invalid properties produced by chained setters:\n- expected %#v\n- found: %#v", p0, p1)
}
}