test: add WebSocket integration tests

Add comprehensive WebSocket test coverage:
- TestWebSocketConnection: Basic connection and JWT auth
- TestWebSocketDeviceAuth: Device token authentication
- TestWebSocketProgressBroadcast: Real-time update delivery
- TestWebSocketPingPong: Heartbeat mechanism
- TestWebSocketConnectionLimit: Multiple concurrent connections
- TestWebSocketInvalidToken: Rejection of invalid tokens
- Helper function for test media item creation

Update test helpers to create ConnectionManager for tests.
Tests verify WebSocket connection, authentication, and
real-time progress broadcast functionality.
This commit is contained in:
2026-01-30 21:48:30 -05:00
parent d77585a6f5
commit 77d683277a
4 changed files with 288 additions and 15 deletions
+12 -9
View File
@@ -125,8 +125,8 @@ func TestPhase1Integration(t *testing.T) {
var adminToken string
t.Run("LoginAsAdmin", func(t *testing.T) {
loginReq := map[string]interface{}{
"identifier": "admin@bookmann.test",
"password": "SecurePass123!",
"login": "admin@bookmann.test",
"password": "SecurePass123!",
}
body, _ := json.Marshal(loginReq)
@@ -139,7 +139,9 @@ func TestPhase1Integration(t *testing.T) {
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
adminToken = result["token"].(string)
token, ok := result["access_token"].(string)
assert.True(t, ok, "Should have access_token")
adminToken = token
assert.NotEmpty(t, adminToken)
})
@@ -149,7 +151,7 @@ func TestPhase1Integration(t *testing.T) {
libraryReq := map[string]interface{}{
"name": "Test Library",
"description": "Integration test library",
"type": "ebook",
"type": "ebooks",
}
body, _ := json.Marshal(libraryReq)
@@ -233,7 +235,8 @@ func TestPhase1Integration(t *testing.T) {
// Step 5: List media-items
t.Run("Step5_ListMediaItems", func(t *testing.T) {
req, _ := http.NewRequest("GET", baseTestURL+"/media-items?limit=50", nil)
url := fmt.Sprintf("%s/libraries/%s/media-items", baseTestURL, libraryID)
req, _ := http.NewRequest("GET", url, nil)
req.Header.Set("Authorization", "Bearer "+adminToken)
client := &http.Client{}
@@ -246,11 +249,11 @@ func TestPhase1Integration(t *testing.T) {
var result map[string]interface{}
json.NewDecoder(resp.Body).Decode(&result)
items, ok := result["items"].([]interface{})
assert.True(t, ok, "Items field should exist")
assert.True(t, len(items) >= 0, "Should return items array")
data, ok := result["data"].([]interface{})
assert.True(t, ok, "Data field should exist")
assert.True(t, len(data) >= 0, "Should return data array")
t.Logf("✅ Step 5 PASSED: Media items listed (count: %d)", len(items))
t.Logf("✅ Step 5 PASSED: Media items listed (count: %d)", len(data))
})
}