Skip to content

Commit 99c69ec

Browse files
authored
Merge pull request #4 from xmartlabs/testing-module
Testing module
2 parents f148e57 + 29a9930 commit 99c69ec

12 files changed

Lines changed: 3493 additions & 84 deletions

.github/workflows/ci.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,3 @@ jobs:
4949

5050
- name: Build package
5151
run: yarn prepare
52-
53-
build-web:
54-
runs-on: ubuntu-latest
55-
steps:
56-
- name: Checkout
57-
uses: actions/checkout@v4
58-
59-
- name: Setup
60-
uses: ./.github/actions/setup
61-
62-
- name: Build example for Web
63-
run: |
64-
yarn example expo export --platform web

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,6 @@ lib/
8080
# React Native Codegen
8181
ios/generated
8282
android/generated
83+
84+
# Jest
85+
coverage/
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
getSdkStatus: jest.fn().mockResolvedValue('SDK_AVAILABLE'),
3+
initialize: jest.fn().mockResolvedValue(undefined),
4+
requestPermission: jest.fn().mockResolvedValue(['granted']),
5+
6+
readRecords: jest.fn().mockResolvedValue({ records: [] }),
7+
insertRecords: jest.fn().mockResolvedValue(undefined),
8+
9+
SdkAvailabilityStatus: {
10+
SDK_AVAILABLE: 'SDK_AVAILABLE',
11+
SDK_UNAVAILABLE: 'SDK_UNAVAILABLE',
12+
SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED:
13+
'SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED',
14+
},
15+
16+
RecordType: {
17+
BloodGlucose: 'BloodGlucose',
18+
Height: 'Height',
19+
Weight: 'Weight',
20+
HeartRate: 'HeartRate',
21+
RestingHeartRate: 'RestingHeartRate',
22+
BloodPressure: 'BloodPressure',
23+
OxygenSaturation: 'OxygenSaturation',
24+
Steps: 'Steps',
25+
ActiveCaloriesBurned: 'ActiveCaloriesBurned',
26+
BasalMetabolicRate: 'BasalMetabolicRate',
27+
},
28+
};
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
const mockCallback = (callback) => {
2+
if (typeof callback === 'function') {
3+
callback(null, []);
4+
}
5+
};
6+
7+
const mockFunctionWithCallback = jest.fn().mockImplementation(mockCallback);
8+
9+
const mockBloodPressureCallback = jest
10+
.fn()
11+
.mockImplementation((_, callback) => {
12+
callback(null, [
13+
{
14+
bloodPressureSystolicValue: 120,
15+
bloodPressureDiastolicValue: 80,
16+
startDate: '2023-01-01',
17+
endDate: '2023-01-01',
18+
id: 'bp-mock-1',
19+
sourceId: 'test-source',
20+
},
21+
]);
22+
});
23+
24+
const mockOxygenSaturationCallback = jest
25+
.fn()
26+
.mockImplementation((_, callback) => {
27+
callback(null, [
28+
{
29+
value: 0.98,
30+
unit: 'percent',
31+
startDate: '2023-01-01',
32+
endDate: '2023-01-01',
33+
id: 'o2-mock-1',
34+
},
35+
]);
36+
});
37+
38+
module.exports = {
39+
initHealthKit: jest.fn().mockImplementation((options, callback) => {
40+
if (typeof callback === 'function') {
41+
callback(null, true);
42+
}
43+
}),
44+
45+
isAvailable: jest.fn().mockImplementation((callback) => {
46+
callback(null, true);
47+
}),
48+
49+
getBloodGlucoseSamples: mockFunctionWithCallback,
50+
getHeightSamples: mockFunctionWithCallback,
51+
getWeightSamples: mockFunctionWithCallback,
52+
getHeartRateSamples: mockFunctionWithCallback,
53+
getRestingHeartRateSamples: mockFunctionWithCallback,
54+
getOxygenSaturationSamples: mockOxygenSaturationCallback,
55+
getBloodPressureSamples: mockBloodPressureCallback,
56+
getDailyStepCountSamples: mockFunctionWithCallback,
57+
getActiveEnergyBurned: mockFunctionWithCallback,
58+
getBasalEnergyBurned: mockFunctionWithCallback,
59+
60+
saveBloodGlucoseSample: jest.fn().mockImplementation((data, callback) => {
61+
if (typeof callback === 'function') {
62+
callback(null, true);
63+
}
64+
}),
65+
saveHeight: jest.fn().mockImplementation((data, callback) => {
66+
if (typeof callback === 'function') {
67+
callback(null, true);
68+
}
69+
}),
70+
saveWeight: jest.fn().mockImplementation((data, callback) => {
71+
if (typeof callback === 'function') {
72+
callback(null, true);
73+
}
74+
}),
75+
saveHeartRateSample: jest.fn().mockImplementation((data, callback) => {
76+
if (typeof callback === 'function') {
77+
callback(null, true);
78+
}
79+
}),
80+
saveSteps: jest.fn().mockImplementation((data, callback) => {
81+
if (typeof callback === 'function') {
82+
callback(null, true);
83+
}
84+
}),
85+
86+
Constants: {
87+
Permissions: {
88+
BloodGlucose: 'BloodGlucose',
89+
Height: 'Height',
90+
Weight: 'Weight',
91+
HeartRate: 'HeartRate',
92+
RestingHeartRate: 'RestingHeartRate',
93+
BloodPressureDiastolic: 'BloodPressureDiastolic',
94+
BloodPressureSystolic: 'BloodPressureSystolic',
95+
OxygenSaturation: 'OxygenSaturation',
96+
Steps: 'Steps',
97+
ActiveEnergyBurned: 'ActiveEnergyBurned',
98+
BasalEnergyBurned: 'BasalEnergyBurned',
99+
},
100+
Units: {
101+
gram: 'gram',
102+
kilogram: 'kilogram',
103+
ounce: 'ounce',
104+
pound: 'pound',
105+
meter: 'meter',
106+
inch: 'inch',
107+
foot: 'foot',
108+
centimeter: 'centimeter',
109+
bpm: 'count/min',
110+
calories: 'kcal',
111+
count: 'count',
112+
percent: 'percent',
113+
mmhg: 'mmHg',
114+
mmolPerL: 'mmol<180.1558800000541>/L',
115+
mgPerdL: 'mg/dL',
116+
},
117+
},
118+
119+
getDateOfBirth: mockFunctionWithCallback,
120+
getBiologicalSex: mockFunctionWithCallback,
121+
getLatestWeight: mockFunctionWithCallback,
122+
getLatestHeight: mockFunctionWithCallback,
123+
getLatestBmi: mockFunctionWithCallback,
124+
};

0 commit comments

Comments
 (0)