Skip to content

Commit dda4e50

Browse files
Merge pull request #1438 from sendbird/fix/clnp-8533
[CLNP-8533] fix: detect super group channel via premiumFeatureList
2 parents 212ed23 + 5595e22 commit dda4e50

3 files changed

Lines changed: 78 additions & 5 deletions

File tree

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { isBroadcastChannelEnabled, isSuperGroupChannelEnabled } from '../utils';
2+
import type { SdkStore } from '../../../lib/Sendbird/types';
3+
4+
type Sdk = SdkStore['sdk'];
5+
6+
interface MockAppInfo {
7+
applicationAttributes?: string[];
8+
premiumFeatureList?: string[];
9+
}
10+
11+
const mockSdk = (appInfo: MockAppInfo | null): Sdk => ({ appInfo } as unknown as Sdk);
12+
const noSdk = undefined as unknown as Sdk;
13+
14+
describe('CreateChannel/utils: isSuperGroupChannelEnabled reads premiumFeatureList', () => {
15+
it('returns true when premiumFeatureList includes super_group_channel', () => {
16+
expect(isSuperGroupChannelEnabled(mockSdk({ premiumFeatureList: ['delivery_receipt', 'super_group_channel'] }))).toBe(true);
17+
});
18+
19+
it('returns false when premiumFeatureList does not include super_group_channel', () => {
20+
expect(isSuperGroupChannelEnabled(mockSdk({ premiumFeatureList: ['delivery_receipt'] }))).toBe(false);
21+
});
22+
23+
it('returns false for an empty premiumFeatureList', () => {
24+
expect(isSuperGroupChannelEnabled(mockSdk({ premiumFeatureList: [] }))).toBe(false);
25+
});
26+
27+
it('returns false when premiumFeatureList is missing', () => {
28+
expect(isSuperGroupChannelEnabled(mockSdk({}))).toBe(false);
29+
});
30+
31+
it('returns false when appInfo is null', () => {
32+
expect(isSuperGroupChannelEnabled(mockSdk(null))).toBe(false);
33+
});
34+
35+
it('returns false when sdk is undefined', () => {
36+
expect(isSuperGroupChannelEnabled(noSdk)).toBe(false);
37+
});
38+
39+
it('no longer reads the deprecated allow_super_group_channel applicationAttributes flag', () => {
40+
expect(isSuperGroupChannelEnabled(mockSdk({ applicationAttributes: ['allow_super_group_channel'], premiumFeatureList: [] }))).toBe(false);
41+
});
42+
});
43+
44+
describe('CreateChannel/utils: isBroadcastChannelEnabled still reads applicationAttributes', () => {
45+
it('returns true when applicationAttributes includes allow_broadcast_channel', () => {
46+
expect(isBroadcastChannelEnabled(mockSdk({ applicationAttributes: ['allow_broadcast_channel'] }))).toBe(true);
47+
});
48+
49+
it('returns false when applicationAttributes does not include allow_broadcast_channel', () => {
50+
expect(isBroadcastChannelEnabled(mockSdk({ applicationAttributes: ['allow_super_group_channel'] }))).toBe(false);
51+
});
52+
53+
it('returns false for an empty applicationAttributes', () => {
54+
expect(isBroadcastChannelEnabled(mockSdk({ applicationAttributes: [] }))).toBe(false);
55+
});
56+
57+
it('returns false when applicationAttributes is missing', () => {
58+
expect(isBroadcastChannelEnabled(mockSdk({}))).toBe(false);
59+
});
60+
61+
it('returns false when appInfo is null', () => {
62+
expect(isBroadcastChannelEnabled(mockSdk(null))).toBe(false);
63+
});
64+
65+
it('returns false when sdk is undefined', () => {
66+
expect(isBroadcastChannelEnabled(noSdk)).toBe(false);
67+
});
68+
69+
it('does not read broadcast_channel from premiumFeatureList', () => {
70+
expect(isBroadcastChannelEnabled(mockSdk({ premiumFeatureList: ['broadcast_channel'], applicationAttributes: [] }))).toBe(false);
71+
});
72+
});

src/modules/CreateChannel/utils.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { SdkStore } from '../../lib/Sendbird/types';
2+
import { SUPER_GROUP_CHANNEL } from '../../utils/consts';
23

34
export const isBroadcastChannelEnabled = (sdk: SdkStore['sdk']): boolean => {
45
const ALLOW_BROADCAST_CHANNEL = 'allow_broadcast_channel';
@@ -12,11 +13,10 @@ export const isBroadcastChannelEnabled = (sdk: SdkStore['sdk']): boolean => {
1213
};
1314

1415
export const isSuperGroupChannelEnabled = (sdk: SdkStore['sdk']): boolean => {
15-
const ALLOW_SUPER_GROUP_CHANNEL = 'allow_super_group_channel';
16-
const applicationAttributes = sdk?.appInfo?.applicationAttributes;
16+
const premiumFeatureList = sdk?.appInfo?.premiumFeatureList;
1717

18-
if (Array.isArray(applicationAttributes)) {
19-
return applicationAttributes.includes(ALLOW_SUPER_GROUP_CHANNEL);
18+
if (Array.isArray(premiumFeatureList)) {
19+
return premiumFeatureList.includes(SUPER_GROUP_CHANNEL);
2020
}
2121

2222
return false;

src/utils/consts.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@ export const META_ARRAY_VOICE_DURATION_KEY = 'KEY_VOICE_MESSAGE_DURATION';
3434
export const META_ARRAY_MESSAGE_TYPE_KEY = 'KEY_INTERNAL_MESSAGE_TYPE';
3535
export const META_ARRAY_MESSAGE_TYPE_VALUE__VOICE = 'voice/mp3';
3636

37-
// delivery receipt in feature list
37+
// premium feature list keys (appInfo.premiumFeatureList)
3838
export const DELIVERY_RECEIPT = 'delivery_receipt';
39+
export const SUPER_GROUP_CHANNEL = 'super_group_channel';
3940

4041
// file viewer slider
4142
export const SLIDER_BUTTON_ICON_SIDE_LENGTH = '32px';

0 commit comments

Comments
 (0)