|
1 | 1 | package controllers |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bytes" |
4 | 5 | "encoding/gob" |
5 | 6 | "encoding/json" |
6 | 7 | "net/http" |
@@ -122,3 +123,76 @@ func Test_LogoutHandler(t *testing.T) { |
122 | 123 | session, _ := app.SessionStore.Get(req, "session-name") |
123 | 124 | assert.Equal(t, -1, session.Options.MaxAge) |
124 | 125 | } |
| 126 | + |
| 127 | +func Test_AddTaskHandler_WithDueDate(t *testing.T) { |
| 128 | + // Initialize job queue |
| 129 | + GlobalJobQueue = NewJobQueue() |
| 130 | + |
| 131 | + requestBody := map[string]interface{}{ |
| 132 | + "email": "test@example.com", |
| 133 | + "encryptionSecret": "secret", |
| 134 | + "UUID": "test-uuid", |
| 135 | + "description": "Test task", |
| 136 | + "project": "TestProject", |
| 137 | + "priority": "H", |
| 138 | + "due": "2025-12-31", |
| 139 | + "tags": []string{"test", "important"}, |
| 140 | + } |
| 141 | + |
| 142 | + body, _ := json.Marshal(requestBody) |
| 143 | + req, err := http.NewRequest("POST", "/add-task", bytes.NewBuffer(body)) |
| 144 | + assert.NoError(t, err) |
| 145 | + req.Header.Set("Content-Type", "application/json") |
| 146 | + |
| 147 | + rr := httptest.NewRecorder() |
| 148 | + AddTaskHandler(rr, req) |
| 149 | + |
| 150 | + assert.Equal(t, http.StatusAccepted, rr.Code) |
| 151 | +} |
| 152 | + |
| 153 | +func Test_AddTaskHandler_WithoutDueDate(t *testing.T) { |
| 154 | + // Initialize job queue |
| 155 | + GlobalJobQueue = NewJobQueue() |
| 156 | + |
| 157 | + requestBody := map[string]interface{}{ |
| 158 | + "email": "test@example.com", |
| 159 | + "encryptionSecret": "secret", |
| 160 | + "UUID": "test-uuid", |
| 161 | + "description": "Test task without due date", |
| 162 | + "project": "TestProject", |
| 163 | + "priority": "M", |
| 164 | + "tags": []string{"test"}, |
| 165 | + } |
| 166 | + |
| 167 | + body, _ := json.Marshal(requestBody) |
| 168 | + req, err := http.NewRequest("POST", "/add-task", bytes.NewBuffer(body)) |
| 169 | + assert.NoError(t, err) |
| 170 | + req.Header.Set("Content-Type", "application/json") |
| 171 | + |
| 172 | + rr := httptest.NewRecorder() |
| 173 | + AddTaskHandler(rr, req) |
| 174 | + |
| 175 | + assert.Equal(t, http.StatusAccepted, rr.Code) |
| 176 | +} |
| 177 | + |
| 178 | +func Test_AddTaskHandler_MissingDescription(t *testing.T) { |
| 179 | + requestBody := map[string]interface{}{ |
| 180 | + "email": "test@example.com", |
| 181 | + "encryptionSecret": "secret", |
| 182 | + "UUID": "test-uuid", |
| 183 | + "description": "", |
| 184 | + "project": "TestProject", |
| 185 | + "priority": "H", |
| 186 | + } |
| 187 | + |
| 188 | + body, _ := json.Marshal(requestBody) |
| 189 | + req, err := http.NewRequest("POST", "/add-task", bytes.NewBuffer(body)) |
| 190 | + assert.NoError(t, err) |
| 191 | + req.Header.Set("Content-Type", "application/json") |
| 192 | + |
| 193 | + rr := httptest.NewRecorder() |
| 194 | + AddTaskHandler(rr, req) |
| 195 | + |
| 196 | + assert.Equal(t, http.StatusBadRequest, rr.Code) |
| 197 | + assert.Contains(t, rr.Body.String(), "Description is required") |
| 198 | +} |
0 commit comments