-
Notifications
You must be signed in to change notification settings - Fork 0
/
cal_service_test.go
114 lines (110 loc) · 2.7 KB
/
cal_service_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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"github.com/stretchr/testify/assert"
"google.golang.org/api/calendar/v3"
"testing"
"time"
)
func TestParseStatus(t *testing.T) {
baseTime := time.Date(2018, time.August, 19, 1, 2, 3, 4, time.UTC)
tests := []struct {
name string
input *calendar.Event
expected EventStatus
}{
{
name: "newly created event - no time difference",
input: &calendar.Event{
Status: googleStatusConfirmed,
Created: baseTime.Format(time.RFC3339),
Updated: baseTime.Format(time.RFC3339),
},
expected: StatusCreated,
},
{
name: "newly created event - slight time difference",
input: &calendar.Event{
Status: googleStatusConfirmed,
Created: baseTime.Format(time.RFC3339),
Updated: baseTime.Add(time.Millisecond).Format(time.RFC3339),
},
expected: StatusCreated,
},
{
name: "updated event",
input: &calendar.Event{
Status: googleStatusConfirmed,
Created: baseTime.Format(time.RFC3339),
Updated: baseTime.Add(time.Minute).Format(time.RFC3339),
},
expected: StatusUpdated,
},
{
name: "cancelled event",
input: &calendar.Event{
Status: googleStatusCancelled,
Created: baseTime.Format(time.RFC3339),
Updated: baseTime.Add(time.Minute).Format(time.RFC3339),
},
expected: StatusCanceled,
},
{
name: "unknown event status",
input: &calendar.Event{
Status: "unexpected google status",
Created: baseTime.Format(time.RFC3339),
Updated: baseTime.Add(time.Minute).Format(time.RFC3339),
},
expected: StatusUnknown,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := parseEventStatus(test.input)
assert.Equal(t, test.expected, actual)
})
}
}
func TestParseEventDates(t *testing.T) {
tests := []struct {
name string
input *calendar.Event
expectedStart string
expectedEnd string
}{
{
name: "date and time",
input: &calendar.Event{
Start: &calendar.EventDateTime{
DateTime: "2024-06-12T20:00:00+03:00",
},
End: &calendar.EventDateTime{
DateTime: "2024-06-12T21:00:00+03:00",
},
},
expectedStart: "2024-06-12T20:00:00+03:00",
expectedEnd: "2024-06-12T21:00:00+03:00",
},
{
name: "date only",
input: &calendar.Event{
Start: &calendar.EventDateTime{
Date: "2024-06-12",
},
End: &calendar.EventDateTime{
Date: "2024-06-13",
},
},
expectedStart: "2024-06-12",
expectedEnd: "2024-06-13",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actualStart := parseEventStart(test.input)
actualEnd := parseEventEnd(test.input)
assert.Equal(t, test.expectedStart, actualStart)
assert.Equal(t, test.expectedEnd, actualEnd)
})
}
}