mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-11-03 08:40:36 +00:00
76 lines
2.3 KiB
Go
76 lines
2.3 KiB
Go
package handler
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/Wei-Shaw/sub2api/internal/service"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestShouldRecordGrokMediaUsage(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
endpoint service.GrokMediaEndpoint
|
|
model string
|
|
want bool
|
|
}{
|
|
{
|
|
name: "image generation records usage",
|
|
endpoint: service.GrokMediaEndpointImagesGenerations,
|
|
model: "grok-imagine",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "image edit records usage",
|
|
endpoint: service.GrokMediaEndpointImagesEdits,
|
|
model: "grok-imagine-edit",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "video generation records usage",
|
|
endpoint: service.GrokMediaEndpointVideosGenerations,
|
|
model: "grok-imagine-video-1.5",
|
|
want: true,
|
|
},
|
|
{
|
|
name: "video status skips empty model usage",
|
|
endpoint: service.GrokMediaEndpointVideoStatus,
|
|
model: "",
|
|
want: false,
|
|
},
|
|
{
|
|
name: "generation skips usage without model",
|
|
endpoint: service.GrokMediaEndpointImagesGenerations,
|
|
model: " ",
|
|
want: false,
|
|
},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
require.Equal(t, tt.want, shouldRecordGrokMediaUsage(tt.endpoint, tt.model))
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestGrokMediaRequiredCapability(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
endpoint service.GrokMediaEndpoint
|
|
want service.OpenAIEndpointCapability
|
|
}{
|
|
{name: "image generation", endpoint: service.GrokMediaEndpointImagesGenerations, want: service.OpenAIEndpointCapabilityGrokMediaGeneration},
|
|
{name: "image edit", endpoint: service.GrokMediaEndpointImagesEdits, want: service.OpenAIEndpointCapabilityGrokMediaGeneration},
|
|
{name: "video generation", endpoint: service.GrokMediaEndpointVideosGenerations, want: service.OpenAIEndpointCapabilityGrokMediaGeneration},
|
|
{name: "video edit", endpoint: service.GrokMediaEndpointVideosEdits, want: service.OpenAIEndpointCapabilityGrokMediaGeneration},
|
|
{name: "video extension", endpoint: service.GrokMediaEndpointVideosExtensions, want: service.OpenAIEndpointCapabilityGrokMediaGeneration},
|
|
{name: "video status preserves lookup", endpoint: service.GrokMediaEndpointVideoStatus, want: ""},
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
require.Equal(t, tt.want, grokMediaRequiredCapability(tt.endpoint))
|
|
})
|
|
}
|
|
}
|