forked from QuantumNous/new-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog_format_test.go
More file actions
35 lines (29 loc) · 1.03 KB
/
Copy pathlog_format_test.go
File metadata and controls
35 lines (29 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package model
import (
"testing"
"github.com/QuantumNous/new-api/common"
"github.com/stretchr/testify/require"
)
// TestFormatUserLogsStripsQuotaSaturation verifies the admin-only quota
// saturation marker (nested under other.admin_info) is removed for non-admin
// log views, since formatUserLogs strips the whole admin_info object.
func TestFormatUserLogsStripsQuotaSaturation(t *testing.T) {
other := common.MapToJsonStr(map[string]interface{}{
"model_price": 0.004,
"admin_info": map[string]interface{}{
"quota_saturation": map[string]interface{}{
"op": "QuotaFromDecimal",
"kind": "overflow",
"clamped": common.MaxQuota,
},
},
})
logs := []*Log{{Other: other}}
formatUserLogs(logs, 0)
parsed, err := common.StrToMap(logs[0].Other)
require.NoError(t, err)
_, hasAdminInfo := parsed["admin_info"]
require.False(t, hasAdminInfo, "admin_info (and nested quota_saturation) must be stripped for non-admin views")
// Non-admin billing fields remain visible.
require.Contains(t, parsed, "model_price")
}