Do not extract test url

This commit is contained in:
Sebastiaan de Schaetzen 2025-05-08 15:45:43 +02:00
parent 5f4abb3387
commit a0f0a245c2

View File

@ -9,7 +9,6 @@ import (
const ( const (
TestGoalName = "Test Goal" TestGoalName = "Test Goal"
UserGoalsURL = "/user/1/goals"
) )
func startServer(t *testing.T) *httpexpect.Expect { func startServer(t *testing.T) *httpexpect.Expect {
@ -50,7 +49,7 @@ func TestGetUserBadId(t *testing.T) {
func TestGetUserGoalsWhenNoGoalsPresent(t *testing.T) { func TestGetUserGoalsWhenNoGoalsPresent(t *testing.T) {
e := startServer(t) e := startServer(t)
result := e.GET(UserGoalsURL).Expect().Status(200).JSON().Array() result := e.GET("/user/1/goals").Expect().Status(200).JSON().Array()
result.Length().IsEqual(0) result.Length().IsEqual(0)
} }
@ -74,7 +73,7 @@ func TestCreateUserGoal(t *testing.T) {
"weight": 10, "weight": 10,
} }
response := e.POST(UserGoalsURL). response := e.POST("/user/1/goals").
WithJSON(requestBody). WithJSON(requestBody).
Expect(). Expect().
Status(201). Status(201).
@ -85,7 +84,7 @@ func TestCreateUserGoal(t *testing.T) {
goalId := response.Value("id").Number().Raw() goalId := response.Value("id").Number().Raw()
// Verify the goal exists in the list of goals // Verify the goal exists in the list of goals
goals := e.GET(UserGoalsURL). goals := e.GET("/user/1/goals").
Expect(). Expect().
Status(200). Status(200).
JSON().Array() JSON().Array()
@ -125,7 +124,7 @@ func TestCreateUserGoalInvalidInput(t *testing.T) {
"weight": 10, "weight": 10,
} }
e.POST(UserGoalsURL). e.POST("/user/1/goals").
WithJSON(requestBody). WithJSON(requestBody).
Expect(). Expect().
Status(400) Status(400)
@ -135,7 +134,7 @@ func TestCreateUserGoalInvalidInput(t *testing.T) {
"target": 5000, "target": 5000,
} }
e.POST(UserGoalsURL). e.POST("/user/1/goals").
WithJSON(invalidRequest). WithJSON(invalidRequest).
Expect(). Expect().
Status(400) Status(400)
@ -165,7 +164,7 @@ func TestDeleteUserGoal(t *testing.T) {
"target": 1000, "target": 1000,
"weight": 5, "weight": 5,
} }
response := e.POST(UserGoalsURL). response := e.POST("/user/1/goals").
WithJSON(createRequest). WithJSON(createRequest).
Expect(). Expect().
Status(201). Status(201).
@ -180,7 +179,7 @@ func TestDeleteUserGoal(t *testing.T) {
JSON().Object().Value("message").IsEqual("Goal deleted successfully") JSON().Object().Value("message").IsEqual("Goal deleted successfully")
// Verify the goal no longer exists // Verify the goal no longer exists
goals := e.GET(UserGoalsURL). goals := e.GET("/user/1/goals").
Expect(). Expect().
Status(200). Status(200).
JSON().Array() JSON().Array()