Skip to content

Commit

Permalink
[CLNP-5591] Allow localCacheEnabled override through sdkInitParams (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
AhyoungRyu authored Nov 7, 2024
1 parent 05f723d commit 0673f0b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/lib/hooks/useConnect/__test__/setupConnection.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,4 +265,27 @@ describe('useConnect/setupConnection/initSDK', () => {
});
expect(newSdk).toEqual(mockSdk);
});
it('should override default localCacheEnabled when provided in sdkInitParams', async () => {
const setUpConnectionProps = generateSetUpConnectionParams();
const { appId } = setUpConnectionProps;
const sdkInitParams = {
localCacheEnabled: false,
};

const newSdk = initSDK({ appId, sdkInitParams });

// @ts-ignore
expect(require('@sendbird/chat').init).toBeCalledWith({
appId,
newInstance: false,
modules: [
// @ts-ignore
new (require('@sendbird/chat/groupChannel').GroupChannelModule)(),
// @ts-ignore
new (require('@sendbird/chat/openChannel').OpenChannelModule)(),
],
localCacheEnabled: false,
});
expect(newSdk).toEqual(mockSdk);
});
});
5 changes: 3 additions & 2 deletions src/lib/hooks/useConnect/setupConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,12 +173,13 @@ export function initSDK({
sdkInitParams?: SendbirdChatInitParams;
customExtensionParams?: CustomExtensionParams;
}) {
const params = Object.assign(sdkInitParams, {
// eslint-disable-next-line prefer-object-spread -- not to break the existing types
const params = Object.assign({}, {
appId,
modules: [new GroupChannelModule(), new OpenChannelModule()],
newInstance: isNewApp,
localCacheEnabled: true,
});
}, sdkInitParams);

if (customApiHost) params.customApiHost = customApiHost;
if (customWebSocketHost) params.customWebSocketHost = customWebSocketHost;
Expand Down

0 comments on commit 0673f0b

Please sign in to comment.