Add /user/{userId} (#24)

Closes #9

Reviewed-on: #24
This commit was merged in pull request #24.
This commit is contained in:
2025-05-08 11:31:02 +02:00
parent 1baa1afb07
commit 5a19fc041d
5 changed files with 68 additions and 10 deletions

View File

@@ -5,7 +5,7 @@ import (
)
import "github.com/gavv/httpexpect/v2"
func startServer(t *testing.T) {
func startServer(t *testing.T) *httpexpect.Expect {
config := ServerConfig{
Datasource: ":memory:",
Port: "8181",
@@ -13,13 +13,30 @@ func startServer(t *testing.T) {
}
go start(t.Context(), &config)
<-config.Started
return httpexpect.Default(t, "http://localhost:8181/api")
}
func TestGetUsers(t *testing.T) {
startServer(t)
e := httpexpect.Default(t, "http://localhost:8181/api")
e := startServer(t)
result := e.GET("/users").Expect().Status(200).JSON()
result.Array().Length().IsEqual(2)
result.Path("$[0].name").InList("Seeseemelk", "Huffle")
result.Path("$[1].name").InList("Seeseemelk", "Huffle")
}
func TestGetUser(t *testing.T) {
e := startServer(t)
result := e.GET("/user/1").Expect().Status(200).JSON().Object()
result.Value("name").IsEqual("Seeseemelk")
result.Value("id").IsEqual(1)
}
func TestGetUserUnknown(t *testing.T) {
e := startServer(t)
e.GET("/user/999").Expect().Status(404)
}
func TestGetUserBadId(t *testing.T) {
e := startServer(t)
e.GET("/user/bad-id").Expect().Status(400)
}