forked from jsteenb2/mess
-
Notifications
You must be signed in to change notification settings - Fork 0
/
availability_test.go
125 lines (94 loc) · 3.04 KB
/
availability_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
115
116
117
118
119
120
121
122
123
124
125
package hour_test
import (
"testing"
"github.com/ThreeDotsLabs/wild-workouts-go-ddd-example/internal/trainer/domain/hour"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestHour_MakeNotAvailable(t *testing.T) {
t.Parallel()
h, err := testHourFactory.NewAvailableHour(validTrainingHour())
require.NoError(t, err)
require.NoError(t, h.MakeNotAvailable())
assert.False(t, h.IsAvailable())
}
func TestHour_MakeNotAvailable_with_scheduled_training(t *testing.T) {
t.Parallel()
h := newHourWithScheduledTraining(t)
assert.Equal(t, hour.ErrTrainingScheduled, h.MakeNotAvailable())
}
func TestHour_MakeAvailable(t *testing.T) {
t.Parallel()
h, err := testHourFactory.NewAvailableHour(validTrainingHour())
require.NoError(t, err)
require.NoError(t, h.MakeNotAvailable())
require.NoError(t, h.MakeAvailable())
assert.True(t, h.IsAvailable())
}
func TestHour_MakeAvailable_with_scheduled_training(t *testing.T) {
t.Parallel()
h := newHourWithScheduledTraining(t)
assert.Equal(t, hour.ErrTrainingScheduled, h.MakeAvailable())
}
func TestHour_ScheduleTraining(t *testing.T) {
t.Parallel()
h, err := testHourFactory.NewAvailableHour(validTrainingHour())
require.NoError(t, err)
require.NoError(t, h.ScheduleTraining())
assert.True(t, h.HasTrainingScheduled())
assert.False(t, h.IsAvailable())
}
func TestHour_ScheduleTraining_with_not_available(t *testing.T) {
t.Parallel()
h := newNotAvailableHour(t)
assert.Equal(t, hour.ErrHourNotAvailable, h.ScheduleTraining())
}
func TestHour_CancelTraining(t *testing.T) {
t.Parallel()
h := newHourWithScheduledTraining(t)
require.NoError(t, h.CancelTraining())
assert.False(t, h.HasTrainingScheduled())
assert.True(t, h.IsAvailable())
}
func TestHour_CancelTraining_no_training_scheduled(t *testing.T) {
t.Parallel()
h, err := testHourFactory.NewAvailableHour(validTrainingHour())
require.NoError(t, err)
assert.Equal(t, hour.ErrNoTrainingScheduled, h.CancelTraining())
}
func TestNewAvailabilityFromString(t *testing.T) {
t.Parallel()
testCases := []hour.Availability{
hour.Available,
hour.NotAvailable,
hour.TrainingScheduled,
}
for _, tc := range testCases {
expectedAvailability := tc
t.Run(expectedAvailability.String(), func(t *testing.T) {
t.Parallel()
availability, err := hour.NewAvailabilityFromString(expectedAvailability.String())
require.NoError(t, err)
assert.Equal(t, expectedAvailability, availability)
})
}
}
func TestNewAvailabilityFromString_invalid(t *testing.T) {
t.Parallel()
_, err := hour.NewAvailabilityFromString("invalid_value")
assert.Error(t, err)
_, err = hour.NewAvailabilityFromString("")
assert.Error(t, err)
}
func newHourWithScheduledTraining(t *testing.T) *hour.Hour {
h, err := testHourFactory.NewAvailableHour(validTrainingHour())
require.NoError(t, err)
require.NoError(t, h.ScheduleTraining())
return h
}
func newNotAvailableHour(t *testing.T) *hour.Hour {
h, err := testHourFactory.NewAvailableHour(validTrainingHour())
require.NoError(t, err)
require.NoError(t, h.MakeNotAvailable())
return h
}