fix(HH-581): keep widget websocket on visitor auth (#152)

Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
Rogee
2026-08-24 10:54:38 +08:00
committed by GitHub
co-authored by rogee
parent c4ac664deb
commit 2c6bee2b37
5 changed files with 78 additions and 4 deletions
@@ -66,6 +66,24 @@ describe('BaseActionCableConnector', () => {
);
});
it('keeps widget token auth when a dashboard cookie shares its origin', () => {
getCookie.mockReturnValue('dashboard-session');
const connector = new BaseActionCableConnector(
app,
'visitor token',
'',
20000,
false
);
expect(post).not.toHaveBeenCalled();
expect(createConsumer).toHaveBeenCalledWith(
`${window.location.origin}/cable?pubsub_token=visitor%20token`
);
connector.disconnect();
});
it('continues consuming widget events after ActionCable reconnects', async () => {
getCookie.mockReturnValue(undefined);
const connector = new BaseActionCableConnector(app, 'visitor-token');
@@ -138,9 +156,19 @@ describe('BaseActionCableConnector', () => {
getCookie.mockReturnValue('1');
post.mockRejectedValue({ response: { status: 401 } });
const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
new BaseActionCableConnector(app, 'pubsub');
await vi.waitFor(() => expect(post).toHaveBeenCalledOnce());
await vi.advanceTimersByTimeAsync(1000);
await vi.waitFor(() => expect(post).toHaveBeenCalledTimes(2));
expect(createConsumer).not.toHaveBeenCalled();
expect(warn).toHaveBeenCalledOnce();
expect(warn).toHaveBeenCalledWith(
'WebSocket ticket exchange failed; retrying'
);
warn.mockRestore();
});
});