Skip to content

Commit 0673f0b

Browse files
authored
[CLNP-5591] Allow localCacheEnabled override through sdkInitParams (#1248)
Fixes https://sendbird.atlassian.net/browse/SBISSUE-17702 - Fix Object.assign order to allow proper parameter override - Add test case to verify localCacheEnabled override
1 parent 05f723d commit 0673f0b

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,27 @@ describe('useConnect/setupConnection/initSDK', () => {
265265
});
266266
expect(newSdk).toEqual(mockSdk);
267267
});
268+
it('should override default localCacheEnabled when provided in sdkInitParams', async () => {
269+
const setUpConnectionProps = generateSetUpConnectionParams();
270+
const { appId } = setUpConnectionProps;
271+
const sdkInitParams = {
272+
localCacheEnabled: false,
273+
};
274+
275+
const newSdk = initSDK({ appId, sdkInitParams });
276+
277+
// @ts-ignore
278+
expect(require('@sendbird/chat').init).toBeCalledWith({
279+
appId,
280+
newInstance: false,
281+
modules: [
282+
// @ts-ignore
283+
new (require('@sendbird/chat/groupChannel').GroupChannelModule)(),
284+
// @ts-ignore
285+
new (require('@sendbird/chat/openChannel').OpenChannelModule)(),
286+
],
287+
localCacheEnabled: false,
288+
});
289+
expect(newSdk).toEqual(mockSdk);
290+
});
268291
});

src/lib/hooks/useConnect/setupConnection.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,12 +173,13 @@ export function initSDK({
173173
sdkInitParams?: SendbirdChatInitParams;
174174
customExtensionParams?: CustomExtensionParams;
175175
}) {
176-
const params = Object.assign(sdkInitParams, {
176+
// eslint-disable-next-line prefer-object-spread -- not to break the existing types
177+
const params = Object.assign({}, {
177178
appId,
178179
modules: [new GroupChannelModule(), new OpenChannelModule()],
179180
newInstance: isNewApp,
180181
localCacheEnabled: true,
181-
});
182+
}, sdkInitParams);
182183

183184
if (customApiHost) params.customApiHost = customApiHost;
184185
if (customWebSocketHost) params.customWebSocketHost = customWebSocketHost;

0 commit comments

Comments
 (0)