Skip to content

Commit

Permalink
test(FilesProvider): test SetEventTimes
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-he committed Aug 16, 2024
1 parent ada8aa4 commit 6fcde64
Showing 1 changed file with 100 additions and 0 deletions.
100 changes: 100 additions & 0 deletions internal/storage/providers/files_provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,106 @@ func TestFilesProvider(t *testing.T) {
})
})

t.Run("set-event-times", func(t *testing.T) {
setupWithSingleEvent := func(t *testing.T, start time.Time, end time.Time) string {
doEmpty(t)
id, err := p.AddEvent(model.Event{
Name: "test event",
Category: "test",
Start: start,
End: end,
})
assert.Nil(t, err)
return id
}

originalStart := time.Date(2023, 1, 1, 12, 0, 0, 0, time.UTC)
originalEnd := time.Date(2023, 1, 1, 14, 0, 0, 0, time.UTC)

t.Run("valid-change-with-same-date", func(t *testing.T) {
id := setupWithSingleEvent(t, originalStart, originalEnd)
newStart := time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC)
newEnd := time.Date(2023, 1, 1, 16, 0, 0, 0, time.UTC)

err := p.SetEventTimes(id, newStart, newEnd)
assert.Nil(t, err)

event, err := p.GetEvent(id)
assert.Nil(t, err)
assert.Equal(t, newStart, event.Start)
assert.Equal(t, newEnd, event.End)
})

t.Run("valid-change-to-different-date", func(t *testing.T) {
id := setupWithSingleEvent(t, originalStart, originalEnd)
newStart := time.Date(2023, 1, 2, 10, 0, 0, 0, time.UTC)
newEnd := time.Date(2023, 1, 2, 16, 0, 0, 0, time.UTC)

err := p.SetEventTimes(id, newStart, newEnd)
assert.Nil(t, err)

event, err := p.GetEvent(id)
assert.Nil(t, err)
assert.Equal(t, newStart, event.Start)
assert.Equal(t, newEnd, event.End)
})

t.Run("invalid-same-start-and-end", func(t *testing.T) {
id := setupWithSingleEvent(t, originalStart, originalEnd)
newTime := time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC)

err := p.SetEventTimes(id, newTime, newTime)
assert.NotNil(t, err)

event, err := p.GetEvent(id)
assert.Nil(t, err)
assert.Equal(t, originalStart, event.Start)
assert.Equal(t, originalEnd, event.End)
})

t.Run("invalid-start-after-end", func(t *testing.T) {
id := setupWithSingleEvent(t, originalStart, originalEnd)
newStart := time.Date(2023, 1, 1, 18, 0, 0, 0, time.UTC)
newEnd := time.Date(2023, 1, 1, 16, 0, 0, 0, time.UTC)

err := p.SetEventTimes(id, newStart, newEnd)
assert.NotNil(t, err)

event, err := p.GetEvent(id)
assert.Nil(t, err)
assert.Equal(t, originalStart, event.Start)
assert.Equal(t, originalEnd, event.End)
})

t.Run("invalid-start-to-different-date", func(t *testing.T) {
id := setupWithSingleEvent(t, originalStart, originalEnd)
newStart := time.Date(2023, 1, 5, 18, 0, 0, 0, time.UTC)
newEnd := time.Date(2023, 1, 6, 16, 0, 0, 0, time.UTC)

err := p.SetEventTimes(id, newStart, newEnd)
assert.NotNil(t, err)

event, err := p.GetEvent(id)
assert.Nil(t, err)
assert.Equal(t, originalStart, event.Start)
assert.Equal(t, originalEnd, event.End)
})

t.Run("invalid-end-to-different-date", func(t *testing.T) {
id := setupWithSingleEvent(t, originalStart, originalEnd)
newStart := time.Date(2023, 1, 1, 10, 0, 0, 0, time.UTC)
newEnd := time.Date(2023, 1, 2, 14, 0, 0, 0, time.UTC)

err := p.SetEventTimes(id, newStart, newEnd)
assert.NotNil(t, err)

event, err := p.GetEvent(id)
assert.Nil(t, err)
assert.Equal(t, originalStart, event.Start)
assert.Equal(t, originalEnd, event.End)
})
})

}

type testWriter struct {
Expand Down

0 comments on commit 6fcde64

Please sign in to comment.