Skip to content

Commit 633e2d7

Browse files
committed
[14/1/23] testing fix admin controller
1 parent 8ec18b7 commit 633e2d7

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

golang-website-example.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ time="2023-01-14T15:14:15+07:00" level=info msg="models.User: [+]success" route=
3939
v user controller
4040
v home controller
4141
v about controller
42+
- admin controller
4243

4344
2. [v] controller UpdateUser: validation
4445

tests/admin_controller_test.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,18 @@ import (
55
"testing"
66

77
"github.com/gavv/httpexpect/v2"
8+
modelsTest "github.com/ockibagusp/golang-website-example/tests/models"
89
)
910

1011
func TestAdminDeletePermanently(t *testing.T) {
1112
no_auth := setupTestServer(t)
12-
auth_admin := setupTestServerAuth(no_auth, 1)
13-
// auth_sugriwa := setupTestServerAuth(no_auth, 2)
1413

1514
// test for db users
1615
truncateUsers(db)
1716

1817
test_cases := []struct {
1918
name string
20-
expect *httpexpect.Expect // auth or no-auth
19+
expect string // auth or no-auth
2120
url_query string
2221
status int
2322
}{
@@ -26,7 +25,7 @@ func TestAdminDeletePermanently(t *testing.T) {
2625
*/
2726
{
2827
name: "delete permanently [admin] to GET it success: all",
29-
expect: auth_admin,
28+
expect: ADMIN,
3029
// HTTP response status: 200 OK
3130
status: http.StatusOK,
3231
},
@@ -61,18 +60,18 @@ func TestAdminDeletePermanently(t *testing.T) {
6160
6261
var expect = test.expect
6362
*/
64-
var expect *httpexpect.Expect = test.expect
63+
modelsTest.UserSelectTest = test.expect // ADMIN and SUGRIWA
6564

6665
t.Run(test.name, func(t *testing.T) {
6766
// @route: exemple "/admin/delete-permanently?admin=all"
6867
if test.url_query != "" {
69-
result = expect.GET("/admin/delete-permanently").
68+
result = no_auth.GET("/admin/delete-permanently").
7069
WithQuery(test.url_query, "all").
7170
Expect().
7271
Status(test.status)
7372
} else {
7473
// @route: "/admin/delete-permanently"
75-
result = expect.GET("/admin/delete-permanently").
74+
result = no_auth.GET("/admin/delete-permanently").
7675
Expect().
7776
Status(test.status)
7877
}

0 commit comments

Comments
 (0)