|
| 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 | +}); |
0 commit comments