From 7335eb083f3ae7e38b4109a27b978811624de23c Mon Sep 17 00:00:00 2001 From: Sebastiaan de Schaetzen Date: Wed, 8 Oct 2025 20:13:29 +0200 Subject: [PATCH] Disable schedules They aren't functional, and we have a better alternative. --- backend/api_test.go | 94 ++++++++++++++++++++++----------------------- backend/main.go | 5 +++ 2 files changed, 52 insertions(+), 47 deletions(-) diff --git a/backend/api_test.go b/backend/api_test.go index a09ebcd..9c68c89 100644 --- a/backend/api_test.go +++ b/backend/api_test.go @@ -286,53 +286,53 @@ func TestCreateTask(t *testing.T) { responseWithUser.Value("id").Number().IsEqual(2) } -func TestCreateScheduleTask(t *testing.T) { - e := startServer(t) - - // Create a new task without assigned user - requestBody := map[string]interface{}{ - "name": "Test Task", - "reward": 100, - "schedule": "0 */5 * * * *", - } - - response := e.POST("/tasks"). - WithJSON(requestBody). - Expect(). - Status(201). // Expect Created status - JSON().Object() - - requestBody["schedule"] = "every 5 seconds" - e.POST("/tasks").WithJSON(requestBody).Expect().Status(400) - - // Verify the response has an ID - response.ContainsKey("id") - response.Value("id").Number().IsEqual(1) - - e.GET("/tasks").Expect().Status(200).JSON().Array().Length().IsEqual(1) - - // Get task - result := e.GET("/task/1").Expect().Status(200).JSON().Object() - result.Value("id").IsEqual(1) - result.Value("name").IsEqual("Test Task") - result.Value("schedule").IsEqual("0 */5 * * * *") - result.Value("reward").IsEqual(100) - result.Value("assigned").IsNull() - - // Complete the task - e.POST("/task/1/complete").Expect().Status(200) - - // Set expires date to 1 second in the past - db.db.Query("update tasks set next_run = ? where id = 1").Bind(time.Now().Add(10 * -time.Minute).Unix()).MustExec() - - // Verify a new task is created - newTask := e.GET("/task/2").Expect().Status(200).JSON().Object() - newTask.Value("id").IsEqual(2) - newTask.Value("name").IsEqual("Test Task") - newTask.Value("schedule").IsEqual("0 */5 * * * *") - newTask.Value("reward").IsEqual(100) - newTask.Value("assigned").IsNull() -} +//func TestCreateScheduleTask(t *testing.T) { +// e := startServer(t) +// +// // Create a new task without assigned user +// requestBody := map[string]interface{}{ +// "name": "Test Task", +// "reward": 100, +// "schedule": "0 */5 * * * *", +// } +// +// response := e.POST("/tasks"). +// WithJSON(requestBody). +// Expect(). +// Status(201). // Expect Created status +// JSON().Object() +// +// requestBody["schedule"] = "every 5 seconds" +// e.POST("/tasks").WithJSON(requestBody).Expect().Status(400) +// +// // Verify the response has an ID +// response.ContainsKey("id") +// response.Value("id").Number().IsEqual(1) +// +// e.GET("/tasks").Expect().Status(200).JSON().Array().Length().IsEqual(1) +// +// // Get task +// result := e.GET("/task/1").Expect().Status(200).JSON().Object() +// result.Value("id").IsEqual(1) +// result.Value("name").IsEqual("Test Task") +// result.Value("schedule").IsEqual("0 */5 * * * *") +// result.Value("reward").IsEqual(100) +// result.Value("assigned").IsNull() +// +// // Complete the task +// e.POST("/task/1/complete").Expect().Status(200) +// +// // Set expires date to 1 second in the past +// db.db.Query("update tasks set next_run = ? where id = 1").Bind(time.Now().Add(10 * -time.Minute).Unix()).MustExec() +// +// // Verify a new task is created +// newTask := e.GET("/task/2").Expect().Status(200).JSON().Object() +// newTask.Value("id").IsEqual(2) +// newTask.Value("name").IsEqual("Test Task") +// newTask.Value("schedule").IsEqual("0 */5 * * * *") +// newTask.Value("reward").IsEqual(100) +// newTask.Value("assigned").IsNull() +//} func TestDeleteTask(t *testing.T) { e := startServer(t) diff --git a/backend/main.go b/backend/main.go index 5d1dd38..132a4db 100644 --- a/backend/main.go +++ b/backend/main.go @@ -439,6 +439,11 @@ func createTask(c *gin.Context) { return } + if taskRequest.Schedule != nil { + c.JSON(http.StatusBadRequest, gin.H{"error": "Schedules are not yet supported"}) + return + } + // If assigned is not nil, check if user exists if taskRequest.Assigned != nil { exists, err := db.UserExists(*taskRequest.Assigned)