|
1 | 1 | package integration_test |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "encoding/json" |
4 | 5 | "net/http" |
5 | 6 | "testing" |
6 | 7 |
|
| 8 | + "api/types" |
| 9 | + |
7 | 10 | "github.com/google/uuid" |
8 | 11 | "github.com/stretchr/testify/assert" |
9 | 12 | "github.com/stretchr/testify/require" |
@@ -242,3 +245,136 @@ func TestDeleteRetrospective(t *testing.T) { |
242 | 245 | assert.Equal(t, http.StatusNotFound, resp.StatusCode) |
243 | 246 | }) |
244 | 247 | } |
| 248 | + |
| 249 | +func TestExportRetrospective(t *testing.T) { |
| 250 | + client := NewTestClient(t) |
| 251 | + |
| 252 | + t.Run("successfully exports retrospective as JSON", func(t *testing.T) { |
| 253 | + retro, err := client.SetupRetrospective("Export JSON Test", "Test Description") |
| 254 | + require.NoError(t, err) |
| 255 | + |
| 256 | + // Create a question and answer for richer export |
| 257 | + question, resp, err := client.CreateQuestion("What went well?") |
| 258 | + require.NoError(t, err) |
| 259 | + resp.Body.Close() |
| 260 | + |
| 261 | + _, resp, err = client.CreateAnswer(question.ID, "Great teamwork") |
| 262 | + require.NoError(t, err) |
| 263 | + resp.Body.Close() |
| 264 | + |
| 265 | + // Export as JSON |
| 266 | + data, resp, err := client.ExportRetrospective(retro.ID, types.ExportTypeJSON) |
| 267 | + require.NoError(t, err) |
| 268 | + defer resp.Body.Close() |
| 269 | + |
| 270 | + assert.Equal(t, http.StatusOK, resp.StatusCode) |
| 271 | + assert.Equal(t, "application/json", resp.Header.Get("Content-Type")) |
| 272 | + assert.Contains(t, resp.Header.Get("Content-Disposition"), "attachment") |
| 273 | + assert.Contains(t, resp.Header.Get("Content-Disposition"), ".json") |
| 274 | + |
| 275 | + // Verify JSON content |
| 276 | + var exportedRetro types.Retrospective |
| 277 | + err = json.Unmarshal(data, &exportedRetro) |
| 278 | + require.NoError(t, err) |
| 279 | + assert.Equal(t, retro.ID, exportedRetro.ID) |
| 280 | + assert.Equal(t, "Export JSON Test", exportedRetro.Name) |
| 281 | + assert.Len(t, exportedRetro.Questions, 1) |
| 282 | + assert.Len(t, exportedRetro.Questions[0].Answers, 1) |
| 283 | + }) |
| 284 | + |
| 285 | + t.Run("successfully exports retrospective as Markdown", func(t *testing.T) { |
| 286 | + retro, err := client.SetupRetrospective("Export Markdown Test", "Markdown Description") |
| 287 | + require.NoError(t, err) |
| 288 | + |
| 289 | + // Create a question and answer |
| 290 | + question, resp, err := client.CreateQuestion("What could be improved?") |
| 291 | + require.NoError(t, err) |
| 292 | + resp.Body.Close() |
| 293 | + |
| 294 | + _, resp, err = client.CreateAnswer(question.ID, "Better communication") |
| 295 | + require.NoError(t, err) |
| 296 | + resp.Body.Close() |
| 297 | + |
| 298 | + // Export as Markdown |
| 299 | + data, resp, err := client.ExportRetrospective(retro.ID, types.ExportTypeMarkdown) |
| 300 | + require.NoError(t, err) |
| 301 | + defer resp.Body.Close() |
| 302 | + |
| 303 | + assert.Equal(t, http.StatusOK, resp.StatusCode) |
| 304 | + assert.Equal(t, "text/markdown", resp.Header.Get("Content-Type")) |
| 305 | + assert.Contains(t, resp.Header.Get("Content-Disposition"), "attachment") |
| 306 | + assert.Contains(t, resp.Header.Get("Content-Disposition"), ".md") |
| 307 | + |
| 308 | + // Verify Markdown content |
| 309 | + content := string(data) |
| 310 | + assert.Contains(t, content, "# Simple Retro") |
| 311 | + assert.Contains(t, content, "## Export Markdown Test") |
| 312 | + assert.Contains(t, content, "Markdown Description") |
| 313 | + assert.Contains(t, content, "### What could be improved?") |
| 314 | + assert.Contains(t, content, "- Better communication") |
| 315 | + }) |
| 316 | + |
| 317 | + t.Run("successfully exports retrospective as PDF", func(t *testing.T) { |
| 318 | + retro, err := client.SetupRetrospective("Export PDF Test", "PDF Description") |
| 319 | + require.NoError(t, err) |
| 320 | + |
| 321 | + // Create a question and answer |
| 322 | + question, resp, err := client.CreateQuestion("Action items?") |
| 323 | + require.NoError(t, err) |
| 324 | + resp.Body.Close() |
| 325 | + |
| 326 | + _, resp, err = client.CreateAnswer(question.ID, "Schedule follow-up meeting") |
| 327 | + require.NoError(t, err) |
| 328 | + resp.Body.Close() |
| 329 | + |
| 330 | + // Export as PDF |
| 331 | + data, resp, err := client.ExportRetrospective(retro.ID, types.ExportTypePDF) |
| 332 | + require.NoError(t, err) |
| 333 | + defer resp.Body.Close() |
| 334 | + |
| 335 | + assert.Equal(t, http.StatusOK, resp.StatusCode) |
| 336 | + assert.Equal(t, "application/pdf", resp.Header.Get("Content-Type")) |
| 337 | + assert.Contains(t, resp.Header.Get("Content-Disposition"), "attachment") |
| 338 | + assert.Contains(t, resp.Header.Get("Content-Disposition"), ".pdf") |
| 339 | + |
| 340 | + // Verify PDF content (check PDF magic bytes) |
| 341 | + assert.True(t, len(data) > 4) |
| 342 | + assert.Equal(t, "%PDF", string(data[:4])) |
| 343 | + }) |
| 344 | + |
| 345 | + t.Run("exports empty retrospective", func(t *testing.T) { |
| 346 | + retro, err := client.SetupRetrospective("Empty Export Test", "No questions") |
| 347 | + require.NoError(t, err) |
| 348 | + |
| 349 | + // Export as Markdown |
| 350 | + data, resp, err := client.ExportRetrospective(retro.ID, types.ExportTypeMarkdown) |
| 351 | + require.NoError(t, err) |
| 352 | + defer resp.Body.Close() |
| 353 | + |
| 354 | + assert.Equal(t, http.StatusOK, resp.StatusCode) |
| 355 | + content := string(data) |
| 356 | + assert.Contains(t, content, "# Simple Retro") |
| 357 | + assert.Contains(t, content, "## Empty Export Test") |
| 358 | + }) |
| 359 | + |
| 360 | + t.Run("returns 404 for non-existent retrospective", func(t *testing.T) { |
| 361 | + nonExistentID := uuid.New() |
| 362 | + _, resp, err := client.ExportRetrospective(nonExistentID, types.ExportTypeJSON) |
| 363 | + require.NoError(t, err) |
| 364 | + defer resp.Body.Close() |
| 365 | + |
| 366 | + assert.Equal(t, http.StatusNotFound, resp.StatusCode) |
| 367 | + }) |
| 368 | + |
| 369 | + t.Run("returns 400 for unknown export type", func(t *testing.T) { |
| 370 | + retro, err := client.SetupRetrospective("Unknown Type Test", "Description") |
| 371 | + require.NoError(t, err) |
| 372 | + |
| 373 | + // Export with unknown type |
| 374 | + _, resp, err := client.ExportRetrospective(retro.ID, types.ExportType("UNKNOWN")) |
| 375 | + require.NoError(t, err) |
| 376 | + defer resp.Body.Close() |
| 377 | + |
| 378 | + assert.Equal(t, http.StatusBadRequest, resp.StatusCode) |
| 379 | + }) |
| 380 | +} |
0 commit comments