mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-22 12:19:09 +00:00
refactor(core): Delete all collaboration related code (no-changelog) (#9929)
This commit is contained in:
committed by
GitHub
parent
24091dfd9b
commit
22990342df
@@ -1,10 +1,11 @@
|
||||
import Container from 'typedi';
|
||||
import { Container } from 'typedi';
|
||||
import { EventEmitter } from 'events';
|
||||
import type WebSocket from 'ws';
|
||||
|
||||
import { WebSocketPush } from '@/push/websocket.push';
|
||||
import { Logger } from '@/Logger';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { PushDataExecutionRecovered } from '@/Interfaces';
|
||||
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
|
||||
jest.useFakeTimers();
|
||||
@@ -26,7 +27,6 @@ const createMockWebSocket = () => new MockWebSocket() as unknown as jest.Mocked<
|
||||
describe('WebSocketPush', () => {
|
||||
const pushRef1 = 'test-session1';
|
||||
const pushRef2 = 'test-session2';
|
||||
const userId: User['id'] = 'test-user';
|
||||
|
||||
mockInstance(Logger);
|
||||
const webSocketPush = Container.get(WebSocketPush);
|
||||
@@ -38,26 +38,24 @@ describe('WebSocketPush', () => {
|
||||
});
|
||||
|
||||
it('can add a connection', () => {
|
||||
webSocketPush.add(pushRef1, userId, mockWebSocket1);
|
||||
webSocketPush.add(pushRef1, mockWebSocket1);
|
||||
|
||||
expect(mockWebSocket1.listenerCount('close')).toBe(1);
|
||||
expect(mockWebSocket1.listenerCount('pong')).toBe(1);
|
||||
expect(mockWebSocket1.listenerCount('message')).toBe(1);
|
||||
});
|
||||
|
||||
it('closes a connection', () => {
|
||||
webSocketPush.add(pushRef1, userId, mockWebSocket1);
|
||||
webSocketPush.add(pushRef1, mockWebSocket1);
|
||||
|
||||
mockWebSocket1.emit('close');
|
||||
|
||||
expect(mockWebSocket1.listenerCount('close')).toBe(0);
|
||||
expect(mockWebSocket1.listenerCount('pong')).toBe(0);
|
||||
expect(mockWebSocket1.listenerCount('message')).toBe(0);
|
||||
});
|
||||
|
||||
it('sends data to one connection', () => {
|
||||
webSocketPush.add(pushRef1, userId, mockWebSocket1);
|
||||
webSocketPush.add(pushRef2, userId, mockWebSocket2);
|
||||
webSocketPush.add(pushRef1, mockWebSocket1);
|
||||
webSocketPush.add(pushRef2, mockWebSocket2);
|
||||
const data: PushDataExecutionRecovered = {
|
||||
type: 'executionRecovered',
|
||||
data: {
|
||||
@@ -65,7 +63,7 @@ describe('WebSocketPush', () => {
|
||||
},
|
||||
};
|
||||
|
||||
webSocketPush.sendToOneSession('executionRecovered', data, pushRef1);
|
||||
webSocketPush.sendToOne('executionRecovered', data, pushRef1);
|
||||
|
||||
expect(mockWebSocket1.send).toHaveBeenCalledWith(
|
||||
JSON.stringify({
|
||||
@@ -82,8 +80,8 @@ describe('WebSocketPush', () => {
|
||||
});
|
||||
|
||||
it('sends data to all connections', () => {
|
||||
webSocketPush.add(pushRef1, userId, mockWebSocket1);
|
||||
webSocketPush.add(pushRef2, userId, mockWebSocket2);
|
||||
webSocketPush.add(pushRef1, mockWebSocket1);
|
||||
webSocketPush.add(pushRef2, mockWebSocket2);
|
||||
const data: PushDataExecutionRecovered = {
|
||||
type: 'executionRecovered',
|
||||
data: {
|
||||
@@ -106,56 +104,13 @@ describe('WebSocketPush', () => {
|
||||
expect(mockWebSocket2.send).toHaveBeenCalledWith(expectedMsg);
|
||||
});
|
||||
|
||||
it('sends data to all users connections', () => {
|
||||
webSocketPush.add(pushRef1, userId, mockWebSocket1);
|
||||
webSocketPush.add(pushRef2, userId, mockWebSocket2);
|
||||
const data: PushDataExecutionRecovered = {
|
||||
type: 'executionRecovered',
|
||||
data: {
|
||||
executionId: 'test-execution-id',
|
||||
},
|
||||
};
|
||||
|
||||
webSocketPush.sendToUsers('executionRecovered', data, [userId]);
|
||||
|
||||
const expectedMsg = JSON.stringify({
|
||||
type: 'executionRecovered',
|
||||
data: {
|
||||
type: 'executionRecovered',
|
||||
data: {
|
||||
executionId: 'test-execution-id',
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(mockWebSocket1.send).toHaveBeenCalledWith(expectedMsg);
|
||||
expect(mockWebSocket2.send).toHaveBeenCalledWith(expectedMsg);
|
||||
});
|
||||
|
||||
it('pings all connections', () => {
|
||||
webSocketPush.add(pushRef1, userId, mockWebSocket1);
|
||||
webSocketPush.add(pushRef2, userId, mockWebSocket2);
|
||||
webSocketPush.add(pushRef1, mockWebSocket1);
|
||||
webSocketPush.add(pushRef2, mockWebSocket2);
|
||||
|
||||
jest.runOnlyPendingTimers();
|
||||
|
||||
expect(mockWebSocket1.ping).toHaveBeenCalled();
|
||||
expect(mockWebSocket2.ping).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('emits message event when connection receives data', () => {
|
||||
const mockOnMessageReceived = jest.fn();
|
||||
webSocketPush.on('message', mockOnMessageReceived);
|
||||
webSocketPush.add(pushRef1, userId, mockWebSocket1);
|
||||
webSocketPush.add(pushRef2, userId, mockWebSocket2);
|
||||
|
||||
const data = { test: 'data' };
|
||||
const buffer = Buffer.from(JSON.stringify(data));
|
||||
|
||||
mockWebSocket1.emit('message', buffer);
|
||||
|
||||
expect(mockOnMessageReceived).toHaveBeenCalledWith({
|
||||
msg: data,
|
||||
pushRef: pushRef1,
|
||||
userId,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user