61 lines
1.3 KiB
Go
61 lines
1.3 KiB
Go
package main
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/json"
|
|
"net/http"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestKillmailIDsEndpoint(t *testing.T) {
|
|
// Start server in background
|
|
go func() {
|
|
StartAPIServer("3002")
|
|
}()
|
|
|
|
// Wait for server to start
|
|
time.Sleep(2 * time.Second)
|
|
|
|
// Test with ship=24692 and module=26914
|
|
reqBody := APIKillmailIDsRequest{
|
|
Filters: AnalyticsFilters{
|
|
VictimShipTypeID: []int32{24692},
|
|
HasModule: &ModuleFilter{
|
|
ModuleID: 26914,
|
|
},
|
|
},
|
|
Limit: 100,
|
|
Offset: 0,
|
|
}
|
|
|
|
jsonData, err := json.Marshal(reqBody)
|
|
if err != nil {
|
|
t.Fatalf("Failed to marshal request: %v", err)
|
|
}
|
|
|
|
resp, err := http.Post("http://localhost:3002/api/analytics/killmails", "application/json", bytes.NewBuffer(jsonData))
|
|
if err != nil {
|
|
t.Fatalf("Failed to make request: %v", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode != http.StatusOK {
|
|
bodyBytes := make([]byte, 1024)
|
|
resp.Body.Read(bodyBytes)
|
|
t.Fatalf("Expected status 200, got %d. Body: %s", resp.StatusCode, string(bodyBytes))
|
|
}
|
|
|
|
var results []int64
|
|
if err := json.NewDecoder(resp.Body).Decode(&results); err != nil {
|
|
t.Fatalf("Failed to decode response: %v", err)
|
|
}
|
|
|
|
if len(results) == 0 {
|
|
t.Fatalf("Expected at least one killmail ID, got 0")
|
|
}
|
|
|
|
t.Logf("Successfully retrieved %d killmail IDs", len(results))
|
|
t.Logf("First killmail ID: %d", results[0])
|
|
}
|