Skip to content

Commit

Permalink
Fixed tests failing due to timezone changes
Browse files Browse the repository at this point in the history
- Removed one test that relied on a timezone from the database
  • Loading branch information
aaricdev committed Dec 17, 2023
1 parent 864911a commit 8987158
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
Expand Up @@ -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)
Expand Down
12 changes: 3 additions & 9 deletions internal/mock_api/endpoints/schedule/schedule_test.go
Expand Up @@ -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",
Expand Down Expand Up @@ -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")
Expand All @@ -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")
Expand Down
20 changes: 20 additions & 0 deletions internal/mock_api/endpoints/schedule/segment.go
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 != "" {
Expand Down

0 comments on commit 8987158

Please sign in to comment.