diff --git a/README.md b/README.md index e955e6c..4638ab0 100644 --- a/README.md +++ b/README.md @@ -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 . +``` diff --git a/backend/api_test.go b/backend/api_test.go index 68f4708..2fc70a1 100644 --- a/backend/api_test.go +++ b/backend/api_test.go @@ -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)