-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetup.ts
144 lines (128 loc) · 3.71 KB
/
setup.ts
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
import 'react-native-gesture-handler/jestSetup';
jest.useFakeTimers();
jest.mock(
'@nozbe/watermelondb/adapters/sqlite/makeDispatcher/index.native.js',
() => {
return jest.requireActual(
'@nozbe/watermelondb/adapters/sqlite/makeDispatcher/index.js',
);
},
);
jest.mock('./src/lib/bleManager');
jest.mock('expo-font');
jest.mock('expo-asset');
jest.mock('expo-secure-store');
jest.mock('expo-linking');
jest.mock('expo-file-system');
jest.mock('react-native/Libraries/EventEmitter/NativeEventEmitter');
jest.mock('react-native-reanimated', () => {
const Reanimated = require('react-native-reanimated/mock');
// The mock for `call` immediately calls the callback which is incorrect
// So we override it with a no-op
Reanimated.default.call = () => {};
return Reanimated;
});
jest.mock('expo-auth-session', () => {
let req: any = null;
let res: any = null;
const promptAsync = () => {
res = {type: 'success', params: {code: '123'}};
return Promise.resolve();
};
const useAuthRequest = () => {
return [req, res, promptAsync];
};
return {
makeRedirectUri: jest.fn(),
useAuthRequest,
};
});
jest.mock('./src/constants');
jest.mock('./src/lib/strava/api', () => {
const dummyToken = {
token_type: 'Bearer',
expires_at: Math.round(Date.now() / 1000) + 21600,
expires_in: 21600,
refresh_token: 'xyz',
access_token: 'abc',
athlete: {
id: 101,
username: null,
resource_state: 2,
firstname: 'Craig',
lastname: 'Mulligan',
bio: null,
city: '',
state: '',
country: null,
sex: null,
premium: false,
summit: false,
created_at: '2022-03-30T16:36:16Z',
updated_at: '2023-03-28T17:43:08Z',
badge_type_id: 0,
weight: 84.0008,
profile_medium:
'https://lh3.googleusercontent.com/a/AGNmyxafxyza4C7yewDLpgLWrmXW-Rmrds543HpKSrA_=s96-c',
profile:
'https://lh3.googleusercontent.com/a/AGNmyxafxyza4C7yewDLpgLWrmXW-Rmrds543HpKSrA_=s96-c',
friend: null,
follower: null,
},
};
const {token_type, expires_at, expires_in, refresh_token, access_token} =
dummyToken;
const uploads: any = [];
// @ts-ignore
const uploader = (_token, ride, _fileURI) => {
const payload = {
external_id: ride.id,
activity_id: uploads.length + 1,
id: uploads.length + 1,
error: null,
status: 'complete',
};
uploads.push(payload);
return Promise.resolve(payload);
};
return {
// ensure we don't call the API in
// tests accidentally
uploads,
authorize: jest.fn().mockResolvedValue(dummyToken),
refreshToken: jest.fn().mockResolvedValue({
token_type,
expires_at,
expires_in,
refresh_token,
access_token,
}),
upload: jest.fn(uploader),
};
});
jest.mock('expo-location', () => {
const mod = jest.requireActual('expo-location');
let _callbacks: any[] = [];
return {
...mod,
clearAll: () => {
_callbacks = [];
},
_emitLocation: (loc: any) => {
return Promise.all([_callbacks.map(cb => cb(loc))]);
},
requestForegroundPermissionsAsync: () => {
return Promise.resolve({status: 'granted'});
},
watchPositionAsync: jest.fn(function (_opts, cb) {
_callbacks.push(cb);
return Promise.resolve({remove: jest.fn()});
// jest.fn().mockResolvedValue()
}),
};
});
// Silence the warning: Animated: `useNativeDriver` is not supported because the native animated module is missing
// jest.mock('react-native/Libraries/Animated/src/NativeAnimatedHelper');
// As of [email protected] file has moved
jest.mock('react-native/Libraries/Animated/NativeAnimatedHelper');
// jest.mock('react-native/Libraries/Animated/Easing');