Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
陈曦
sub2api
Commits
29ca1290
Commit
29ca1290
authored
Feb 10, 2026
by
yangjianbo
Browse files
chore(test): 清理测试用例与类型导入
parent
3fcb0cc3
Changes
8
Hide whitespace changes
Inline
Side-by-side
backend/internal/pkg/geminicli/oauth_test.go
View file @
29ca1290
...
@@ -377,7 +377,7 @@ func TestBuildAuthorizationURL_EmptyRedirectURI(t *testing.T) {
...
@@ -377,7 +377,7 @@ func TestBuildAuthorizationURL_EmptyRedirectURI(t *testing.T) {
OAuthConfig
{},
OAuthConfig
{},
"test-state"
,
"test-state"
,
"test-challenge"
,
"test-challenge"
,
""
,
// 空 redirectURI
""
,
// 空 redirectURI
""
,
""
,
"code_assist"
,
"code_assist"
,
)
)
...
...
backend/internal/util/logredact/redact_test.go
View file @
29ca1290
...
@@ -28,9 +28,9 @@ func TestRedactText_QueryLike(t *testing.T) {
...
@@ -28,9 +28,9 @@ func TestRedactText_QueryLike(t *testing.T) {
}
}
func
TestRedactText_GOCSPX
(
t
*
testing
.
T
)
{
func
TestRedactText_GOCSPX
(
t
*
testing
.
T
)
{
in
:=
"client_secret=GOCSPX-
abcdefghijklmnopqrstuvwxyz_0123456789
"
in
:=
"client_secret=GOCSPX-
your-client-secret
"
out
:=
RedactText
(
in
)
out
:=
RedactText
(
in
)
if
strings
.
Contains
(
out
,
"
abcdefghijklmnopqrstuvwxyz
"
)
{
if
strings
.
Contains
(
out
,
"
your-client-secret
"
)
{
t
.
Fatalf
(
"expected secret redacted, got %q"
,
out
)
t
.
Fatalf
(
"expected secret redacted, got %q"
,
out
)
}
}
if
!
strings
.
Contains
(
out
,
"client_secret=***"
)
{
if
!
strings
.
Contains
(
out
,
"client_secret=***"
)
{
...
...
frontend/src/api/__tests__/client.spec.ts
View file @
29ca1290
import
{
describe
,
it
,
expect
,
vi
,
beforeEach
,
afterEach
}
from
'
vitest
'
import
{
describe
,
it
,
expect
,
vi
,
beforeEach
,
afterEach
}
from
'
vitest
'
import
axios
from
'
axios
'
import
axios
from
'
axios
'
import
type
{
AxiosInstance
,
InternalAxiosRequestConfig
,
AxiosResponse
,
AxiosHeaders
}
from
'
axios
'
import
type
{
AxiosInstance
}
from
'
axios
'
// 需要在导入 client 之前设置 mock
// 需要在导入 client 之前设置 mock
vi
.
mock
(
'
@/i18n
'
,
()
=>
({
vi
.
mock
(
'
@/i18n
'
,
()
=>
({
...
...
frontend/src/components/__tests__/Dashboard.spec.ts
View file @
29ca1290
...
@@ -9,7 +9,6 @@ import { defineComponent, ref, onMounted, nextTick } from 'vue'
...
@@ -9,7 +9,6 @@ import { defineComponent, ref, onMounted, nextTick } from 'vue'
// Mock API
// Mock API
const
mockGetDashboardStats
=
vi
.
fn
()
const
mockGetDashboardStats
=
vi
.
fn
()
const
mockRefreshUser
=
vi
.
fn
()
vi
.
mock
(
'
@/api
'
,
()
=>
({
vi
.
mock
(
'
@/api
'
,
()
=>
({
authAPI
:
{
authAPI
:
{
...
...
frontend/src/composables/__tests__/useClipboard.spec.ts
View file @
29ca1290
...
@@ -96,10 +96,12 @@ describe('useClipboard', () => {
...
@@ -96,10 +96,12 @@ describe('useClipboard', () => {
})
})
it
(
'
Clipboard API 失败时降级到 fallback
'
,
async
()
=>
{
it
(
'
Clipboard API 失败时降级到 fallback
'
,
async
()
=>
{
;(
navigator
.
clipboard
.
writeText
as
any
).
mockRejectedValue
(
new
Error
(
'
API failed
'
))
const
writeTextMock
=
navigator
.
clipboard
.
writeText
as
any
writeTextMock
.
mockRejectedValue
(
new
Error
(
'
API failed
'
))
// jsdom 没有 execCommand,手动定义
// jsdom 没有 execCommand,手动定义
;(
document
as
any
).
execCommand
=
vi
.
fn
().
mockReturnValue
(
true
)
const
documentAny
=
document
as
any
documentAny
.
execCommand
=
vi
.
fn
().
mockReturnValue
(
true
)
const
{
copyToClipboard
,
copied
}
=
useClipboard
()
const
{
copyToClipboard
,
copied
}
=
useClipboard
()
const
result
=
await
copyToClipboard
(
'
fallback text
'
)
const
result
=
await
copyToClipboard
(
'
fallback text
'
)
...
@@ -112,7 +114,8 @@ describe('useClipboard', () => {
...
@@ -112,7 +114,8 @@ describe('useClipboard', () => {
it
(
'
非安全上下文使用 fallback
'
,
async
()
=>
{
it
(
'
非安全上下文使用 fallback
'
,
async
()
=>
{
Object
.
defineProperty
(
window
,
'
isSecureContext
'
,
{
value
:
false
,
writable
:
true
})
Object
.
defineProperty
(
window
,
'
isSecureContext
'
,
{
value
:
false
,
writable
:
true
})
;(
document
as
any
).
execCommand
=
vi
.
fn
().
mockReturnValue
(
true
)
const
documentAny
=
document
as
any
documentAny
.
execCommand
=
vi
.
fn
().
mockReturnValue
(
true
)
const
{
copyToClipboard
,
copied
}
=
useClipboard
()
const
{
copyToClipboard
,
copied
}
=
useClipboard
()
const
result
=
await
copyToClipboard
(
'
insecure context text
'
)
const
result
=
await
copyToClipboard
(
'
insecure context text
'
)
...
@@ -124,8 +127,11 @@ describe('useClipboard', () => {
...
@@ -124,8 +127,11 @@ describe('useClipboard', () => {
})
})
it
(
'
所有复制方式均失败时调用 showError
'
,
async
()
=>
{
it
(
'
所有复制方式均失败时调用 showError
'
,
async
()
=>
{
;(
navigator
.
clipboard
.
writeText
as
any
).
mockRejectedValue
(
new
Error
(
'
fail
'
))
const
writeTextMock
=
navigator
.
clipboard
.
writeText
as
any
;(
document
as
any
).
execCommand
=
vi
.
fn
().
mockReturnValue
(
false
)
writeTextMock
.
mockRejectedValue
(
new
Error
(
'
fail
'
))
const
documentAny
=
document
as
any
documentAny
.
execCommand
=
vi
.
fn
().
mockReturnValue
(
false
)
const
{
copyToClipboard
,
copied
}
=
useClipboard
()
const
{
copyToClipboard
,
copied
}
=
useClipboard
()
const
result
=
await
copyToClipboard
(
'
text
'
)
const
result
=
await
copyToClipboard
(
'
text
'
)
...
...
frontend/src/composables/__tests__/useTableLoader.spec.ts
View file @
29ca1290
import
{
describe
,
it
,
expect
,
vi
,
beforeEach
,
afterEach
}
from
'
vitest
'
import
{
describe
,
it
,
expect
,
vi
,
beforeEach
,
afterEach
}
from
'
vitest
'
import
{
useTableLoader
}
from
'
@/composables/useTableLoader
'
import
{
useTableLoader
}
from
'
@/composables/useTableLoader
'
import
{
nextTick
}
from
'
vue
'
// Mock @vueuse/core 的 useDebounceFn
// Mock @vueuse/core 的 useDebounceFn
vi
.
mock
(
'
@vueuse/core
'
,
()
=>
({
vi
.
mock
(
'
@vueuse/core
'
,
()
=>
({
...
@@ -212,7 +211,7 @@ describe('useTableLoader', () => {
...
@@ -212,7 +211,7 @@ describe('useTableLoader', () => {
})
})
})
})
const
{
load
,
items
}
=
useTableLoader
({
fetchFn
})
const
{
load
}
=
useTableLoader
({
fetchFn
})
// 第一次加载
// 第一次加载
const
p1
=
load
()
const
p1
=
load
()
...
...
frontend/src/router/__tests__/guards.spec.ts
View file @
29ca1290
import
{
describe
,
it
,
expect
,
vi
,
beforeEach
}
from
'
vitest
'
import
{
describe
,
it
,
expect
,
vi
,
beforeEach
}
from
'
vitest
'
import
{
createRouter
,
createMemoryHistory
}
from
'
vue-router
'
import
{
setActivePinia
,
createPinia
}
from
'
pinia
'
import
{
setActivePinia
,
createPinia
}
from
'
pinia
'
import
{
defineComponent
,
h
}
from
'
vue
'
// Mock 导航加载状态
// Mock 导航加载状态
vi
.
mock
(
'
@/composables/useNavigationLoading
'
,
()
=>
{
vi
.
mock
(
'
@/composables/useNavigationLoading
'
,
()
=>
{
...
@@ -47,61 +45,6 @@ vi.mock('@/api/auth', () => ({
...
@@ -47,61 +45,6 @@ vi.mock('@/api/auth', () => ({
getPublicSettings
:
vi
.
fn
(),
getPublicSettings
:
vi
.
fn
(),
}))
}))
const
DummyComponent
=
defineComponent
({
render
()
{
return
h
(
'
div
'
,
'
dummy
'
)
},
})
/**
* 创建带守卫逻辑的测试路由
* 模拟 router/index.ts 中的 beforeEach 守卫逻辑
*/
function
createTestRouter
()
{
const
router
=
createRouter
({
history
:
createMemoryHistory
(),
routes
:
[
{
path
:
'
/login
'
,
component
:
DummyComponent
,
meta
:
{
requiresAuth
:
false
,
title
:
'
Login
'
}
},
{
path
:
'
/register
'
,
component
:
DummyComponent
,
meta
:
{
requiresAuth
:
false
,
title
:
'
Register
'
},
},
{
path
:
'
/home
'
,
component
:
DummyComponent
,
meta
:
{
requiresAuth
:
false
,
title
:
'
Home
'
}
},
{
path
:
'
/dashboard
'
,
component
:
DummyComponent
,
meta
:
{
title
:
'
Dashboard
'
}
},
{
path
:
'
/keys
'
,
component
:
DummyComponent
,
meta
:
{
title
:
'
API Keys
'
}
},
{
path
:
'
/subscriptions
'
,
component
:
DummyComponent
,
meta
:
{
title
:
'
Subscriptions
'
}
},
{
path
:
'
/redeem
'
,
component
:
DummyComponent
,
meta
:
{
title
:
'
Redeem
'
}
},
{
path
:
'
/admin/dashboard
'
,
component
:
DummyComponent
,
meta
:
{
requiresAdmin
:
true
,
title
:
'
Admin Dashboard
'
},
},
{
path
:
'
/admin/users
'
,
component
:
DummyComponent
,
meta
:
{
requiresAdmin
:
true
,
title
:
'
Admin Users
'
},
},
{
path
:
'
/admin/groups
'
,
component
:
DummyComponent
,
meta
:
{
requiresAdmin
:
true
,
title
:
'
Admin Groups
'
},
},
{
path
:
'
/admin/subscriptions
'
,
component
:
DummyComponent
,
meta
:
{
requiresAdmin
:
true
,
title
:
'
Admin Subscriptions
'
},
},
{
path
:
'
/admin/redeem
'
,
component
:
DummyComponent
,
meta
:
{
requiresAdmin
:
true
,
title
:
'
Admin Redeem
'
},
},
],
})
return
router
}
// 用于测试的 auth 状态
// 用于测试的 auth 状态
interface
MockAuthState
{
interface
MockAuthState
{
...
...
frontend/src/stores/__tests__/app.spec.ts
View file @
29ca1290
...
@@ -250,7 +250,8 @@ describe('useAppStore', () => {
...
@@ -250,7 +250,8 @@ describe('useAppStore', () => {
describe
(
'
公开设置加载
'
,
()
=>
{
describe
(
'
公开设置加载
'
,
()
=>
{
it
(
'
从 window.__APP_CONFIG__ 初始化
'
,
()
=>
{
it
(
'
从 window.__APP_CONFIG__ 初始化
'
,
()
=>
{
;(
window
as
any
).
__APP_CONFIG__
=
{
const
windowAny
=
window
as
any
windowAny
.
__APP_CONFIG__
=
{
site_name
:
'
TestSite
'
,
site_name
:
'
TestSite
'
,
site_logo
:
'
/logo.png
'
,
site_logo
:
'
/logo.png
'
,
version
:
'
1.0.0
'
,
version
:
'
1.0.0
'
,
...
@@ -278,7 +279,8 @@ describe('useAppStore', () => {
...
@@ -278,7 +279,8 @@ describe('useAppStore', () => {
})
})
it
(
'
clearPublicSettingsCache 清除缓存
'
,
()
=>
{
it
(
'
clearPublicSettingsCache 清除缓存
'
,
()
=>
{
;(
window
as
any
).
__APP_CONFIG__
=
{
site_name
:
'
Test
'
}
const
windowAny
=
window
as
any
windowAny
.
__APP_CONFIG__
=
{
site_name
:
'
Test
'
}
const
store
=
useAppStore
()
const
store
=
useAppStore
()
store
.
initFromInjectedConfig
()
store
.
initFromInjectedConfig
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment