|
|
|
package themis
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
"time"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAddAbsence(t *testing.T) {
|
|
|
|
store, err := NewStore(fmt.Sprintf(TEST_CONN_STRING_PATTERN, "TestAddAbsence"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
now := NextMonday()
|
|
|
|
assert.NoError(t, store.AddAbsence(context.TODO(), now, "foobarbaz"))
|
|
|
|
absentees, err := store.GetAbsentees(context.TODO(), now)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(absentees))
|
|
|
|
assert.Equal(t, "foobarbaz", absentees[0])
|
|
|
|
|
|
|
|
assert.NoError(t, store.AddAbsence(context.TODO(), now, "foobarbaz"))
|
|
|
|
absentees, err = store.GetAbsentees(context.TODO(), now)
|
|
|
|
assert.NoError(t, err)
|
|
|
|
assert.Equal(t, 1, len(absentees))
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGetSchedule(t *testing.T) {
|
|
|
|
store, err := NewStore(fmt.Sprintf(TEST_CONN_STRING_PATTERN, "TestGetSchedule"))
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
now := NextMonday()
|
|
|
|
|
|
|
|
_ = store.AddAbsence(context.TODO(), now.Add(7*24*time.Hour), "foobar")
|
|
|
|
|
|
|
|
schedule, err := store.GetSchedule(context.TODO(), now, now.AddDate(0, 0, 14))
|
|
|
|
assert.NoError(t, err)
|
|
|
|
// reason being, the schedule should initialize to the desired time range
|
|
|
|
assert.Equal(t, 3, len(schedule))
|
|
|
|
for d, a := range schedule {
|
|
|
|
if d == now.Add(7*24*time.Hour).Format(time.DateOnly) {
|
|
|
|
assert.Equal(t, 1, len(a))
|
|
|
|
} else {
|
|
|
|
assert.Equal(t, 0, len(a))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|