-
Notifications
You must be signed in to change notification settings - Fork 10
/
many_2_many_test.go
83 lines (64 loc) · 2.36 KB
/
many_2_many_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
package publish_test
import "testing"
func TestPublishManyToManyFromProduction(t *testing.T) {
name := "create_product_with_multi_categories_from_production"
pbprod.Create(&Product{
Name: name,
Categories: []Category{{Name: "category1"}, {Name: "category2"}},
})
var product Product
pbprod.First(&product, "name = ?", name)
if pbprod.Model(&product).Association("Categories").Count() != 2 {
t.Errorf("categories count should be 2 in production db")
}
if pbdraft.Model(&product).Association("Categories").Count() != 2 {
t.Errorf("categories count should be 2 in draft db")
}
}
func TestPublishManyToManyFromDraft(t *testing.T) {
name := "create_product_with_multi_categories_from_draft"
pbdraft.Create(&Product{
Name: name,
Categories: []Category{{Name: "category1"}, {Name: "category2"}},
})
var product Product
pbdraft.First(&product, "name = ?", name)
if pbprod.Model(&product).Association("Categories").Count() != 0 {
t.Errorf("categories count should be 0 in production db")
}
if pbdraft.Model(&product).Association("Categories").Count() != 2 {
t.Errorf("categories count should be 2 in draft db")
}
pb.Publish(&product)
var categories []Category
pbdraft.Find(&categories)
pb.Publish(&categories)
if pbprod.Model(&product).Association("Categories").Count() != 2 {
t.Errorf("categories count should be 2 in production db after publish")
}
if pbdraft.Model(&product).Association("Categories").Count() != 2 {
t.Errorf("categories count should be 2 in draft db after publish")
}
}
func TestDiscardManyToManyFromDraft(t *testing.T) {
name := "discard_product_with_multi_categories_from_draft"
pbdraft.Create(&Product{
Name: name,
Categories: []Category{{Name: "category1"}, {Name: "category2"}},
})
var product Product
pbdraft.First(&product, "name = ?", name)
if pbprod.Model(&product).Association("Categories").Count() != 0 {
t.Errorf("categories count should be 0 in production db")
}
if pbdraft.Model(&product).Association("Categories").Count() != 2 {
t.Errorf("categories count should be 2 in draft db")
}
pb.Discard(&product)
if pbprod.Model(&product).Association("Categories").Count() != 0 {
t.Errorf("categories count should be 0 in production db after discard")
}
if pbdraft.Model(&product).Association("Categories").Count() != 0 {
t.Errorf("categories count should be 0 in draft db after discard")
}
}