Add configurable SUB2API account priority

This commit is contained in:
initiatione
2026-05-06 17:53:07 +08:00
parent 9e6899f37c
commit 5014cb4de3
10 changed files with 254 additions and 1 deletions
+46
View File
@@ -277,3 +277,49 @@ test('SUB2API step 10 omits proxy_id when no proxy is configured', async () => {
assert.equal(Object.hasOwn(exchangeCall.body, 'proxy_id'), false);
assert.equal(Object.hasOwn(createCall.body, 'proxy_id'), false);
});
test('SUB2API step 10 creates account with configured account priority', async () => {
const fetchCalls = [];
const context = createSub2ApiPanelContext(fetchCalls);
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',
sub2apiSessionId: 'session-1',
sub2apiOAuthState: 'oauth-state',
sub2apiGroupId: 5,
sub2apiAccountPriority: 3
})
`, context);
const createCall = fetchCalls.find((call) => call.path === '/api/v1/admin/accounts');
assert.equal(createCall.body.priority, 3);
});
test('SUB2API account priority must be an integer greater than or equal to 1', async () => {
const fetchCalls = [];
const context = createSub2ApiPanelContext(fetchCalls);
await assert.rejects(
() => 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',
sub2apiSessionId: 'session-1',
sub2apiOAuthState: 'oauth-state',
sub2apiGroupId: 5,
sub2apiAccountPriority: 0
})
`, context),
/SUB2API 账号优先级必须是大于等于 1 的整数/
);
assert.equal(fetchCalls.some((call) => call.path === '/api/v1/admin/accounts'), false);
});