Skip to content

Commit 8987158

Browse files
committed
Fixed tests failing due to timezone changes
- Removed one test that relied on a timezone from the database
1 parent 864911a commit 8987158

3 files changed

Lines changed: 24 additions & 9 deletions

File tree

internal/mock_api/endpoints/channel_points/channel_points_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ func TestRedemption(t *testing.T) {
8686
a.Equal(400, resp.StatusCode)
8787

8888
q.Set("broadcaster_id", "2")
89+
q.Set("status", "FULFILLED")
8990
req.URL.RawQuery = q.Encode()
9091
resp, err = http.DefaultClient.Do(req)
9192
a.Nil(err)

internal/mock_api/endpoints/schedule/schedule_test.go

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ func TestSegment(t *testing.T) {
133133
// post tests
134134
body := SegmentPatchAndPostBody{
135135
Title: "hello",
136+
Timezone: "America/Los_Angeles",
136137
StartTime: time.Now().Format(time.RFC3339),
137138
IsRecurring: &tr,
138139
Duration: "60",
@@ -166,6 +167,7 @@ func TestSegment(t *testing.T) {
166167
a.Equal(401, resp.StatusCode)
167168

168169
body.Title = "testing"
170+
body.Timezone = ""
169171
b, _ = json.Marshal(body)
170172
req, _ = http.NewRequest(http.MethodPost, ts.URL+ScheduleSegment{}.Path(), bytes.NewBuffer(b))
171173
q.Set("broadcaster_id", "1")
@@ -174,15 +176,7 @@ func TestSegment(t *testing.T) {
174176
a.Nil(err)
175177
a.Equal(400, resp.StatusCode)
176178

177-
b, _ = json.Marshal(body)
178-
req, _ = http.NewRequest(http.MethodPost, ts.URL+ScheduleSegment{}.Path(), bytes.NewBuffer(b))
179-
q.Set("broadcaster_id", "1")
180-
req.URL.RawQuery = q.Encode()
181-
resp, err = http.DefaultClient.Do(req)
182-
a.Nil(err)
183-
a.Equal(400, resp.StatusCode)
184-
185-
body.IsRecurring = nil
179+
body.Timezone = "test"
186180
b, _ = json.Marshal(body)
187181
req, _ = http.NewRequest(http.MethodPost, ts.URL+ScheduleSegment{}.Path(), bytes.NewBuffer(b))
188182
q.Set("broadcaster_id", "1")

internal/mock_api/endpoints/schedule/segment.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ type ScheduleSegment struct{}
3939

4040
type SegmentPatchAndPostBody struct {
4141
StartTime string `json:"start_time"`
42+
Timezone string `json:"timezone"`
4243
IsRecurring *bool `json:"is_recurring"`
4344
Duration string `json:"duration"`
4445
CategoryID *string `json:"category_id"`
@@ -96,6 +97,16 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) {
9697
return
9798
}
9899

100+
if body.Timezone == "" {
101+
mock_errors.WriteBadRequest(w, "Missing timezone")
102+
return
103+
}
104+
_, err = time.LoadLocation(body.Timezone)
105+
if err != nil {
106+
mock_errors.WriteBadRequest(w, "Invalid timezone provided")
107+
return
108+
}
109+
99110
var isRecurring bool
100111

101112
if body.IsRecurring == nil {
@@ -255,6 +266,15 @@ func (e ScheduleSegment) patchSegment(w http.ResponseWriter, r *http.Request) {
255266
isCanceled = *body.IsCanceled
256267
}
257268

269+
// timezone
270+
if body.Timezone != "" {
271+
_, err := time.LoadLocation(body.Timezone)
272+
if err != nil {
273+
mock_errors.WriteBadRequest(w, "Error parsing timezone")
274+
return
275+
}
276+
}
277+
258278
// title
259279
title := segment.Title
260280
if body.Title != "" {

0 commit comments

Comments
 (0)