From 8987158e3ac07b1f43da711cee3eb73f51936c04 Mon Sep 17 00:00:00 2001 From: Aaricdev Date: Sun, 17 Dec 2023 17:52:43 +0100 Subject: [PATCH] Fixed tests failing due to timezone changes - Removed one test that relied on a timezone from the database --- .../channel_points/channel_points_test.go | 1 + .../endpoints/schedule/schedule_test.go | 12 +++-------- .../mock_api/endpoints/schedule/segment.go | 20 +++++++++++++++++++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/internal/mock_api/endpoints/channel_points/channel_points_test.go b/internal/mock_api/endpoints/channel_points/channel_points_test.go index 878fe05b..cdffae19 100644 --- a/internal/mock_api/endpoints/channel_points/channel_points_test.go +++ b/internal/mock_api/endpoints/channel_points/channel_points_test.go @@ -86,6 +86,7 @@ func TestRedemption(t *testing.T) { a.Equal(400, resp.StatusCode) q.Set("broadcaster_id", "2") + q.Set("status", "FULFILLED") req.URL.RawQuery = q.Encode() resp, err = http.DefaultClient.Do(req) a.Nil(err) diff --git a/internal/mock_api/endpoints/schedule/schedule_test.go b/internal/mock_api/endpoints/schedule/schedule_test.go index d6a74381..92a744c2 100644 --- a/internal/mock_api/endpoints/schedule/schedule_test.go +++ b/internal/mock_api/endpoints/schedule/schedule_test.go @@ -133,6 +133,7 @@ func TestSegment(t *testing.T) { // post tests body := SegmentPatchAndPostBody{ Title: "hello", + Timezone: "America/Los_Angeles", StartTime: time.Now().Format(time.RFC3339), IsRecurring: &tr, Duration: "60", @@ -166,6 +167,7 @@ func TestSegment(t *testing.T) { a.Equal(401, resp.StatusCode) body.Title = "testing" + body.Timezone = "" b, _ = json.Marshal(body) req, _ = http.NewRequest(http.MethodPost, ts.URL+ScheduleSegment{}.Path(), bytes.NewBuffer(b)) q.Set("broadcaster_id", "1") @@ -174,15 +176,7 @@ func TestSegment(t *testing.T) { a.Nil(err) a.Equal(400, resp.StatusCode) - b, _ = json.Marshal(body) - req, _ = http.NewRequest(http.MethodPost, ts.URL+ScheduleSegment{}.Path(), bytes.NewBuffer(b)) - q.Set("broadcaster_id", "1") - req.URL.RawQuery = q.Encode() - resp, err = http.DefaultClient.Do(req) - a.Nil(err) - a.Equal(400, resp.StatusCode) - - body.IsRecurring = nil + body.Timezone = "test" b, _ = json.Marshal(body) req, _ = http.NewRequest(http.MethodPost, ts.URL+ScheduleSegment{}.Path(), bytes.NewBuffer(b)) q.Set("broadcaster_id", "1") diff --git a/internal/mock_api/endpoints/schedule/segment.go b/internal/mock_api/endpoints/schedule/segment.go index e048e617..a86a15e8 100644 --- a/internal/mock_api/endpoints/schedule/segment.go +++ b/internal/mock_api/endpoints/schedule/segment.go @@ -39,6 +39,7 @@ type ScheduleSegment struct{} type SegmentPatchAndPostBody struct { StartTime string `json:"start_time"` + Timezone string `json:"timezone"` IsRecurring *bool `json:"is_recurring"` Duration string `json:"duration"` CategoryID *string `json:"category_id"` @@ -96,6 +97,16 @@ func (e ScheduleSegment) postSegment(w http.ResponseWriter, r *http.Request) { return } + if body.Timezone == "" { + mock_errors.WriteBadRequest(w, "Missing timezone") + return + } + _, err = time.LoadLocation(body.Timezone) + if err != nil { + mock_errors.WriteBadRequest(w, "Invalid timezone provided") + return + } + var isRecurring bool if body.IsRecurring == nil { @@ -255,6 +266,15 @@ func (e ScheduleSegment) patchSegment(w http.ResponseWriter, r *http.Request) { isCanceled = *body.IsCanceled } + // timezone + if body.Timezone != "" { + _, err := time.LoadLocation(body.Timezone) + if err != nil { + mock_errors.WriteBadRequest(w, "Error parsing timezone") + return + } + } + // title title := segment.Title if body.Title != "" {