fix: preserve wechat bind resume state

This commit is contained in:
IanShaw027
2026-04-20 22:52:56 +08:00
parent 4d10ba4297
commit 7fdede579a
2 changed files with 60 additions and 5 deletions

View File

@@ -342,6 +342,7 @@ describe('WechatCallbackView', () => {
expect(replaceMock.mock.calls[0]?.[0]).toContain('/login?')
expect(replaceMock.mock.calls[0]?.[0]).toContain('wechat_bind_existing%3D1')
expect(replaceMock.mock.calls[0]?.[0]).toContain('email=user%40example.com')
expect(replaceMock.mock.calls[0]?.[0]).toContain('mode%3Dopen')
})
it('collects email for pending oauth account creation and submits adoption decisions', async () => {
@@ -592,7 +593,8 @@ describe('WechatCallbackView', () => {
it('restarts the current-user bind flow after returning from login', async () => {
routeState.query = {
wechat_bind_existing: '1',
redirect: '/profile'
redirect: '/profile',
mode: 'mp',
}
getAuthTokenMock.mockReturnValue('existing-auth-token')
@@ -612,7 +614,38 @@ describe('WechatCallbackView', () => {
expect(exchangePendingOAuthCompletionMock).not.toHaveBeenCalled()
expect(prepareOAuthBindAccessTokenCookieMock).toHaveBeenCalledTimes(1)
expect(locationState.current.href).toContain('/api/v1/auth/oauth/wechat/start?')
expect(locationState.current.href).toContain('mode=mp')
expect(locationState.current.href).toContain('intent=bind_current_user')
expect(locationState.current.href).toContain('redirect=%2Fprofile')
})
it('redirects back to login instead of falling through when bind-existing resume has no auth token', async () => {
routeState.query = {
wechat_bind_existing: '1',
redirect: '/profile',
mode: 'mp',
email: 'resume@example.com',
}
getAuthTokenMock.mockReturnValue(null)
mount(WechatCallbackView, {
global: {
stubs: {
AuthLayout: { template: '<div><slot /></div>' },
Icon: true,
RouterLink: { template: '<a><slot /></a>' },
transition: false,
},
},
})
await flushPromises()
expect(exchangePendingOAuthCompletionMock).not.toHaveBeenCalled()
expect(replaceMock).toHaveBeenCalledTimes(1)
expect(replaceMock.mock.calls[0]?.[0]).toContain('/login?')
expect(replaceMock.mock.calls[0]?.[0]).toContain('wechat_bind_existing%3D1')
expect(replaceMock.mock.calls[0]?.[0]).toContain('mode%3Dmp')
expect(replaceMock.mock.calls[0]?.[0]).toContain('email=resume%40example.com')
})
})