-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathuser_profile_test.go
More file actions
229 lines (183 loc) · 7.43 KB
/
Copy pathuser_profile_test.go
File metadata and controls
229 lines (183 loc) · 7.43 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
package main
import (
"context"
"testing"
"github.com/Microkubes/microservice-security/auth"
"github.com/Microkubes/microservice-user-profile/app"
"github.com/Microkubes/microservice-user-profile/app/test"
"github.com/Microkubes/microservice-user-profile/db"
"github.com/keitaroinc/goa"
)
var (
service = goa.New("user-profile-test")
database = db.New()
ctrl = NewUserProfileController(service, database)
hexObjectID = "5975c461f9f8eb02aae053f3"
internalErrorObjectID = "6975c461f9f8eb02aae053f3"
fakeHexObjectID = "fakeobjectidab02aae053f3"
badHexObjectID = "fakeobjectidab02aae053f3aasadas"
expectedUserEmail = "frieda@oberbrunnerkirlin.name"
expectedUserFullName = "Alexandra Anderson"
)
func TestGetUserProfileUserProfileOK(t *testing.T) {
// Call generated test helper, this checks that the returned media type is of the
// correct type (i.e. uses view "default") and validates the media type.
// Also, it ckecks the returned status code
_, user := test.GetUserProfileUserProfileOK(t, context.Background(), service, ctrl, hexObjectID)
if user == nil {
t.Fatal("Nil user")
}
if user.UserID != hexObjectID {
t.Errorf("Invalid user ID, expected %s, got %s", hexObjectID, user.UserID)
}
userEmail := *user.Email
if userEmail != expectedUserEmail {
t.Errorf("Invalid user Email, expected %s, got %s", expectedUserEmail, userEmail)
}
userFullName := *user.FullName
if userFullName != expectedUserFullName {
t.Errorf("Invalid user Full Name, expected %s, got %s", expectedUserFullName, userFullName)
}
}
func TestGetUserProfileUserProfileNotFound(t *testing.T) {
// The test helper takes care of validating the status code for us
test.GetUserProfileUserProfileNotFound(t, context.Background(), service, ctrl, fakeHexObjectID)
}
func TestGetUserProfileUserProfileInternalServerError(t *testing.T) {
// The test helper takes care of validating the status code for us
test.GetUserProfileUserProfileInternalServerError(t, context.Background(), service, ctrl, internalErrorObjectID)
}
func TestGetUserProfileUserProfileBadRequest(t *testing.T) {
// The test helper takes care of validating the status code for us
test.GetUserProfileUserProfileBadRequest(t, context.Background(), service, ctrl, badHexObjectID)
}
func TestGetMyProfileUserProfileOK(t *testing.T) {
// Call generated test helper, this checks that the returned media type is of the
// correct type (i.e. uses view "default") and validates the media type.
// Also, it ckecks the returned status code
ctx := context.Background()
authObj := &auth.Auth{UserID: hexObjectID}
ctx = auth.SetAuth(ctx, authObj)
_, user := test.GetMyProfileUserProfileOK(t, ctx, service, ctrl)
if user == nil {
t.Fatal("Nil user")
}
if user.UserID != hexObjectID {
t.Errorf("Invalid user ID, expected %s, got %s", hexObjectID, user.UserID)
}
userEmail := *user.Email
if userEmail != expectedUserEmail {
t.Errorf("Invalid user Email, expected %s, got %s", expectedUserEmail, userEmail)
}
userFullName := *user.FullName
if userFullName != expectedUserFullName {
t.Errorf("Invalid user Full Name, expected %s, got %s", expectedUserFullName, userFullName)
}
}
func TestGetMyProfileUserProfileNotFound(t *testing.T) {
// The test helper takes care of validating the status code for us
ctx := context.Background()
authObj := &auth.Auth{UserID: fakeHexObjectID}
ctx = auth.SetAuth(ctx, authObj)
test.GetMyProfileUserProfileNotFound(t, ctx, service, ctrl)
}
func TestGetMyProfileUserProfileInternalServerError(t *testing.T) {
// The test helper takes care of validating the status code for us
ctx := context.Background()
authObj := &auth.Auth{UserID: internalErrorObjectID}
ctx = auth.SetAuth(ctx, authObj)
test.GetMyProfileUserProfileInternalServerError(t, ctx, service, ctrl)
}
func TestGetMyProfileUserProfileBadRequest(t *testing.T) {
// The test helper takes care of validating the status code for us
ctx := context.Background()
authObj := &auth.Auth{UserID: badHexObjectID}
ctx = auth.SetAuth(ctx, authObj)
test.GetMyProfileUserProfileBadRequest(t, ctx, service, ctrl)
}
func TestUpdateUserProfileUserProfileInternalServerError(t *testing.T) {
ctx := context.Background()
userProfilePayload := &app.UserProfilePayload{
FullName: expectedUserFullName,
Email: expectedUserEmail,
}
_, users := test.UpdateUserProfileUserProfileInternalServerError(t, ctx, service, ctrl, internalErrorObjectID, userProfilePayload)
if users == nil {
t.Fatal()
}
}
func TestUpdateUserProfileUserProfileBadRequest(t *testing.T) {
ctx := context.Background()
userProfilePayload := &app.UserProfilePayload{
FullName: expectedUserFullName,
Email: expectedUserEmail,
}
_, users := test.UpdateUserProfileUserProfileBadRequest(t, ctx, service, ctrl, badHexObjectID, userProfilePayload)
if users == nil {
t.Fatal()
}
}
func TestUpdateUserProfileUserProfileOK(t *testing.T) {
ctx := context.Background()
userProfilePayload := &app.UserProfilePayload{
FullName: expectedUserFullName,
Email: expectedUserEmail,
}
_, users := test.UpdateUserProfileUserProfileOK(t, ctx, service, ctrl, hexObjectID, userProfilePayload)
if users == nil {
t.Fatal()
}
}
func TestUpdateMyProfileUserProfileBadRequest(t *testing.T){
ctx := context.Background()
authObj := &auth.Auth{UserID: badHexObjectID}
ctx = auth.SetAuth(ctx, authObj)
userProfilePayload := &app.UserProfilePayload{
FullName: expectedUserFullName,
Email: expectedUserEmail,
}
_, users := test.UpdateMyProfileUserProfileBadRequest(t, ctx, service, ctrl, userProfilePayload)
if users == nil {
t.Fatal()
}
}
// func UpdateMyProfileUserProfileOK(t goatest.TInterface, ctx context.Context, service *goa.Service, ctrl app.UserProfileController, payload *app.UserProfilePayload) (http.ResponseWriter, *app.UserProfile) {
func TestUpdateMyProfileUserProfileOK(t *testing.T) {
ctx := context.Background()
authObj := &auth.Auth{UserID: hexObjectID}
ctx = auth.SetAuth(ctx, authObj)
userProfilePayload := &app.UserProfilePayload{
FullName: expectedUserFullName,
Email: expectedUserEmail,
}
_, users := test.UpdateMyProfileUserProfileOK(t, ctx, service, ctrl, userProfilePayload)
if users == nil {
t.Fatal()
}
}
// // func UpdateMyProfileUserProfileInternalServerError(t goatest.TInterface, ctx context.Context, service *goa.Service, ctrl app.UserProfileController, payload *app.UserProfilePayload) (http.ResponseWriter, error) {
func TestUpdateMyProfileUserProfileInternalServerError(t *testing.T) {
ctx := context.Background()
authObj := &auth.Auth{UserID: internalErrorObjectID}
ctx = auth.SetAuth(ctx, authObj)
userProfilePayload := &app.UserProfilePayload{
FullName: expectedUserFullName,
Email: expectedUserEmail,
}
_, users := test.UpdateMyProfileUserProfileInternalServerError(t, ctx, service, ctrl, userProfilePayload)
if users == nil {
t.Fatal()
}}
// // func UpdateMyProfileUserProfileNotFound(t goatest.TInterface, ctx context.Context, service *goa.Service, ctrl app.UserProfileController, payload *app.UserProfilePayload) (http.ResponseWriter, error) {
func TestUpdateMyProfileUserProfileNotFound(t *testing.T) {
ctx := context.Background()
authObj := &auth.Auth{UserID: fakeHexObjectID}
ctx = auth.SetAuth(ctx, authObj)
userProfilePayload := &app.UserProfilePayload{
FullName: expectedUserFullName,
Email: expectedUserEmail,
}
_, users := test.UpdateMyProfileUserProfileNotFound(t, ctx, service, ctrl, userProfilePayload)
if users == nil {
t.Fatal()
}}