Skip to content

Commit 99911cf

Browse files
committed
allow localCacheEnabled override through sdkInitParams
1 parent 086f90a commit 99911cf

File tree

2 files changed

+34
-20
lines changed

2 files changed

+34
-20
lines changed

src/lib/hooks/useConnect/__test__/setupConnection.spec.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import { getMissingParamError, setUpConnection, initSDK, getConnectSbError } fro
66
import { SetupConnectionTypes } from '../types';
77
import { generateSetUpConnectionParams, mockSdk, mockUser, mockUser2 } from './data.mocks';
88
import { SendbirdError } from '@sendbird/chat';
9+
import { OpenChannelModule } from '@sendbird/chat/openChannel';
10+
import { GroupChannelModule } from '@sendbird/chat/groupChannel';
911

1012
// todo: combine after mock-sdk is implemented
1113
jest.mock('@sendbird/chat', () => {
@@ -196,10 +198,8 @@ describe('useConnect/setupConnection/initSDK', () => {
196198
newInstance: false,
197199
localCacheEnabled: true,
198200
modules: [
199-
// @ts-ignore
200-
new (require('@sendbird/chat/groupChannel').GroupChannelModule)(),
201-
// @ts-ignore
202-
new (require('@sendbird/chat/openChannel').OpenChannelModule)(),
201+
GroupChannelModule,
202+
OpenChannelModule,
203203
],
204204
});
205205
expect(newSdk).toEqual(mockSdk);
@@ -215,10 +215,8 @@ describe('useConnect/setupConnection/initSDK', () => {
215215
newInstance: false,
216216
localCacheEnabled: true,
217217
modules: [
218-
// @ts-ignore
219-
new (require('@sendbird/chat/groupChannel').GroupChannelModule)(),
220-
// @ts-ignore
221-
new (require('@sendbird/chat/openChannel').OpenChannelModule)(),
218+
GroupChannelModule,
219+
OpenChannelModule,
222220
],
223221
customApiHost,
224222
customWebSocketHost,
@@ -236,10 +234,8 @@ describe('useConnect/setupConnection/initSDK', () => {
236234
newInstance: false,
237235
localCacheEnabled: true,
238236
modules: [
239-
// @ts-ignore
240-
new (require('@sendbird/chat/groupChannel').GroupChannelModule)(),
241-
// @ts-ignore
242-
new (require('@sendbird/chat/openChannel').OpenChannelModule)(),
237+
GroupChannelModule,
238+
OpenChannelModule,
243239
],
244240
sdkInitParams,
245241
});
@@ -256,13 +252,32 @@ describe('useConnect/setupConnection/initSDK', () => {
256252
newInstance: false,
257253
localCacheEnabled: true,
258254
modules: [
259-
// @ts-ignore
260-
new (require('@sendbird/chat/groupChannel').GroupChannelModule)(),
261-
// @ts-ignore
262-
new (require('@sendbird/chat/openChannel').OpenChannelModule)(),
255+
GroupChannelModule,
256+
OpenChannelModule,
263257
],
264258
customExtensionParams,
265259
});
266260
expect(newSdk).toEqual(mockSdk);
267261
});
262+
it('should override default localCacheEnabled when provided in sdkInitParams', async () => {
263+
const setUpConnectionProps = generateSetUpConnectionParams();
264+
const { appId } = setUpConnectionProps;
265+
const sdkInitParams = {
266+
localCacheEnabled: false,
267+
};
268+
269+
const newSdk = initSDK({ appId, sdkInitParams });
270+
271+
// @ts-ignore
272+
expect(require('@sendbird/chat').init).toBeCalledWith({
273+
appId,
274+
newInstance: false,
275+
modules: [
276+
GroupChannelModule,
277+
OpenChannelModule,
278+
],
279+
localCacheEnabled: false,
280+
});
281+
expect(newSdk).toEqual(mockSdk);
282+
});
268283
});

src/lib/hooks/useConnect/setupConnection.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,11 @@ export function initSDK({
173173
sdkInitParams?: SendbirdChatInitParams;
174174
customExtensionParams?: CustomExtensionParams;
175175
}) {
176-
const params = Object.assign(sdkInitParams, {
177-
appId,
178-
modules: [new GroupChannelModule(), new OpenChannelModule()],
176+
const params = { appId,
177+
modules: [GroupChannelModule, OpenChannelModule],
179178
newInstance: isNewApp,
180179
localCacheEnabled: true,
181-
});
180+
...sdkInitParams };
182181

183182
if (customApiHost) params.customApiHost = customApiHost;
184183
if (customWebSocketHost) params.customWebSocketHost = customWebSocketHost;

0 commit comments

Comments
 (0)