-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathgetSimInfo.test.js
More file actions
100 lines (77 loc) · 3.77 KB
/
getSimInfo.test.js
File metadata and controls
100 lines (77 loc) · 3.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// getSimInfo.test.js
import Ussd from './index';
import { Platform } from 'react-native';
// Corrected path for mock import assuming getSimInfo.test.js is in the project root
import { mockUssdGetSimInfo } from './__mocks__/react-native';
jest.mock('react-native'); // Ensures we use the mock
describe('Ussd.getSimInfo', () => {
beforeEach(() => {
jest.clearAllMocks();
});
describe('getSimInfo - Android', () => {
beforeAll(() => {
Platform.OS = 'android';
});
test('should retrieve single SIM data successfully', async () => {
const mockSimData = [{ subscriptionId: 1, slotIndex: 0, carrierName: 'NetA', countryIso: 'us', phoneNumber: '12345' }];
mockUssdGetSimInfo.mockResolvedValueOnce(mockSimData);
const result = await Ussd.getSimInfo();
expect(mockUssdGetSimInfo).toHaveBeenCalled();
expect(result).toEqual(mockSimData);
});
test('should retrieve multi-SIM data successfully', async () => {
const mockSimDataMulti = [
{ subscriptionId: 1, slotIndex: 0, carrierName: 'NetA', countryIso: 'us', phoneNumber: '123' },
{ subscriptionId: 2, slotIndex: 1, carrierName: 'NetB', countryIso: 'ca', phoneNumber: null }
];
mockUssdGetSimInfo.mockResolvedValueOnce(mockSimDataMulti);
const result = await Ussd.getSimInfo();
expect(mockUssdGetSimInfo).toHaveBeenCalled();
expect(result).toEqual(mockSimDataMulti);
});
test('should reject on permission error', async () => {
mockUssdGetSimInfo.mockRejectedValueOnce(new Error('Permission denied for getSimInfo'));
await expect(Ussd.getSimInfo()).rejects.toThrow('Permission denied for getSimInfo');
expect(mockUssdGetSimInfo).toHaveBeenCalled();
});
test('should return empty array on older Android (API < 22)', async () => {
mockUssdGetSimInfo.mockResolvedValueOnce([]); // Simulate native module returning empty array
const result = await Ussd.getSimInfo();
expect(mockUssdGetSimInfo).toHaveBeenCalled();
expect(result).toEqual([]);
});
});
describe('getSimInfo - iOS', () => {
beforeAll(() => {
Platform.OS = 'ios';
});
test('should retrieve single SIM representation successfully', async () => {
const mockSimDataIOS = [{ slotIndex: 0, subscriptionId: 0, carrierName: 'NetC', countryIso: 'gb', mobileCountryCode: '234', mobileNetworkCode: '10', phoneNumber: null }];
mockUssdGetSimInfo.mockResolvedValueOnce(mockSimDataIOS);
const result = await Ussd.getSimInfo();
expect(mockUssdGetSimInfo).toHaveBeenCalled();
expect(result).toEqual(mockSimDataIOS);
result.forEach(sim => {
expect(sim.phoneNumber).toBeNull();
});
});
test('should retrieve multi-SIM representation successfully (iOS 12+)', async () => {
const mockSimDataIOSMulti = [
{ slotIndex: 0, subscriptionId: 0, carrierName: 'NetC', countryIso: 'gb', mobileCountryCode: '234', mobileNetworkCode: '10', phoneNumber: null },
{ slotIndex: 1, subscriptionId: 1, carrierName: 'NetD', countryIso: 'de', mobileCountryCode: '262', mobileNetworkCode: '01', phoneNumber: null }
];
mockUssdGetSimInfo.mockResolvedValueOnce(mockSimDataIOSMulti);
const result = await Ussd.getSimInfo();
expect(mockUssdGetSimInfo).toHaveBeenCalled();
expect(result).toEqual(mockSimDataIOSMulti);
result.forEach(sim => {
expect(sim.phoneNumber).toBeNull();
});
});
test('should reject on native error', async () => {
mockUssdGetSimInfo.mockRejectedValueOnce(new Error('iOS CoreTelephony error'));
await expect(Ussd.getSimInfo()).rejects.toThrow('iOS CoreTelephony error');
expect(mockUssdGetSimInfo).toHaveBeenCalled();
});
});
});