Disable schedules
All checks were successful
Backend Build and Test / build (push) Successful in 7m22s

They aren't functional, and we have a better alternative.
This commit is contained in:
Sebastiaan de Schaetzen 2025-10-08 20:13:29 +02:00
parent 8e2e5e6f71
commit 7335eb083f
2 changed files with 52 additions and 47 deletions

View File

@ -286,53 +286,53 @@ func TestCreateTask(t *testing.T) {
responseWithUser.Value("id").Number().IsEqual(2) responseWithUser.Value("id").Number().IsEqual(2)
} }
func TestCreateScheduleTask(t *testing.T) { //func TestCreateScheduleTask(t *testing.T) {
e := startServer(t) // e := startServer(t)
//
// Create a new task without assigned user // // Create a new task without assigned user
requestBody := map[string]interface{}{ // requestBody := map[string]interface{}{
"name": "Test Task", // "name": "Test Task",
"reward": 100, // "reward": 100,
"schedule": "0 */5 * * * *", // "schedule": "0 */5 * * * *",
} // }
//
response := e.POST("/tasks"). // response := e.POST("/tasks").
WithJSON(requestBody). // WithJSON(requestBody).
Expect(). // Expect().
Status(201). // Expect Created status // Status(201). // Expect Created status
JSON().Object() // JSON().Object()
//
requestBody["schedule"] = "every 5 seconds" // requestBody["schedule"] = "every 5 seconds"
e.POST("/tasks").WithJSON(requestBody).Expect().Status(400) // e.POST("/tasks").WithJSON(requestBody).Expect().Status(400)
//
// Verify the response has an ID // // Verify the response has an ID
response.ContainsKey("id") // response.ContainsKey("id")
response.Value("id").Number().IsEqual(1) // response.Value("id").Number().IsEqual(1)
//
e.GET("/tasks").Expect().Status(200).JSON().Array().Length().IsEqual(1) // e.GET("/tasks").Expect().Status(200).JSON().Array().Length().IsEqual(1)
//
// Get task // // Get task
result := e.GET("/task/1").Expect().Status(200).JSON().Object() // result := e.GET("/task/1").Expect().Status(200).JSON().Object()
result.Value("id").IsEqual(1) // result.Value("id").IsEqual(1)
result.Value("name").IsEqual("Test Task") // result.Value("name").IsEqual("Test Task")
result.Value("schedule").IsEqual("0 */5 * * * *") // result.Value("schedule").IsEqual("0 */5 * * * *")
result.Value("reward").IsEqual(100) // result.Value("reward").IsEqual(100)
result.Value("assigned").IsNull() // result.Value("assigned").IsNull()
//
// Complete the task // // Complete the task
e.POST("/task/1/complete").Expect().Status(200) // e.POST("/task/1/complete").Expect().Status(200)
//
// Set expires date to 1 second in the past // // 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() // 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 // // Verify a new task is created
newTask := e.GET("/task/2").Expect().Status(200).JSON().Object() // newTask := e.GET("/task/2").Expect().Status(200).JSON().Object()
newTask.Value("id").IsEqual(2) // newTask.Value("id").IsEqual(2)
newTask.Value("name").IsEqual("Test Task") // newTask.Value("name").IsEqual("Test Task")
newTask.Value("schedule").IsEqual("0 */5 * * * *") // newTask.Value("schedule").IsEqual("0 */5 * * * *")
newTask.Value("reward").IsEqual(100) // newTask.Value("reward").IsEqual(100)
newTask.Value("assigned").IsNull() // newTask.Value("assigned").IsNull()
} //}
func TestDeleteTask(t *testing.T) { func TestDeleteTask(t *testing.T) {
e := startServer(t) e := startServer(t)

View File

@ -439,6 +439,11 @@ func createTask(c *gin.Context) {
return 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 assigned is not nil, check if user exists
if taskRequest.Assigned != nil { if taskRequest.Assigned != nil {
exists, err := db.UserExists(*taskRequest.Assigned) exists, err := db.UserExists(*taskRequest.Assigned)