mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-29 23:36:12 +00:00
Remove ALL Sora code — client, gateway, generation, S3 storage, accounts, media, SDK, quota, scheduling, billing, OAuth, settings, and frontend UI. Backend: 60+ files deleted/cleaned, including service layer (scheduling, billing, token provider), handler layer (client/gateway handlers, DTOs), repository layer (sora repos), config, wire DI, routes, domain constants. Frontend: 14 files deleted + 29 files cleaned, including components, views, API clients, composables, i18n keys, types, router entries. Cloudflare challenge detection migrated from soraerror to httputil package. Migration files retained (046/047/063/070) to preserve DB migration history. 136 files changed, ~24,300 lines removed. All tests pass.
60 lines
1.7 KiB
Go
60 lines
1.7 KiB
Go
//go:build unit
|
|
|
|
package service
|
|
|
|
import (
|
|
"encoding/json"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestCreateGeminiTestPayload_ImageModel(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
payload := createGeminiTestPayload("gemini-2.5-flash-image", "draw a tiny robot")
|
|
|
|
var parsed struct {
|
|
Contents []struct {
|
|
Parts []struct {
|
|
Text string `json:"text"`
|
|
} `json:"parts"`
|
|
} `json:"contents"`
|
|
GenerationConfig struct {
|
|
ResponseModalities []string `json:"responseModalities"`
|
|
ImageConfig struct {
|
|
AspectRatio string `json:"aspectRatio"`
|
|
} `json:"imageConfig"`
|
|
} `json:"generationConfig"`
|
|
}
|
|
|
|
require.NoError(t, json.Unmarshal(payload, &parsed))
|
|
require.Len(t, parsed.Contents, 1)
|
|
require.Len(t, parsed.Contents[0].Parts, 1)
|
|
require.Equal(t, "draw a tiny robot", parsed.Contents[0].Parts[0].Text)
|
|
require.Equal(t, []string{"TEXT", "IMAGE"}, parsed.GenerationConfig.ResponseModalities)
|
|
require.Equal(t, "1:1", parsed.GenerationConfig.ImageConfig.AspectRatio)
|
|
}
|
|
|
|
func TestProcessGeminiStream_EmitsImageEvent(t *testing.T) {
|
|
t.Parallel()
|
|
gin.SetMode(gin.TestMode)
|
|
|
|
ctx, recorder := newTestContext()
|
|
svc := &AccountTestService{}
|
|
|
|
stream := strings.NewReader("data: {\"candidates\":[{\"content\":{\"parts\":[{\"text\":\"ok\"},{\"inlineData\":{\"mimeType\":\"image/png\",\"data\":\"QUJD\"}}]}}]}\n\ndata: [DONE]\n\n")
|
|
|
|
err := svc.processGeminiStream(ctx, stream)
|
|
require.NoError(t, err)
|
|
|
|
body := recorder.Body.String()
|
|
require.Contains(t, body, "\"type\":\"content\"")
|
|
require.Contains(t, body, "\"text\":\"ok\"")
|
|
require.Contains(t, body, "\"type\":\"image\"")
|
|
require.Contains(t, body, "\"image_url\":\"data:image/png;base64,QUJD\"")
|
|
require.Contains(t, body, "\"mime_type\":\"image/png\"")
|
|
}
|