Skip to content

Commit 441547e

Browse files
committed
fix all, admin and user user_controller: Users (#3)
1 parent 1ae931d commit 441547e

File tree

1 file changed

+28
-31
lines changed

1 file changed

+28
-31
lines changed

test/user_controller_test.go

Lines changed: 28 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func TestUsersController(t *testing.T) {
4848
Name: "Sugriwa",
4949
}.Save(db)
5050

51-
// TODO: typing: all, admin and user
51+
// TODO: rows all, admin dan user
5252

5353
test_cases := []struct {
5454
name string
@@ -59,7 +59,7 @@ func TestUsersController(t *testing.T) {
5959
html_heading regex
6060
}{
6161
/*
62-
users: All
62+
users [admin]
6363
*/
6464
{
6565
name: "users [admin] to GET it success: all",
@@ -74,25 +74,21 @@ func TestUsersController(t *testing.T) {
7474
},
7575
},
7676
{
77-
name: "users [user] to GET it success: all",
78-
expect: auth_sugriwa,
79-
url: "/users",
80-
// redirect @route: /user/read/2 [sugriwa: 2]
77+
name: "users [admin] to GET it success: admin",
78+
expect: auth_admin,
79+
url: "/users?admin=all",
8180
// HTTP response status: 200 OK
8281
status: http.StatusOK,
83-
// body heading
84-
html_heading: regex{
85-
must_compile: `<h2 class="mt-4">(.*)</h2>`,
86-
actual: `<h2 class="mt-4">User: Sugriwa</h2>`,
82+
// body navbar
83+
html_navbar: regex{
84+
must_compile: `<a class="btn">(.*)</a>`,
85+
actual: `<a class="btn">ADMIN</a>`,
8786
},
8887
},
89-
/*
90-
users: Admin
91-
*/
9288
{
93-
name: "users [admin] to GET it success: admin",
89+
name: "users [admin] to GET it success: user",
9490
expect: auth_admin,
95-
url: "/users?admin=all",
91+
url: "/users?user=all",
9692
// HTTP response status: 200 OK
9793
status: http.StatusOK,
9894
// body navbar
@@ -102,37 +98,37 @@ func TestUsersController(t *testing.T) {
10298
},
10399
},
104100
{
105-
name: "users [user] to GET it success: admin",
106-
expect: auth_sugriwa,
107-
url: "/users?admin=all",
108-
// redirect @route: /user/read/2 [sugriwa: 2]
109-
// HTTP response status: 200 OK
101+
name: "users [admin] to GET it failed: all",
102+
expect: auth_admin,
103+
url: "/users?false=all",
110104
status: http.StatusOK,
111105
// body heading
112106
html_heading: regex{
113107
must_compile: `<h2 class="mt-4">(.*)</h2>`,
114-
actual: `<h2 class="mt-4">User: Sugriwa</h2>`,
108+
actual: `<h2 class="mt-4">Users: All</h2>`,
115109
},
116110
},
111+
117112
/*
118-
users: User
113+
users [user]
119114
*/
120115
{
121-
name: "users [admin] to GET it success: user",
122-
expect: auth_admin,
123-
url: "/users?user=all",
116+
name: "users [user] to GET it redirect success: sugriwa",
117+
expect: auth_sugriwa,
118+
url: "/users",
119+
// redirect @route: /user/read/2 [sugriwa: 2]
124120
// HTTP response status: 200 OK
125121
status: http.StatusOK,
126-
// body navbar
127-
html_navbar: regex{
128-
must_compile: `<a class="btn">(.*)</a>`,
129-
actual: `<a class="btn">ADMIN</a>`,
122+
// body heading
123+
html_heading: regex{
124+
must_compile: `<h2 class="mt-4">(.*)</h2>`,
125+
actual: `<h2 class="mt-4">User: Sugriwa</h2>`,
130126
},
131127
},
132128
{
133-
name: "users [user] to GET it success: user",
129+
name: "users [user] to GET it redirect success: admin failed",
134130
expect: auth_sugriwa,
135-
url: "/users?user=all",
131+
url: "/users?admin=all",
136132
// redirect @route: /user/read/2 [sugriwa: 2]
137133
// HTTP response status: 200 OK
138134
status: http.StatusOK,
@@ -142,6 +138,7 @@ func TestUsersController(t *testing.T) {
142138
actual: `<h2 class="mt-4">User: Sugriwa</h2>`,
143139
},
144140
},
141+
145142
/*
146143
No Auth
147144
*/

0 commit comments

Comments
 (0)