-
Notifications
You must be signed in to change notification settings - Fork 0
/
activities_integration_test.go
132 lines (105 loc) · 3.57 KB
/
activities_integration_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
126
127
128
129
130
131
132
//go:build integration
// nolint:errcheck
package libwekan
import (
"go.mongodb.org/mongo-driver/bson"
"testing"
"github.com/stretchr/testify/assert"
)
func TestActivities_insertActivity_whenEverythingsFine(t *testing.T) {
ass := assert.New(t)
// GIVEN
activity := newActivityCreateBoard(UserID(t.Name()+"_userId"), BoardID(t.Name()+"_boardID"))
// WHEN
insertedActivity, err := wekan.insertActivity(ctx, activity)
ass.Nil(err)
// THEN
selectedActivity, err := wekan.GetActivityFromID(ctx, insertedActivity.ID)
ass.Nil(err)
ass.Equal(insertedActivity, selectedActivity)
}
func TestActivities_InsertActivity_WithActivityIsAlreadySet(t *testing.T) {
ass := assert.New(t)
// GIVEN
activity := newActivityCreateBoard(UserID(t.Name()+"_userId"), BoardID(t.Name()+"_boardID"))
// WHEN
insertedActivity, err := wekan.insertActivity(ctx, activity)
ass.Nil(err)
notInsertedActivity, err := wekan.insertActivity(ctx, insertedActivity)
// THEN
ass.IsType(AlreadySetActivityError{}, err)
ass.Empty(notInsertedActivity)
}
func TestActivities_selectActivitiesFromBoardID(t *testing.T) {
ass := assert.New(t)
// GIVEN
board, _, _ := createTestBoard(t, "", 1, 1)
userID := UserID(t.Name() + "userID")
memberID := UserID(t.Name() + "memberID")
activityToInsert := newActivityAddBoardMember(userID, memberID, board.ID)
insertedActivity, _ := wekan.insertActivity(ctx, activityToInsert)
// WHEN
activities, err := wekan.SelectActivitiesFromBoardID(ctx, board.ID)
// THEN
ass.Nil(err)
ass.NotNil(activities)
ass.Contains(activities, insertedActivity)
}
func TestActivities_selectActivitiesFromQuery(t *testing.T) {
ass := assert.New(t)
// GIVEN
board, _, _ := createTestBoard(t, "", 1, 1)
userID := UserID(t.Name() + "userID")
memberID := UserID(t.Name() + "memberID")
activityToInsert := newActivityAddBoardMember(userID, memberID, board.ID)
insertedActivity, _ := wekan.insertActivity(ctx, activityToInsert)
// WHEN
activities, err := wekan.SelectActivitiesFromQuery(ctx, bson.M{"boardId": board.ID})
// THEN
ass.Nil(err)
ass.NotNil(activities)
ass.Contains(activities, insertedActivity)
}
func TestActivities_GetActivityFromID(t *testing.T) {
ass := assert.New(t)
// GIVEN
activity := newActivityCreateBoard("", "")
insertedActivity, _ := wekan.insertActivity(ctx, activity)
// WHEN
actualActivityFromMethod, err := wekan.GetActivityFromID(ctx, insertedActivity.ID)
ass.Nil(err)
actualActivityFromID, err := insertedActivity.ID.GetDocument(ctx, &wekan)
ass.Nil(err)
// THEN
ass.Equal(insertedActivity, actualActivityFromID)
ass.Equal(insertedActivity, actualActivityFromMethod)
}
func TestActivities_GetActivityFromID_WhenActivityDoesntExist(t *testing.T) {
ass := assert.New(t)
// GIVEN
activityID := ActivityID(t.Name() + "absent")
// WHEN
actualActivityFromMethod, errFromMethod := wekan.GetActivityFromID(ctx, activityID)
actualActivityFromID, errFromID := activityID.GetDocument(ctx, &wekan)
// THEN
ass.Empty(actualActivityFromMethod)
ass.Empty(actualActivityFromID)
ass.IsType(ActivityNotFoundError{}, errFromMethod)
ass.IsType(ActivityNotFoundError{}, errFromID)
}
func TestActivities_CheckActivityFromID(t *testing.T) {
ass := assert.New(t)
// GIVEN
activity := newActivityCreateBoard("", "")
// WHEN
insertedActivity, _ := wekan.insertActivity(ctx, activity)
// THEN
ass.Nil(insertedActivity.ID.Check(ctx, &wekan))
}
func TestActivities_CheckActivityFromID_WhenActivityDoesntExist(t *testing.T) {
ass := assert.New(t)
// GIVEN
activityID := ActivityID(t.Name() + "absent")
// THEN
ass.IsType(ActivityNotFoundError{}, activityID.Check(ctx, &wekan))
}