-
Notifications
You must be signed in to change notification settings - Fork 0
/
LessonWriter_test.go
66 lines (52 loc) · 1.77 KB
/
LessonWriter_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
package main
import (
"github.com/go-redis/redismock/v9"
"github.com/kneu-messenger-pigeon/events"
"github.com/stretchr/testify/assert"
"testing"
"time"
)
func TestWriteLesson(t *testing.T) {
t.Run("write lesson", func(t *testing.T) {
event := events.LessonEvent{
Id: 600,
DisciplineId: 200,
TypeId: 5,
Date: time.Date(2027, time.Month(5), 13, 0, 0, 0, 0, time.Local),
Year: 2026,
Semester: 2,
IsDeleted: false,
}
redis, redisMock := redismock.NewClientMock()
redisMock.ExpectHSet("2026:2:lessons:200", "600", "2705135").SetVal(1)
lessonWriter := LessonWriter{}
lessonWriter.setRedis(redis)
err := lessonWriter.write(&event)
assert.IsType(t, lessonWriter.getExpectedEventType(), &event)
assert.Equal(t, lessonWriter.getExpectedMessageKey(), events.LessonEventName)
assert.NoError(t, err)
assert.NoError(t, redisMock.ExpectationsWereMet())
})
t.Run("delete lesson", func(t *testing.T) {
event := events.LessonEvent{
Id: 650,
DisciplineId: 250,
TypeId: 5,
Date: time.Date(2030, time.Month(4), 26, 0, 0, 0, 0, time.Local),
Year: 2029,
Semester: 2,
IsDeleted: true,
}
redis, redisMock := redismock.NewClientMock()
redisMock.MatchExpectationsInOrder(true)
redisMock.ExpectSetEx("2029:2:deleted-lessons:250:650", "3004265", time.Hour*24).SetVal("OK")
redisMock.ExpectHDel("2029:2:lessons:250", "650").SetVal(1)
lessonWriter := LessonWriter{}
lessonWriter.setRedis(redis)
err := lessonWriter.write(&event)
assert.IsType(t, lessonWriter.getExpectedEventType(), &event)
assert.Equal(t, lessonWriter.getExpectedMessageKey(), events.LessonEventName)
assert.NoError(t, err)
assert.NoError(t, redisMock.ExpectationsWereMet())
})
}