Working on test

This commit is contained in:
Sebastiaan de Schaetzen 2025-05-17 16:13:37 +02:00
parent d9521fc59b
commit 05921335f6
2 changed files with 41 additions and 0 deletions

View File

@ -1,2 +1,9 @@
# Allowance Planner 2000
An improved Allowance Planner app.
## Running backend
In order to run the backend, go to the `backend directory and run:
```bash
$ go run .
```

View File

@ -520,6 +520,40 @@ func TestPutAllowanceById(t *testing.T) {
result.Value("weight").IsEqual(15)
}
func TestCompleteTask(t *testing.T) {
e := startServer(t)
createTestTask(e)
// Create a task
requestBody := map[string]interface{}{
"name": "Test Task",
"reward": 100,
}
e.POST("/tasks").WithJSON(requestBody).Expect().Status(201)
// Create two allowance goals
e.POST("/user/1/allowance").WithJSON(CreateAllowanceRequest{
Name: "Test Allowance 1",
Target: 1000,
Weight: 50,
}).Expect().Status(200)
e.POST("/user/1/allowance").WithJSON(CreateAllowanceRequest{
Name: "Test Allowance 1",
Target: 1000,
Weight: 25,
}).Expect().Status(200)
e.PUT("/user/1/allowance/0").WithJSON(UpdateAllowanceRequest{
Weight: 25,
})
// Complete the task
e.POST("/task/1/complete").Expect().Status(200)
// Verify the task is marked as completed
result := e.GET("/task/1").Expect().Status(200).JSON().Object()
result.Value("completed").Boolean().IsTrue()
}
func getDelta(base time.Time, delta float64) (time.Time, time.Time) {
start := base.Add(-time.Duration(delta) * time.Second)
end := base.Add(time.Duration(delta) * time.Second)