1b01caac0f
- Implemented a new prompts loader in `loader.go` to manage prompt templates and configurations. - Introduced caching mechanism for prompt configurations to optimize loading. - Added functions to apply platform-specific prompt template overrides. - Created unit tests in `loader_test.go` to validate prompt configuration loading and reloading behavior. - Ensured that the last valid configuration is retained in case of errors during reload.
96 lines
2.9 KiB
Go
96 lines
2.9 KiB
Go
package app
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/geo-platform/tenant-api/internal/shared/response"
|
|
)
|
|
|
|
func TestResolveDashboardDateWindowAtUsesBusinessTimezone(t *testing.T) {
|
|
loc := time.FixedZone("CST", 8*60*60)
|
|
now := time.Date(2026, 4, 12, 0, 5, 0, 0, loc)
|
|
|
|
startDate, endDate, err := resolveDashboardDateWindowAt(7, "2026-04-12", now, loc)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, time.Date(2026, 4, 6, 0, 0, 0, 0, loc), startDate)
|
|
assert.Equal(t, time.Date(2026, 4, 12, 0, 0, 0, 0, loc), endDate)
|
|
}
|
|
|
|
func TestResolveDashboardDateWindowAtRejectsFutureBusinessDay(t *testing.T) {
|
|
loc := time.FixedZone("CST", 8*60*60)
|
|
now := time.Date(2026, 4, 12, 0, 5, 0, 0, loc)
|
|
|
|
_, _, err := resolveDashboardDateWindowAt(7, "2026-04-13", now, loc)
|
|
require.Error(t, err)
|
|
|
|
appErr := response.Normalize(err)
|
|
assert.Equal(t, 40031, appErr.Code)
|
|
assert.Equal(t, "invalid_business_date", appErr.Message)
|
|
assert.Equal(t, "business_date must not be later than today", appErr.Detail)
|
|
}
|
|
|
|
func TestParseDetailDateRangeAtDefaultsToCurrentBusinessDay(t *testing.T) {
|
|
loc := time.FixedZone("CST", 8*60*60)
|
|
now := time.Date(2026, 4, 12, 0, 5, 0, 0, loc)
|
|
|
|
fromDate, toDate, err := parseDetailDateRangeAt("", "", now, loc)
|
|
require.NoError(t, err)
|
|
|
|
expected := time.Date(2026, 4, 12, 0, 0, 0, 0, loc)
|
|
assert.Equal(t, expected, fromDate)
|
|
assert.Equal(t, expected, toDate)
|
|
}
|
|
|
|
func TestMonitoringBusinessDayAndDateAtUsesShanghaiTimezone(t *testing.T) {
|
|
now := time.Date(2026, 4, 11, 17, 19, 0, 0, time.UTC)
|
|
|
|
businessDay, businessDate := monitoringBusinessDayAndDateAt(now)
|
|
|
|
assert.Equal(t, time.Date(2026, 4, 12, 0, 0, 0, 0, monitoringBusinessLocation()), businessDay)
|
|
assert.Equal(t, "2026-04-12", businessDate)
|
|
}
|
|
|
|
func TestEncodeMonitoringProjectionRebuildEnvelopePreservesBusinessDate(t *testing.T) {
|
|
businessDay := time.Date(2026, 4, 12, 0, 0, 0, 0, monitoringBusinessLocation())
|
|
|
|
payload, err := encodeMonitoringProjectionRebuildEnvelope(1, 2, businessDay, "test")
|
|
require.NoError(t, err)
|
|
|
|
envelope, err := decodeMonitoringProjectionRebuildEnvelope(payload)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, "2026-04-12", envelope.BusinessDate)
|
|
}
|
|
|
|
func TestFilterMonitoringPlatformsReturnsSelectedPlatform(t *testing.T) {
|
|
platforms := []monitoringPlatformMetadata{
|
|
{ID: "deepseek", Name: "DeepSeek"},
|
|
{ID: "qwen", Name: "通义千问"},
|
|
{ID: "doubao", Name: "豆包"},
|
|
}
|
|
selected := "qwen"
|
|
|
|
filtered := filterMonitoringPlatforms(platforms, &selected)
|
|
|
|
assert.Equal(t, []monitoringPlatformMetadata{
|
|
{ID: "qwen", Name: "通义千问"},
|
|
}, filtered)
|
|
}
|
|
|
|
func TestFilterMonitoringPlatformsFallsBackToDisplayName(t *testing.T) {
|
|
platforms := []monitoringPlatformMetadata{
|
|
{ID: "deepseek", Name: "DeepSeek"},
|
|
}
|
|
selected := "doubao"
|
|
|
|
filtered := filterMonitoringPlatforms(platforms, &selected)
|
|
|
|
assert.Equal(t, []monitoringPlatformMetadata{
|
|
{ID: "doubao", Name: "豆包"},
|
|
}, filtered)
|
|
}
|