-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
checkpoint testing for android health connect
- Loading branch information
1 parent
9ac4be0
commit dcbac86
Showing
13 changed files
with
278 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module.exports = { | ||
createClient: jest.fn(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
module.exports = { | ||
openHealthConnectSettings: jest.fn(), | ||
// assume installed for testing purposes. not worth getting into weeds | ||
initialize: () => true, | ||
getSdkStatus: () => 3, | ||
requestPermission: jest.fn(), | ||
readRecords: jest.fn(), | ||
revokeAllPermissions: jest.fn(), | ||
getGrantedPermissions: jest.fn(), | ||
SdkAvailabilityStatus: jest.fn(), | ||
SdkAvailabilityStatus: { | ||
SDK_UNAVAILABLE: 1, | ||
SDK_UNAVAILABLE_PROVIDER_UPDATE_REQUIRED: 2, | ||
SDK_AVAILABLE: 3, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module.exports = { | ||
Native: { | ||
captureException: jest.fn(), | ||
captureMessage: jest.fn(), | ||
}, | ||
Browser: { | ||
captureException: jest.fn(), | ||
captureMessage: jest.fn(), | ||
}, | ||
init: jest.fn(), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
jest.mock('sentry-expo'); | ||
jest.mock('@segment/analytics-react-native'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
src/utils/inventory/__tests__/android-health-connect.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
import item from '../android-health-connect'; | ||
import mockHealth from 'react-native-health-connect'; | ||
import Permission from 'react-native-health-connect/types'; | ||
|
||
jest.mock('react-native-health-connect'); | ||
|
||
beforeEach(() => { | ||
// assume app installed for simplicity of testing. | ||
// manually override when needed | ||
item.checkEligibility = async () => true; | ||
}); | ||
|
||
describe('InventoryItem', () => { | ||
it('should have correct properties', () => { | ||
expect(item.item).toHaveProperty('id'); | ||
expect(item.item).toHaveProperty('name'); | ||
expect(item.item).toHaveProperty('image'); | ||
expect(item.item).toHaveProperty('tags'); | ||
expect(item.item).toHaveProperty('attributes'); | ||
expect(item.item).toHaveProperty('datasource'); | ||
expect(item.item).toHaveProperty('installLink'); | ||
expect(item.item).toHaveProperty('checkStatus'); | ||
expect(item.item).toHaveProperty('canEquip'); | ||
expect(item.item).toHaveProperty('equip'); | ||
expect(item.item).toHaveProperty('unequip'); | ||
}); | ||
}); | ||
|
||
// too many issues with platform mocking and stuff so just assume android and installed | ||
describe('checkEligibility', () => { | ||
// TODO figure out how to mock Platform.OS. Jest defaults to ios | ||
// it('should return false if platform is not android', async () => { | ||
// jest.mock('react-native', () => ({ | ||
// Platform: { | ||
// OS: 'ios', | ||
// }, | ||
// expect(await item.checkEligibility()).toBe(false); | ||
// jest.mock('react-native', () => ({ | ||
// Platform: { | ||
// OS: 'web', | ||
// }, | ||
// expect(await item.checkEligibility()).toBe(false); | ||
// }); | ||
// it('should return true if platform is android', async () => { | ||
// initialize: () => true; | ||
// getSdkStatus: () => 1, | ||
// expect(await item.checkEligibility()).toBe(true); | ||
// }); | ||
// it('should return false if SDK is not available', async () => { | ||
// getSdkStatus: () => 1, | ||
// expect(await item.checkEligibility()).toBe(false); | ||
// }); | ||
// it('should throw error if SDK fails to initialize', async () => { | ||
// getSdkStatus: () => 3, | ||
// initialize: () => false, | ||
// expect(await item.checkEligibility()).rejects.toThrow('Unable to initialize Android Health'); | ||
// }); | ||
}); | ||
|
||
describe('initPermissions', () => { | ||
it('should return false if checkEligibility returns false', async () => { | ||
item.checkEligibility = async () => false; | ||
// mockHealth.requestPermission = async (perms) => perms; | ||
expect(await item.initPermissions()).toBe(false); | ||
}); | ||
|
||
it('should return true if permissions are granted', async () => { | ||
item.checkEligibility = async () => true; | ||
// mockHealth.requestPermission = async (perms) => perms; | ||
mockHealth.getGrantedPermissions = async () => item.permissions as Permission[]; | ||
expect(await item.initPermissions()).toBe(true); | ||
}); | ||
|
||
it('should return false if permissions are not granted', async () => { | ||
mockHealth.requestPermission = async () => []; | ||
mockHealth.getGrantedPermissions = async () => []; | ||
expect(await item.initPermissions()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('getPermissions', () => { | ||
it('should return false if checkEligibility returns false', async () => { | ||
item.checkEligibility = async () => false; | ||
// mockHealth.requestPermission = async (perms) => perms; | ||
mockHealth.getGrantedPermissions = async () => item.permissions as Permission[]; | ||
expect(await item.getPermissions()).toBe(false); | ||
}); | ||
|
||
it('should return false if no permissions are granted', async () => { | ||
// mockHealth.requestPermission = async (perms) => perms; | ||
mockHealth.getGrantedPermissions = async () => []; | ||
expect(await item.getPermissions()).toBe(false); | ||
}); | ||
|
||
it('should return true if permissions are granted', async () => { | ||
// mockHealth.requestPermission = async (perms) => perms; | ||
mockHealth.getGrantedPermissions = async () => item.permissions as Permission[]; | ||
expect(await item.getPermissions()).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('equip', () => { | ||
it('should return false if checkEligibility returns false', async () => { | ||
item.checkEligibility = async () => false; | ||
console.log('equip eligible', await item.checkEligibility()); | ||
expect(await item.equip()).toBe(false); | ||
}); | ||
|
||
it('should return true if permissions are initialized', async () => { | ||
item.initPermissions = async () => true; | ||
expect(await item.equip()).toBe(true); | ||
}); | ||
|
||
it('should return false if permissions are not initialized', async () => { | ||
(item.initPermissions = async () => false), expect(await item.equip()).toBe(false); | ||
}); | ||
}); | ||
|
||
describe('unequip', () => { | ||
it('should return true', async () => { | ||
expect(await item.unequip()).toBe(true); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.