statping/handlers/users_test.go

58 lines
1.2 KiB
Go
Raw Normal View History

2020-03-04 10:29:00 +00:00
package handlers
import (
"github.com/stretchr/testify/require"
"testing"
)
func TestApiUsersRoutes(t *testing.T) {
tests := []HTTPTest{
{
Name: "Statping All Users",
URL: "/api/users",
Method: "GET",
ExpectedStatus: 200,
ResponseLen: 1,
}, {
Name: "Statping Create User",
URL: "/api/users",
HttpHeaders: []string{"Content-Type=application/json"},
Method: "POST",
Body: `{
"username": "adminuser2",
"email": "info@adminemail.com",
"password": "passsword123",
"admin": true
}`,
ExpectedStatus: 200,
}, {
Name: "Statping View User",
URL: "/api/users/1",
Method: "GET",
ExpectedStatus: 200,
}, {
Name: "Statping Update User",
URL: "/api/users/1",
Method: "POST",
Body: `{
"username": "adminupdated",
"email": "info@email.com",
"password": "password12345",
"admin": true
}`,
ExpectedStatus: 200,
}, {
Name: "Statping Delete User",
URL: "/api/users/1",
Method: "DELETE",
ExpectedStatus: 200,
}}
for _, v := range tests {
t.Run(v.Name, func(t *testing.T) {
_, t, err := RunHTTPTest(v, t)
require.Nil(t, err)
})
}
}