-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_test.go
76 lines (59 loc) · 1.81 KB
/
utils_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
package microsite_test
import (
"fmt"
"testing"
"time"
"github.com/Pallinder/go-randomdata"
"github.com/qor/publish2"
"github.com/qor/qor/test/utils"
"github.com/theplant/microsite"
)
func TestTobeOnlineSites(t *testing.T) {
db := utils.PrepareDBAndTables(µsite.QorMicroSite{})
publish2.RegisterCallbacks(db)
now := time.Now()
m1 := NewMicrosite(microsite.Status_draft)
m2 := NewMicrosite(microsite.Status_draft)
aWhileAgo := now.Add(-1 * time.Minute)
aWhileLater := now.Add(1 * time.Minute)
m1.SetScheduledStartAt(&aWhileAgo)
m2.SetScheduledStartAt(&aWhileLater)
utils.AssertNoErr(t, db.Create(&m1).Error)
utils.AssertNoErr(t, db.Create(&m2).Error)
sites, err := microsite.GetSites(db, microsite.Status_draft)
if err != nil {
t.Fatal(err)
}
if len(sites) != 1 {
t.Error("not returning correct numbers of sites")
}
if sites[0].ID != m1.ID {
t.Error("not returning correct site")
}
}
func TestTobeOfflineSites(t *testing.T) {
db := utils.PrepareDBAndTables(µsite.QorMicroSite{})
publish2.RegisterCallbacks(db)
now := time.Now()
m1 := NewMicrosite(microsite.Status_published)
m2 := NewMicrosite(microsite.Status_published)
aWhileAgo := now.Add(-1 * time.Minute)
aWhileLater := now.Add(1 * time.Minute)
m1.SetScheduledEndAt(&aWhileLater)
m2.SetScheduledEndAt(&aWhileAgo)
utils.AssertNoErr(t, db.Create(&m1).Error)
utils.AssertNoErr(t, db.Create(&m2).Error)
sites, err := microsite.GetSites(db, microsite.Status_draft)
if err != nil {
t.Fatal(err)
}
if len(sites) != 1 {
t.Error("not returning correct numbers of sites")
}
if sites[0].ID != m1.ID {
t.Error("not returning correct site")
}
}
func NewMicrosite(status string) microsite.QorMicroSite {
return microsite.QorMicroSite{Name: randomdata.SillyName(), URL: fmt.Sprintf("/%s", randomdata.SillyName()), Status: status}
}