Skip to content
This repository was archived by the owner on Jan 5, 2026. It is now read-only.

Commit d989a43

Browse files
author
Srinaath Ravichandran
committed
All tests working
Signed-off-by: Srinaath Ravichandran <[email protected]>
1 parent de34628 commit d989a43

4 files changed

Lines changed: 45 additions & 32 deletions

File tree

packages/app/main/src/server/routes/channel/conversations/handlers/replyToActivity.spec.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,17 @@ jest.mock('../../../../utils/oauthLinkEncoder', () => ({
4242
}),
4343
}));
4444

45-
jest.mock('../../../../webSocketServer', () => ({
46-
WebSocketServer: {
47-
getSocketByConversationId: () => ({
48-
send: jest.fn(),
49-
}),
50-
},
51-
}));
45+
const mockSocket = {
46+
send: jest.fn(),
47+
};
48+
49+
jest.mock('../../../../webSocketServer', () => {
50+
return {
51+
WebSocketServer: {
52+
sendToSubscribers: (...args) => mockSocket.send(...args),
53+
},
54+
};
55+
});
5256

5357
describe('replyToActivity route middleware', () => {
5458
const mockReq: any = {

packages/app/main/src/server/routes/channel/conversations/handlers/sendActivityToConversation.spec.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,17 @@ import * as HttpStatus from 'http-status-codes';
3535

3636
import { sendActivityToConversation } from './sendActivityToConversation';
3737

38-
jest.mock('../../../../webSocketServer', () => ({
39-
WebSocketServer: {
40-
getSocketByConversationId: () => ({
41-
send: jest.fn(),
42-
}),
43-
},
44-
}));
38+
const mockSocket = {
39+
send: jest.fn(),
40+
};
41+
42+
jest.mock('../../../../webSocketServer', () => {
43+
return {
44+
WebSocketServer: {
45+
sendToSubscribers: (...args) => mockSocket.send(...args),
46+
},
47+
};
48+
});
4549

4650
const mockSendErrorResponse = jest.fn();
4751
jest.mock('../../../../utils/sendErrorResponse', () => ({

packages/app/main/src/server/routes/directLine/handlers/postActivity.spec.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,14 @@ jest.mock('../../../utils/sendErrorResponse', () => ({
4343
const mockSocket = {
4444
send: jest.fn(),
4545
};
46-
jest.mock('../../../webSocketServer', () => ({
47-
WebSocketServer: {
48-
getSocketByConversationId: () => mockSocket,
49-
},
50-
}));
46+
47+
jest.mock('../../../webSocketServer', () => {
48+
return {
49+
WebSocketServer: {
50+
sendToSubscribers: (...args) => mockSocket.send(...args),
51+
},
52+
};
53+
});
5154

5255
describe('postActivity handler', () => {
5356
beforeEach(() => {
@@ -56,14 +59,16 @@ describe('postActivity handler', () => {
5659
});
5760

5861
it('should return a 200 and the id of the posted activity', async () => {
62+
const activity = {
63+
id: 'activity1',
64+
};
65+
5966
const mockEmulatorServer: any = {
6067
logger: {
6168
logMessage: jest.fn(),
6269
},
6370
};
64-
const activity = {
65-
id: 'activity1',
66-
};
71+
6772
const req: any = {
6873
body: activity,
6974
conversation: {
@@ -72,6 +77,7 @@ describe('postActivity handler', () => {
7277
response: {},
7378
statusCode: HttpStatus.OK,
7479
}),
80+
conversationId: 'convo1',
7581
},
7682
params: {
7783
conversationId: 'convo1',
@@ -88,11 +94,7 @@ describe('postActivity handler', () => {
8894
expect(res.send).toHaveBeenCalledWith(HttpStatus.OK, activity);
8995
expect(res.end).toHaveBeenCalled();
9096
expect(next).toHaveBeenCalled();
91-
expect(mockSocket.send).toHaveBeenCalledWith(
92-
JSON.stringify({
93-
activities: [{ ...req.body, id: 'activity1' }],
94-
})
95-
);
97+
expect(mockSocket.send).toHaveBeenCalledWith(req.params.conversationId, activity);
9698
});
9799

98100
it('should return a 200 but not send the /INSPECT open command over the web socket', async () => {

packages/app/main/src/server/routes/emulator/handlers/feedActivitiesAsTranscript.spec.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,14 @@ import { createFeedActivitiesAsTranscriptHandler } from './feedActivitiesAsTrans
3838
const mockSocket = {
3939
send: jest.fn(),
4040
};
41-
jest.mock('../../../webSocketServer', () => ({
42-
WebSocketServer: {
43-
getSocketByConversationId: () => mockSocket,
44-
},
45-
}));
41+
42+
jest.mock('../../../webSocketServer', () => {
43+
return {
44+
WebSocketServer: {
45+
sendToSubscribers: (...args) => mockSocket.send(...args),
46+
},
47+
};
48+
});
4649

4750
describe('feedActivitiesAsTranscript handler', () => {
4851
it('should send a 200 after sending all activities over the web socket connection', () => {

0 commit comments

Comments
 (0)