refactor: remove deprecated apiKey from site management and update related functionality

- Removed apiKey from SiteRow type and related forms in Sites component.
- Updated site saving logic to handle site creation without apiKey.
- Adjusted tests to ensure apiKey is not included in site editor state.
- Refactored Tokens component to support embedded mode and redirect logic.
- Added migration tests for site apiKey to account migration service.
- Implemented siteApiKeyMigrationService to handle migration of apiKey to account tokens.
- Enhanced tests for segmented connections in Accounts and redirect logic for Tokens.
This commit is contained in:
cita
2026-03-07 15:03:30 +08:00
parent a98a6f2c18
commit c31bbcbb51
30 changed files with 1960 additions and 592 deletions
+48
View File
@@ -0,0 +1,48 @@
import { describe, expect, it, vi } from 'vitest';
import { act, create } from 'react-test-renderer';
import { MemoryRouter, Route, Routes, useLocation } from 'react-router-dom';
import { ToastProvider } from '../components/Toast.js';
import Tokens from './Tokens.js';
const { apiMock } = vi.hoisted(() => ({
apiMock: {
getAccountTokens: vi.fn().mockResolvedValue([]),
getAccounts: vi.fn().mockResolvedValue([]),
getAccountTokenGroups: vi.fn().mockResolvedValue({ groups: ['default'] }),
},
}));
vi.mock('../api.js', () => ({
api: apiMock,
}));
function LocationProbe() {
const location = useLocation();
return <div>{`${location.pathname}${location.search}`}</div>;
}
describe('Tokens legacy route redirect', () => {
it('redirects /tokens to the merged accounts tokens segment', async () => {
let root: ReturnType<typeof create> | null = null;
await act(async () => {
root = create(
<ToastProvider>
<MemoryRouter initialEntries={['/tokens?create=1&accountId=23&model=gpt-4.1']}>
<Routes>
<Route path="/tokens" element={<Tokens />} />
<Route path="/accounts" element={<LocationProbe />} />
</Routes>
</MemoryRouter>
</ToastProvider>,
);
});
const rendered = JSON.stringify(root?.toJSON());
expect(rendered).toContain('/accounts?');
expect(rendered).toContain('segment=tokens');
expect(rendered).toContain('create=1');
expect(rendered).toContain('accountId=23');
expect(rendered).toContain('model=gpt-4.1');
root?.unmount();
});
});