Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unit Tests for AndroidHealthConnect Inventory Item #3

Merged
merged 10 commits into from
Dec 10, 2023
3 changes: 3 additions & 0 deletions __mocks__/@segment/analytics-react-native.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
createClient: jest.fn(),
};
16 changes: 16 additions & 0 deletions __mocks__/react-native-health-connect.js
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: jest.fn(),
getSdkStatus: jest.fn(),
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,
},
};
11 changes: 11 additions & 0 deletions __mocks__/sentry-expo.js
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(),
};
118 changes: 118 additions & 0 deletions app.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
const isProd = process.env.EXPO_PUBLIC_APP_VARIANT === 'production';

const packageName = isProd ? 'com.jinnihealth' : `com.jinnihealth.${VARIANT}`;
const appName = isProd ? 'Jinni Health' : `Jinni Health (${VARIANT})`;
export default {
expo: {
name: appName,
slug: 'jinni-health',
version: '0.0.1',
orientation: 'portrait',
icon: './public/icon.png',
userInterfaceStyle: 'light',
splash: {
image: './public/splash.png',
resizeMode: 'contain',
backgroundColor: '#ffffff',
},
assetBundlePatterns: ['**/*'],
scheme: 'jinni-health',
plugins: [
'react-native-health',
'react-native-health-connect',
'react-native-nfc-manager',
[
'expo-build-properties',
{
ios: {
deploymentTarget: '16.0',
},
android: {
compileSdkVersion: 34,
targetSdkVersion: 34,
minSdkVersion: 26,
},
},
],
[
'expo-contacts',
{
contactsPermission:
'Allow your jinni to access your friends list to contact their jinn and communicate with them in the spiritual world.',
},
],
[
'expo-location',
{
locationAlwaysAndWhenInUsePermission:
'Allow your jinni to follow you and protect you around the world.',
isAndroidBackgroundLocationEnabled: false,
},
],
'expo-router',
'sentry-expo',
],
hooks: {
postPublish: [
{
file: 'sentry-expo/upload-sourcemaps',
config: {
organization: '${EXPO_PUBLIC_SENTRY_ORG}',
project: '${EXPO_PUBLIC_SENTRY_PROJECT}',
},
},
],
},
ios: {
supportsTablet: false,
infoPlist: {
NSContactsUsageDescription:
'Allow your jinni to access your friends list to contact their jinn and communicate with them in the spiritual world.',
},
bundleIdentifier: packageName,
},
android: {
adaptiveIcon: {
foregroundImage: './public/adaptive-icon.png',
backgroundColor: '#ffffff',
},
permissions: [
'android.permission.NFC',
'android.permission.READ_CONTACTS',
'android.permission.WRITE_CONTACTS',
'android.permission.health.READ_STEPS',
'android.permission.health.READ_ACTIVE_CALORIES_BURNED',
'android.permission.health.READ_TOTAL_CALORIES_BURNED',
'android.permission.health.READ_BASAL_METABOLIC_RATE',
'android.permission.health.READ_LEAN_BODY_MASS',
'android.permission.health.READ_BODY_FAT',
'android.permission.health.READ_EXERCISE',
'android.permission.health.READ_DISTANCE',
'android.permission.health.READ_HEART_RATE',
'android.permission.health.READ_NUTRITION',
'android.permission.health.READ_HYDRATION',
'android.permission.health.READ_RESPIRATORY_RATE',
'android.permission.health.READ_RESTING_HEART_RATE',
'android.permission.health.READ_SLEEP',
'android.permission.health.READ_WEIGHT',
'android.permission.ACCESS_COARSE_LOCATION',
'android.permission.ACCESS_FINE_LOCATION',
'android.permission.FOREGROUND_SERVICE',
],
package: packageName,
},
experiments: {
typedRoutes: true,
tsconfigPaths: true,
},
extra: {
router: {
origin: false,
},
eas: {
projectId: '9d90a8bf-a538-49f0-925c-afd83fd4c8d3',
},
},
owner: 'malik2',
},
};
113 changes: 0 additions & 113 deletions app.json

This file was deleted.

16 changes: 11 additions & 5 deletions eas.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,31 @@
"build": {
"development": {
"developmentClient": true,
"distribution": "internal"
},
"dev": {
"distribution": "internal",
"env": {
"EXPO_PUBLIC_APP_VARIANT": "development"
},
"android": {
"buildType": "apk",
"gradleCommand": ":app:assembleDebug"
}
},
"test": {
"env": {
"EXPO_PUBLIC_APP_VARIANT": "testing"
},
"android": {
"buildType": "apk",
"gradleCommand": ":app:assembleRelease"
"gradleCommand": ":app:assembleDebug"
}
},
"production": {
"env": {
"EXPO_PUBLIC_APP_VARIANT": "production"
},
"android": {
"buildType": "apk",
"gradleCommand": ":app:assembleRelease"
"gradleCommand": ":app:bundleProductionRelease"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,9 @@
},
"jest": {
"preset": "jest-expo",
"setupFiles": [
"<rootDir>/setupTests.js"
],
"transformIgnorePatterns": [
"node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)"
]
Expand Down
2 changes: 2 additions & 0 deletions setupTests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
jest.mock('sentry-expo');
jest.mock('@segment/analytics-react-native');
3 changes: 2 additions & 1 deletion src/app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,11 @@ const HomeScreen = () => {
const onIntentionPress = async () => {
const now = new Date();
const oneDayAgo = new Date(now.getTime() - 24 * 60 * 60 * 1000);
const startTime = oneDayAgo.toISOString();
const startTime = oneDayAgo.toISOString(); // TODO last activity time
const endTime = now.toISOString();
await getActivityData({ startTime, endTime });
};

return (
<View style={{ flex: 1, ...useTheme() }}>
<View style={styles.container}>
Expand Down
5 changes: 4 additions & 1 deletion src/app/inventory/[item].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ const ItemPage: React.FC<ItemPageProps> = () => {
? await item.equip(promptAsync)
: await item.equip();
// if result.error = "transceive fai" try majik ritual again
if (result) setStatus('post-equip');
if (result) {
setStatus('post-equip');
// TODO api request to add item to their avatar (:DataProvider or :Resource?)
}

// assume failure
setStatus('unequipped');
Expand Down
1 change: 1 addition & 0 deletions src/types/GameMechanics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export interface ItemAbility {
// TODO I feel like this should all be rolled into InventoryItem
export interface InventoryIntegration {
item: InventoryItem;
permissions?: string[];
checkEligibility: () => Promise<boolean>;
getPermissions: () => Promise<boolean>;
initPermissions: () => Promise<boolean>;
Expand Down
2 changes: 1 addition & 1 deletion src/types/UserConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ export type GameWidgetIds =
| 'stat-stength'
| 'stat-stamina'
| 'stat-spirit';
// player action portals

// player action portals
export type ItemWidgetIds =
| 'maliks-majik-leaderboard'
// identity
Expand Down
Loading
Loading