feat(sub2api): 支持多分组创建账号

(cherry picked from commit cc7671e6d2863b68527134008301e14fb86a8666)
This commit is contained in:
朴圣佑
2026-04-26 22:23:25 +08:00
committed by QLHazyCoder
parent aa4e52b9a7
commit 63c53accfe
6 changed files with 130 additions and 11 deletions
+34 -1
View File
@@ -79,7 +79,10 @@ function createSub2ApiPanelContext(fetchCalls = []) {
if (parsed.pathname === '/api/v1/admin/groups/all') {
return createJsonResponse({
code: 0,
data: [{ id: 5, name: 'codex', platform: 'openai' }],
data: [
{ id: 5, name: 'codex', platform: 'openai' },
{ id: 9, name: 'codex-plus', platform: 'openai' },
],
});
}
if (parsed.pathname === '/api/v1/admin/proxies/all') {
@@ -220,6 +223,36 @@ test('SUB2API step 1 omits proxy_id when default proxy is empty', async () => {
assert.equal(Object.hasOwn(generateCall.body, 'proxy_id'), false);
});
test('SUB2API step 10 creates accounts in multiple configured groups', async () => {
const fetchCalls = [];
const context = createSub2ApiPanelContext(fetchCalls);
const step1Result = await vm.runInContext(`
step1_generateOpenAiAuthUrl({
sub2apiEmail: 'admin@example.com',
sub2apiPassword: 'secret',
sub2apiGroupName: 'codex, codex-plus'
}, { report: false })
`, context);
await vm.runInContext(`
step9_submitOpenAiCallback({
localhostUrl: 'http://localhost:1455/auth/callback?code=callback-code&state=oauth-state',
sub2apiUrl: 'https://sub.example/admin/accounts',
sub2apiEmail: 'admin@example.com',
sub2apiPassword: 'secret',
sub2apiGroupName: 'codex, codex-plus',
sub2apiSessionId: 'session-1',
sub2apiOAuthState: 'oauth-state',
sub2apiGroupIds: ${JSON.stringify(step1Result.sub2apiGroupIds)}
})
`, context);
const createCall = fetchCalls.find((call) => call.path === '/api/v1/admin/accounts');
assert.deepEqual(Array.from(step1Result.sub2apiGroupIds), [5, 9]);
assert.deepEqual(createCall.body.group_ids, [5, 9]);
});
test('SUB2API step 10 omits proxy_id when no proxy is configured', async () => {
const fetchCalls = [];
const context = createSub2ApiPanelContext(fetchCalls);