From 1b59b708c46fb8df840902093e6515d7c26be3c6 Mon Sep 17 00:00:00 2001 From: Ethan Zimbelman Date: Mon, 16 Oct 2023 13:33:34 -0700 Subject: [PATCH] allow the socket mode receiver to be used with socket mode --- src/App-basic-features.spec.ts | 20 +++++++++++++++++++- src/App.ts | 5 +---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/App-basic-features.spec.ts b/src/App-basic-features.spec.ts index 7559d3157..78a815380 100644 --- a/src/App-basic-features.spec.ts +++ b/src/App-basic-features.spec.ts @@ -14,6 +14,7 @@ import { } from './types'; import { ConversationStore } from './conversation-store'; import App from './App'; +import SocketModeReceiver from './receivers/SocketModeReceiver'; // Utility functions const noop = () => Promise.resolve(undefined); @@ -264,7 +265,7 @@ describe('App basic features', () => { assert.propertyVal(error, 'code', ErrorCode.AppInitializationError); } }); - it('should fail when both socketMode and receiver are specified', async () => { + it('should fail when both socketMode and a custom receiver are specified', async () => { // Arrange const fakeReceiver = new FakeReceiver(); const MockApp = await importApp(); @@ -278,6 +279,23 @@ describe('App basic features', () => { assert.propertyVal(error, 'code', ErrorCode.AppInitializationError); } }); + it('should succeed when both socketMode and SocketModeReceiver are specified', async () => { + // Arrange + const fakeBotId = 'B_FAKE_BOT_ID'; + const fakeBotUserId = 'U_FAKE_BOT_USER_ID'; + const overrides = mergeOverrides( + withNoopAppMetadata(), + withSuccessfulBotUserFetchingWebClient(fakeBotId, fakeBotUserId), + ); + const MockApp = await importApp(overrides); + const socketModeReceiver = new SocketModeReceiver({ appToken: '' }); + + // Act + const app = new MockApp({ token: '', signingSecret: '', socketMode: true, receiver: socketModeReceiver }); + + // Assert + assert.instanceOf(app, MockApp); + }); it('should initialize MemoryStore conversation store by default', async () => { // Arrange const fakeMemoryStore = sinon.fake(); diff --git a/src/App.ts b/src/App.ts index 055c82494..5fea2290c 100644 --- a/src/App.ts +++ b/src/App.ts @@ -1177,10 +1177,7 @@ export default class App ): Receiver { if (receiver !== undefined) { // Custom receiver supplied - if (this.socketMode === true) { - // socketMode = true should result in SocketModeReceiver being used as receiver - // TODO: Add case for when socketMode = true and receiver = SocketModeReceiver - // as this should not result in an error + if (this.socketMode === true && !(receiver instanceof SocketModeReceiver)) { throw new AppInitializationError('You cannot supply a custom receiver when socketMode is set to true.'); } return receiver;