fix(teacher): 独立刷新老师目录以缩短配置更新延迟
This commit is contained in:
1 parent
2767a15017
commit
913ccad577
9 files changed
+184
-7
No files matched your search
@@ -0,0 +1,34 @@
|
||||
import { beforeEach, expect, it, vi } from 'vitest';
|
||||
const mock = vi.hoisted(() => ({
|
||||
binding: vi.fn(), current: vi.fn(), token: vi.fn(), fetch: vi.fn(),
|
||||
}));
|
||||
vi.mock('../../electron/services/works-square-session', () => ({
|
||||
getWorksSquareAccountBinding: mock.binding,
|
||||
isCurrentWorksSquareAccountBinding: mock.current,
|
||||
getValidWorksSquareAccessToken: mock.token,
|
||||
}));
|
||||
vi.mock('../../electron/utils/proxy-fetch', () => ({ proxyAwareFetch: mock.fetch }));
|
||||
import { teacherCatalogRevision } from '../../electron/coding-teacher/config-client';
|
||||
|
||||
beforeEach(() => {
|
||||
vi.resetAllMocks();
|
||||
mock.binding.mockReturnValue({ accountId: 'student', generation: 1 });
|
||||
mock.current.mockReturnValue(true);
|
||||
mock.token.mockResolvedValue('student-token');
|
||||
mock.fetch.mockResolvedValue(new Response(JSON.stringify({ revision: 12 })));
|
||||
});
|
||||
|
||||
it('reads only the small directory revision with current account authentication', async () => {
|
||||
expect(await teacherCatalogRevision()).toEqual({ revision: 12 });
|
||||
expect(mock.fetch).toHaveBeenCalledTimes(1);
|
||||
expect(mock.fetch.mock.calls[0][0]).toMatch(/\/api\/coding-teacher\/teachers\/revision$/);
|
||||
expect(mock.fetch.mock.calls[0][1].headers.Authorization).toBe('Bearer student-token');
|
||||
});
|
||||
|
||||
it('discards a response when the account changes while waiting', async () => {
|
||||
mock.fetch.mockImplementation(async () => {
|
||||
mock.current.mockReturnValue(false);
|
||||
return new Response(JSON.stringify({ revision: 99 }));
|
||||
});
|
||||
await expect(teacherCatalogRevision()).rejects.toMatchObject({ code: 'teacher_account_changed' });
|
||||
});
|
||||
Reference in new issue
Block a user