fix(HH-581): keep widget websocket on visitor auth (#152)
Co-authored-by: Rogee <rogee@ipao.vip>
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user