fix(auth): route session lifecycle through Square

This commit is contained in:
2026-08-19 16:44:06 +08:00
parent 1907924203
commit dc776ff489
6 changed files with 80 additions and 63 deletions

View File

@@ -71,18 +71,13 @@ describe('works-square-session service', () => {
await expect(getValidWorksSquareAccessToken({ fetchImpl })).resolves.toBe('new-access-token');
expect(fetchImpl).toHaveBeenCalledWith(
'https://biz.nianxx.cn/auth/oauth2/token',
'https://square.nianxx.cn/api/auth/refresh',
expect.objectContaining({
method: 'POST',
headers: expect.objectContaining({
Authorization: `Basic ${Buffer.from('app:app').toString('base64')}`,
'Content-Type': 'application/x-www-form-urlencoded',
}),
body: expect.any(URLSearchParams),
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ refresh_token: 'old-refresh-token' }),
}),
);
const body = fetchImpl.mock.calls[0][1].body as URLSearchParams;
expect(String(body)).toBe('grant_type=refresh_token&refresh_token=old-refresh-token');
expect(getWorksSquareSessionSnapshot()).toMatchObject({
accessToken: 'new-access-token',
tokenType: 'Bearer',
@@ -453,8 +448,9 @@ describe('works-square-session service', () => {
);
await getValidWorksSquareAccessToken({ fetchImpl: secondFetch, forceRefresh: true });
const body = secondFetch.mock.calls[0][1].body as URLSearchParams;
expect(String(body)).toContain('refresh_token=rotated-refresh-token');
expect(secondFetch.mock.calls[0][1].body).toBe(JSON.stringify({
refresh_token: 'rotated-refresh-token',
}));
});
it('uses user_id ahead of username for a stable opaque account partition', () => {