Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
136 changes: 136 additions & 0 deletions integration_test/retrospective_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package integration_test

import (
"encoding/json"
"net/http"
"testing"

"api/types"

"github.com/google/uuid"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -242,3 +245,136 @@ func TestDeleteRetrospective(t *testing.T) {
assert.Equal(t, http.StatusNotFound, resp.StatusCode)
})
}

func TestExportRetrospective(t *testing.T) {
client := NewTestClient(t)

t.Run("successfully exports retrospective as JSON", func(t *testing.T) {
retro, err := client.SetupRetrospective("Export JSON Test", "Test Description")
require.NoError(t, err)

// Create a question and answer for richer export
question, resp, err := client.CreateQuestion("What went well?")
require.NoError(t, err)
resp.Body.Close()

_, resp, err = client.CreateAnswer(question.ID, "Great teamwork")
require.NoError(t, err)
resp.Body.Close()

// Export as JSON
data, resp, err := client.ExportRetrospective(retro.ID, types.ExportTypeJSON)
require.NoError(t, err)
defer resp.Body.Close()

assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "application/json", resp.Header.Get("Content-Type"))
assert.Contains(t, resp.Header.Get("Content-Disposition"), "attachment")
assert.Contains(t, resp.Header.Get("Content-Disposition"), ".json")

// Verify JSON content
var exportedRetro types.Retrospective
err = json.Unmarshal(data, &exportedRetro)
require.NoError(t, err)
assert.Equal(t, retro.ID, exportedRetro.ID)
assert.Equal(t, "Export JSON Test", exportedRetro.Name)
assert.Len(t, exportedRetro.Questions, 1)
assert.Len(t, exportedRetro.Questions[0].Answers, 1)
})

t.Run("successfully exports retrospective as Markdown", func(t *testing.T) {
retro, err := client.SetupRetrospective("Export Markdown Test", "Markdown Description")
require.NoError(t, err)

// Create a question and answer
question, resp, err := client.CreateQuestion("What could be improved?")
require.NoError(t, err)
resp.Body.Close()

_, resp, err = client.CreateAnswer(question.ID, "Better communication")
require.NoError(t, err)
resp.Body.Close()

// Export as Markdown
data, resp, err := client.ExportRetrospective(retro.ID, types.ExportTypeMarkdown)
require.NoError(t, err)
defer resp.Body.Close()

assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "text/markdown", resp.Header.Get("Content-Type"))
assert.Contains(t, resp.Header.Get("Content-Disposition"), "attachment")
assert.Contains(t, resp.Header.Get("Content-Disposition"), ".md")

// Verify Markdown content
content := string(data)
assert.Contains(t, content, "# Simple Retro")
assert.Contains(t, content, "## Export Markdown Test")
assert.Contains(t, content, "Markdown Description")
assert.Contains(t, content, "### What could be improved?")
assert.Contains(t, content, "- Better communication")
})

t.Run("successfully exports retrospective as PDF", func(t *testing.T) {
retro, err := client.SetupRetrospective("Export PDF Test", "PDF Description")
require.NoError(t, err)

// Create a question and answer
question, resp, err := client.CreateQuestion("Action items?")
require.NoError(t, err)
resp.Body.Close()

_, resp, err = client.CreateAnswer(question.ID, "Schedule follow-up meeting")
require.NoError(t, err)
resp.Body.Close()

// Export as PDF
data, resp, err := client.ExportRetrospective(retro.ID, types.ExportTypePDF)
require.NoError(t, err)
defer resp.Body.Close()

assert.Equal(t, http.StatusOK, resp.StatusCode)
assert.Equal(t, "application/pdf", resp.Header.Get("Content-Type"))
assert.Contains(t, resp.Header.Get("Content-Disposition"), "attachment")
assert.Contains(t, resp.Header.Get("Content-Disposition"), ".pdf")

// Verify PDF content (check PDF magic bytes)
assert.True(t, len(data) > 4)
assert.Equal(t, "%PDF", string(data[:4]))
})

t.Run("exports empty retrospective", func(t *testing.T) {
retro, err := client.SetupRetrospective("Empty Export Test", "No questions")
require.NoError(t, err)

// Export as Markdown
data, resp, err := client.ExportRetrospective(retro.ID, types.ExportTypeMarkdown)
require.NoError(t, err)
defer resp.Body.Close()

assert.Equal(t, http.StatusOK, resp.StatusCode)
content := string(data)
assert.Contains(t, content, "# Simple Retro")
assert.Contains(t, content, "## Empty Export Test")
})

t.Run("returns 404 for non-existent retrospective", func(t *testing.T) {
nonExistentID := uuid.New()
_, resp, err := client.ExportRetrospective(nonExistentID, types.ExportTypeJSON)
require.NoError(t, err)
defer resp.Body.Close()

assert.Equal(t, http.StatusNotFound, resp.StatusCode)
})

t.Run("returns 400 for unknown export type", func(t *testing.T) {
retro, err := client.SetupRetrospective("Unknown Type Test", "Description")
require.NoError(t, err)

// Export with unknown type
_, resp, err := client.ExportRetrospective(retro.ID, types.ExportType("UNKNOWN"))
require.NoError(t, err)
defer resp.Body.Close()

assert.Equal(t, http.StatusBadRequest, resp.StatusCode)
})
}
24 changes: 24 additions & 0 deletions integration_test/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,3 +403,27 @@ func GenerateString(length int) string {
}
return string(result)
}

// ExportRetrospective exports a retrospective in the specified format
func (c *TestClient) ExportRetrospective(retroID uuid.UUID, exportType types.ExportType) ([]byte, *http.Response, error) {
reqBody := types.RetrospectiveExportRequest{
RetrospectiveID: retroID,
ExportType: exportType,
}

resp, err := c.DoRequest(http.MethodPost, "/api/retrospective/export", reqBody, map[string]string{})
if err != nil {
return nil, nil, err
}

if resp.StatusCode != http.StatusOK {
return nil, resp, nil
}

var buf bytes.Buffer
if _, err := buf.ReadFrom(resp.Body); err != nil {
return nil, resp, err
}

return buf.Bytes(), resp, nil
}