-
-
Notifications
You must be signed in to change notification settings - Fork 200
/
user_test.go
87 lines (80 loc) · 2.71 KB
/
user_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
// Copyright © Martin Tournoij – This file is part of GoatCounter and published
// under the terms of a slightly modified EUPL v1.2 license, which can be found
// in the LICENSE file or at https://license.goatcounter.com
package goatcounter_test
import (
"testing"
"time"
"zgo.at/goatcounter/v2"
"zgo.at/tz"
"zgo.at/zstd/zint"
"zgo.at/zstd/ztime"
)
func TestUserEmailReportRange(t *testing.T) {
now := time.Date(2019, 6, 18, 14, 42, 0, 0, time.UTC)
ztime.Now = func() time.Time { return now }
t.Cleanup(func() { ztime.Now = func() time.Time { return time.Now().UTC() } })
wita := tz.MustNew("", "Asia/Makassar")
tests := []struct {
user goatcounter.User
wantStart, wantEnd time.Time
}{
{goatcounter.User{
LastReportAt: now,
Settings: goatcounter.UserSettings{
EmailReports: zint.Int(goatcounter.EmailReportDaily),
Timezone: tz.UTC,
},
}, ztime.FromString("2019-06-18 00:00:00"), ztime.FromString("2019-06-18 23:59:59")},
{goatcounter.User{
LastReportAt: now,
Settings: goatcounter.UserSettings{
SundayStartsWeek: false,
EmailReports: zint.Int(goatcounter.EmailReportWeekly),
Timezone: tz.UTC,
},
}, ztime.FromString("2019-06-17 00:00:00"), ztime.FromString("2019-06-23 23:59:59")},
{goatcounter.User{
LastReportAt: now,
Settings: goatcounter.UserSettings{
SundayStartsWeek: true,
EmailReports: zint.Int(goatcounter.EmailReportWeekly),
Timezone: tz.UTC,
},
}, ztime.FromString("2019-06-16 00:00:00"), ztime.FromString("2019-06-22 23:59:59")},
{goatcounter.User{
LastReportAt: now,
Settings: goatcounter.UserSettings{
SundayStartsWeek: false,
EmailReports: zint.Int(goatcounter.EmailReportBiWeekly),
Timezone: tz.UTC,
},
}, ztime.FromString("2019-06-17 00:00:00"), ztime.FromString("2019-06-30 23:59:59")},
{goatcounter.User{
LastReportAt: now,
Settings: goatcounter.UserSettings{
SundayStartsWeek: true,
EmailReports: zint.Int(goatcounter.EmailReportBiWeekly),
Timezone: tz.UTC,
},
}, ztime.FromString("2019-06-16 00:00:00"), ztime.FromString("2019-06-29 23:59:59")},
{goatcounter.User{
LastReportAt: now,
Settings: goatcounter.UserSettings{
EmailReports: zint.Int(goatcounter.EmailReportDaily),
Timezone: wita,
},
}, ztime.FromString("2019-06-17 16:00:00"), ztime.FromString("2019-06-18 15:59:59")},
}
for _, tt := range tests {
t.Run("", func(t *testing.T) {
rng := tt.user.EmailReportRange()
if !rng.Start.Equal(tt.wantStart) {
t.Errorf("start wrong\nwant: %s\nhave: %s\n", tt.wantStart, rng.Start)
}
if !rng.End.Equal(tt.wantEnd) {
t.Errorf("end wrong\nwant: %s\nhave: %s\n", tt.wantEnd, rng.End)
}
})
}
}