forked from QuantumNous/new-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththeme_compat_test.go
More file actions
47 lines (39 loc) · 1.33 KB
/
Copy paththeme_compat_test.go
File metadata and controls
47 lines (39 loc) · 1.33 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
36
37
38
39
40
41
42
43
44
45
46
47
package controller
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"github.com/QuantumNous/new-api/common"
"github.com/gin-gonic/gin"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestUpdateOptionRejectsRetiredFrontendTheme(t *testing.T) {
response := httptest.NewRecorder()
context, _ := gin.CreateTestContext(response)
context.Request = httptest.NewRequest(
http.MethodPut,
"/api/option/",
strings.NewReader(`{"key":"theme.frontend","value":"classic"}`),
)
UpdateOption(context)
assert.Equal(t, http.StatusOK, response.Code)
assert.JSONEq(t, `{"success":false,"message":"Classic 前端已移除,主题只能设置为 default"}`, response.Body.String())
}
func TestGetStatusAdvertisesDefaultDashboard(t *testing.T) {
previousMap := common.OptionMap
common.OptionMap = map[string]string{}
t.Cleanup(func() { common.OptionMap = previousMap })
response := httptest.NewRecorder()
context, _ := gin.CreateTestContext(response)
context.Request = httptest.NewRequest(http.MethodGet, "/api/status", nil)
GetStatus(context)
var payload struct {
Success bool `json:"success"`
Data map[string]any `json:"data"`
}
require.NoError(t, common.Unmarshal(response.Body.Bytes(), &payload))
assert.True(t, payload.Success)
assert.Equal(t, "default", payload.Data["theme"])
}