@trycourier/courier-react-native 5.6.17 → 5.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +66 -135
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/courierreactnative/CourierClientModule.kt +1 -0
- package/android/src/main/java/com/courierreactnative/CourierInboxViewManager.kt +2 -0
- package/android/src/main/java/com/courierreactnative/CourierPreferencesViewManager.kt +2 -0
- package/android/src/main/java/com/courierreactnative/CourierSharedModule.kt +3 -0
- package/android/src/main/java/com/courierreactnative/Utils.kt +11 -1
- package/courier-react-native.podspec +1 -1
- package/ios/CourierClientModule.swift +1 -0
- package/ios/CourierInboxReactNativeManager.swift +8 -0
- package/ios/CourierPreferencesReactNativeManager.swift +8 -0
- package/ios/CourierReactNativeDelegate.m +1 -1
- package/ios/CourierReactNativeEventEmitter.swift +1 -1
- package/ios/CourierReactNativeModule.m +1 -0
- package/ios/CourierSharedModule.swift +10 -3
- package/ios/Utils.swift +10 -0
- package/lib/commonjs/Broadcaster.js +5 -5
- package/lib/commonjs/Broadcaster.js.map +1 -1
- package/lib/commonjs/CourierApiUrls.js +29 -0
- package/lib/commonjs/CourierApiUrls.js.map +1 -0
- package/lib/commonjs/Modules.js.map +1 -1
- package/lib/commonjs/client/BrandClient.js.map +1 -1
- package/lib/commonjs/client/ClientModule.js.map +1 -1
- package/lib/commonjs/client/CourierClient.js +4 -1
- package/lib/commonjs/client/CourierClient.js.map +1 -1
- package/lib/commonjs/client/InboxClient.js.map +1 -1
- package/lib/commonjs/client/PreferenceClient.js.map +1 -1
- package/lib/commonjs/client/TokenClient.js.map +1 -1
- package/lib/commonjs/client/TrackingClient.js.map +1 -1
- package/lib/commonjs/index.js +22 -2
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/commonjs/models/CourierPushListener.js.map +1 -1
- package/lib/commonjs/models/CourierUserPreferences.js +13 -13
- package/lib/commonjs/models/CourierUserPreferences.js.map +1 -1
- package/lib/commonjs/models/InboxAction.js.map +1 -1
- package/lib/commonjs/models/InboxMessage.js.map +1 -1
- package/lib/commonjs/utils.js.map +1 -1
- package/lib/commonjs/views/CourierInboxView.js +13 -13
- package/lib/commonjs/views/CourierInboxView.js.map +1 -1
- package/lib/commonjs/views/CourierPreferencesView.js +4 -4
- package/lib/commonjs/views/CourierPreferencesView.js.map +1 -1
- package/lib/module/Broadcaster.js +7 -7
- package/lib/module/Broadcaster.js.map +1 -1
- package/lib/module/CourierApiUrls.js +20 -0
- package/lib/module/CourierApiUrls.js.map +1 -0
- package/lib/module/Modules.js +1 -1
- package/lib/module/Modules.js.map +1 -1
- package/lib/module/client/BrandClient.js +1 -1
- package/lib/module/client/BrandClient.js.map +1 -1
- package/lib/module/client/ClientModule.js +1 -1
- package/lib/module/client/ClientModule.js.map +1 -1
- package/lib/module/client/CourierClient.js +10 -7
- package/lib/module/client/CourierClient.js.map +1 -1
- package/lib/module/client/InboxClient.js +1 -1
- package/lib/module/client/InboxClient.js.map +1 -1
- package/lib/module/client/PreferenceClient.js +1 -1
- package/lib/module/client/PreferenceClient.js.map +1 -1
- package/lib/module/client/TokenClient.js +1 -1
- package/lib/module/client/TokenClient.js.map +1 -1
- package/lib/module/client/TrackingClient.js +1 -1
- package/lib/module/client/TrackingClient.js.map +1 -1
- package/lib/module/index.js +5 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/models/CourierAuthenticationListener.js +1 -1
- package/lib/module/models/CourierAuthenticationListener.js.map +1 -1
- package/lib/module/models/CourierInboxListener.js +1 -1
- package/lib/module/models/CourierPushListener.js.map +1 -1
- package/lib/module/models/CourierUserPreferences.js +13 -13
- package/lib/module/models/CourierUserPreferences.js.map +1 -1
- package/lib/module/models/InboxAction.js.map +1 -1
- package/lib/module/models/InboxMessage.js +1 -1
- package/lib/module/models/InboxMessage.js.map +1 -1
- package/lib/module/utils.js.map +1 -1
- package/lib/module/views/CourierInboxView.js +18 -18
- package/lib/module/views/CourierInboxView.js.map +1 -1
- package/lib/module/views/CourierPreferencesView.js +7 -7
- package/lib/module/views/CourierPreferencesView.js.map +1 -1
- package/lib/typescript/src/Broadcaster.d.ts +7 -7
- package/lib/typescript/src/Broadcaster.d.ts.map +1 -1
- package/lib/typescript/src/CourierApiUrls.d.ts +11 -0
- package/lib/typescript/src/CourierApiUrls.d.ts.map +1 -0
- package/lib/typescript/src/Modules.d.ts.map +1 -1
- package/lib/typescript/src/client/BrandClient.d.ts +1 -1
- package/lib/typescript/src/client/BrandClient.d.ts.map +1 -1
- package/lib/typescript/src/client/ClientModule.d.ts +1 -1
- package/lib/typescript/src/client/ClientModule.d.ts.map +1 -1
- package/lib/typescript/src/client/CourierClient.d.ts +9 -6
- package/lib/typescript/src/client/CourierClient.d.ts.map +1 -1
- package/lib/typescript/src/client/InboxClient.d.ts +1 -1
- package/lib/typescript/src/client/InboxClient.d.ts.map +1 -1
- package/lib/typescript/src/client/PreferenceClient.d.ts +1 -1
- package/lib/typescript/src/client/PreferenceClient.d.ts.map +1 -1
- package/lib/typescript/src/client/TokenClient.d.ts +1 -1
- package/lib/typescript/src/client/TokenClient.d.ts.map +1 -1
- package/lib/typescript/src/client/TrackingClient.d.ts +1 -1
- package/lib/typescript/src/client/TrackingClient.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +6 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/models/Android_CourierSheet.d.ts +1 -1
- package/lib/typescript/src/models/Android_CourierSheet.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierAuthenticationListener.d.ts +1 -1
- package/lib/typescript/src/models/CourierAuthenticationListener.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierBrand.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierButton.d.ts +1 -1
- package/lib/typescript/src/models/CourierButton.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierFont.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierInboxListener.d.ts +1 -1
- package/lib/typescript/src/models/CourierInboxMessages.d.ts +1 -1
- package/lib/typescript/src/models/CourierInboxTheme.d.ts +4 -3
- package/lib/typescript/src/models/CourierInboxTheme.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierInfoViewStyle.d.ts +2 -2
- package/lib/typescript/src/models/CourierInfoViewStyle.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierPreferencesTheme.d.ts +7 -6
- package/lib/typescript/src/models/CourierPreferencesTheme.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierPushListener.d.ts.map +1 -1
- package/lib/typescript/src/models/CourierUserPreferences.d.ts +1 -1
- package/lib/typescript/src/models/CourierUserPreferences.d.ts.map +1 -1
- package/lib/typescript/src/models/InboxAction.d.ts.map +1 -1
- package/lib/typescript/src/models/InboxMessage.d.ts +1 -1
- package/lib/typescript/src/models/InboxMessage.d.ts.map +1 -1
- package/lib/typescript/src/models/InboxMessageEvent.d.ts.map +1 -1
- package/lib/typescript/src/models/InboxMessageSet.d.ts +1 -1
- package/lib/typescript/src/models/iOS_CourierCell.d.ts.map +1 -1
- package/lib/typescript/src/models/iOS_CourierSheet.d.ts +1 -1
- package/lib/typescript/src/models/iOS_CourierSheet.d.ts.map +1 -1
- package/lib/typescript/src/utils.d.ts.map +1 -1
- package/lib/typescript/src/views/CourierInboxView.d.ts +5 -5
- package/lib/typescript/src/views/CourierInboxView.d.ts.map +1 -1
- package/lib/typescript/src/views/CourierPreferencesView.d.ts +3 -3
- package/lib/typescript/src/views/CourierPreferencesView.d.ts.map +1 -1
- package/package.json +8 -4
- package/src/Broadcaster.tsx +21 -15
- package/src/CourierApiUrls.tsx +30 -0
- package/src/Modules.tsx +22 -13
- package/src/client/BrandClient.tsx +6 -6
- package/src/client/ClientModule.tsx +4 -6
- package/src/client/CourierClient.tsx +20 -13
- package/src/client/InboxClient.tsx +40 -13
- package/src/client/PreferenceClient.tsx +47 -21
- package/src/client/TokenClient.tsx +14 -7
- package/src/client/TrackingClient.tsx +7 -6
- package/src/index.tsx +208 -115
- package/src/models/Android_CourierSheet.tsx +5 -5
- package/src/models/CourierAuthenticationListener.tsx +5 -9
- package/src/models/CourierBrand.tsx +6 -6
- package/src/models/CourierButton.tsx +5 -5
- package/src/models/CourierDevice.tsx +1 -1
- package/src/models/CourierFont.tsx +4 -4
- package/src/models/CourierInboxListener.tsx +3 -3
- package/src/models/CourierInboxMessages.tsx +2 -2
- package/src/models/CourierInboxTheme.tsx +56 -42
- package/src/models/CourierInfoViewStyle.tsx +5 -5
- package/src/models/CourierPaging.tsx +1 -1
- package/src/models/CourierPreferencesTheme.tsx +33 -27
- package/src/models/CourierPushListener.tsx +9 -7
- package/src/models/CourierPushProvider.tsx +1 -1
- package/src/models/CourierTrackingEvent.tsx +6 -6
- package/src/models/CourierUserPreferences.tsx +32 -28
- package/src/models/InboxAction.tsx +2 -6
- package/src/models/InboxMessage.tsx +4 -5
- package/src/models/InboxMessageEvent.tsx +7 -1
- package/src/models/InboxMessageFeed.tsx +1 -1
- package/src/models/InboxMessageSet.tsx +1 -1
- package/src/models/iOS_CourierCell.tsx +10 -5
- package/src/models/iOS_CourierSheet.tsx +4 -4
- package/src/utils.tsx +4 -7
- package/src/views/CourierInboxView.tsx +79 -71
- package/src/views/CourierPreferencesView.tsx +34 -35
- package/lib/example/src/App.js +0 -11
- package/lib/example/src/Emitter.js +0 -11
- package/lib/example/src/Env.js +0 -6
- package/lib/example/src/Home.js +0 -67
- package/lib/example/src/Poke.js +0 -75
- package/lib/example/src/Tabs.js +0 -36
- package/lib/example/src/Utils.js +0 -71
- package/lib/example/src/pages/Auth.js +0 -224
- package/lib/example/src/pages/Inbox.js +0 -38
- package/lib/example/src/pages/Preferences.js +0 -13
- package/lib/example/src/pages/PreferencesStack.js +0 -11
- package/lib/example/src/pages/Push.js +0 -93
- package/lib/example/src/pages/Styles.js +0 -26
- package/lib/example/src/pages/Tests.js +0 -1068
- package/lib/example/src/pages/inbox/InboxCustom.js +0 -141
- package/lib/example/src/pages/inbox/InboxDefault.js +0 -22
- package/lib/example/src/pages/inbox/InboxStyled.js +0 -220
- package/lib/example/src/pages/preferences/PreferencesCustom.js +0 -91
- package/lib/example/src/pages/preferences/PreferencesDefault.js +0 -17
- package/lib/example/src/pages/preferences/PreferencesDetail.js +0 -127
- package/lib/example/src/pages/preferences/PreferencesStyled.js +0 -110
- package/lib/package.json +0 -171
- package/lib/src/Broadcaster.js +0 -24
- package/lib/src/Modules.js +0 -26
- package/lib/src/client/BrandClient.js +0 -17
- package/lib/src/client/ClientModule.js +0 -14
- package/lib/src/client/CourierClient.js +0 -31
- package/lib/src/client/InboxClient.js +0 -99
- package/lib/src/client/PreferenceClient.js +0 -63
- package/lib/src/client/TokenClient.js +0 -27
- package/lib/src/client/TrackingClient.js +0 -17
- package/lib/src/index.js +0 -567
- package/lib/src/models/Android_CourierSheet.js +0 -1
- package/lib/src/models/CourierAuthenticationListener.js +0 -14
- package/lib/src/models/CourierBrand.js +0 -1
- package/lib/src/models/CourierButton.js +0 -1
- package/lib/src/models/CourierDevice.js +0 -1
- package/lib/src/models/CourierFont.js +0 -1
- package/lib/src/models/CourierInboxListener.js +0 -20
- package/lib/src/models/CourierInboxMessages.js +0 -1
- package/lib/src/models/CourierInboxTheme.js +0 -1
- package/lib/src/models/CourierInfoViewStyle.js +0 -1
- package/lib/src/models/CourierPaging.js +0 -1
- package/lib/src/models/CourierPreferencesTheme.js +0 -1
- package/lib/src/models/CourierPushListener.js +0 -14
- package/lib/src/models/CourierPushProvider.js +0 -8
- package/lib/src/models/CourierTrackingEvent.js +0 -8
- package/lib/src/models/CourierUserPreferences.js +0 -51
- package/lib/src/models/InboxAction.js +0 -1
- package/lib/src/models/InboxMessage.js +0 -1
- package/lib/src/models/InboxMessageFeed.js +0 -1
- package/lib/src/models/InboxMessageSet.js +0 -1
- package/lib/src/models/iOS_CourierCell.js +0 -1
- package/lib/src/models/iOS_CourierSheet.js +0 -1
- package/lib/src/utils.js +0 -27
- package/lib/src/views/CourierInboxView.js +0 -75
- package/lib/src/views/CourierPreferencesView.js +0 -33
|
@@ -1,1068 +0,0 @@
|
|
|
1
|
-
import React, { useState, useEffect } from 'react';
|
|
2
|
-
import { View, Text, StyleSheet, ActivityIndicator, Platform, FlatList, TouchableOpacity, TextInput, Modal, Button, Switch, TouchableWithoutFeedback, Keyboard } from 'react-native';
|
|
3
|
-
import { useNavigation } from '@react-navigation/native';
|
|
4
|
-
import Courier, { CourierClient } from '@trycourier/courier-react-native';
|
|
5
|
-
import Env from '../Env';
|
|
6
|
-
import { ExampleServer, Utils } from '../Utils';
|
|
7
|
-
let savedClient = undefined;
|
|
8
|
-
const IntegrationTests = {
|
|
9
|
-
createClient: async (params) => {
|
|
10
|
-
const token = params.jwt ?? await ExampleServer.generateJwt({
|
|
11
|
-
authKey: Env.authKey,
|
|
12
|
-
userId: params.userId,
|
|
13
|
-
});
|
|
14
|
-
savedClient = new CourierClient({
|
|
15
|
-
userId: params.userId,
|
|
16
|
-
showLogs: params.showLogs,
|
|
17
|
-
jwt: token,
|
|
18
|
-
clientKey: params.clientKey,
|
|
19
|
-
tenantId: params.tenantId,
|
|
20
|
-
connectionId: params.connectionId,
|
|
21
|
-
});
|
|
22
|
-
return {
|
|
23
|
-
id: savedClient.clientId,
|
|
24
|
-
options: savedClient.options,
|
|
25
|
-
};
|
|
26
|
-
},
|
|
27
|
-
removeClient: async (params) => {
|
|
28
|
-
let id = params.clientId;
|
|
29
|
-
if (savedClient) {
|
|
30
|
-
id = savedClient.clientId;
|
|
31
|
-
savedClient.remove();
|
|
32
|
-
savedClient = undefined;
|
|
33
|
-
}
|
|
34
|
-
return {
|
|
35
|
-
clientId: id,
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
testPutToken: async (params) => {
|
|
39
|
-
if (!savedClient) {
|
|
40
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
41
|
-
}
|
|
42
|
-
await savedClient.tokens.putUserToken({
|
|
43
|
-
provider: params.provider,
|
|
44
|
-
token: params.token,
|
|
45
|
-
});
|
|
46
|
-
return { token: params.token, provider: params.provider };
|
|
47
|
-
},
|
|
48
|
-
testDeleteToken: async (params) => {
|
|
49
|
-
if (!savedClient) {
|
|
50
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
51
|
-
}
|
|
52
|
-
await savedClient.tokens.deleteUserToken({ token: params.token });
|
|
53
|
-
},
|
|
54
|
-
testGetBrands: async (params) => {
|
|
55
|
-
if (!savedClient) {
|
|
56
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
57
|
-
}
|
|
58
|
-
const brand = await savedClient.brands.getBrand({ brandId: params.brandId });
|
|
59
|
-
return brand;
|
|
60
|
-
},
|
|
61
|
-
testMessages: async (params) => {
|
|
62
|
-
if (!savedClient) {
|
|
63
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
64
|
-
}
|
|
65
|
-
return await savedClient.inbox.getMessages({
|
|
66
|
-
paginationLimit: params.paginationLimit,
|
|
67
|
-
startCursor: params.startCursor,
|
|
68
|
-
});
|
|
69
|
-
},
|
|
70
|
-
testUnreadCount: async () => {
|
|
71
|
-
if (!savedClient) {
|
|
72
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
73
|
-
}
|
|
74
|
-
const count = await savedClient.inbox.getUnreadMessageCount();
|
|
75
|
-
console.log('Unread Count:', count);
|
|
76
|
-
return count;
|
|
77
|
-
},
|
|
78
|
-
testArchivedMessages: async (params) => {
|
|
79
|
-
if (!savedClient) {
|
|
80
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
81
|
-
}
|
|
82
|
-
return await savedClient.inbox.getArchivedMessages({
|
|
83
|
-
paginationLimit: params.paginationLimit,
|
|
84
|
-
startCursor: params.startCursor,
|
|
85
|
-
});
|
|
86
|
-
},
|
|
87
|
-
testMessageById: async (params) => {
|
|
88
|
-
if (!savedClient) {
|
|
89
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
90
|
-
}
|
|
91
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
92
|
-
const result = await ExampleServer.sendTest({
|
|
93
|
-
authKey: Env.authKey,
|
|
94
|
-
userId: savedClient.options.userId,
|
|
95
|
-
channel: 'inbox',
|
|
96
|
-
});
|
|
97
|
-
setTimeout(() => resolve(result), 5000);
|
|
98
|
-
});
|
|
99
|
-
return await savedClient.inbox.getMessageById({
|
|
100
|
-
messageId: messageId,
|
|
101
|
-
});
|
|
102
|
-
},
|
|
103
|
-
openMessage: async (params) => {
|
|
104
|
-
if (!savedClient) {
|
|
105
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
106
|
-
}
|
|
107
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
108
|
-
const result = await ExampleServer.sendTest({
|
|
109
|
-
authKey: Env.authKey,
|
|
110
|
-
userId: savedClient.options.userId,
|
|
111
|
-
channel: 'inbox',
|
|
112
|
-
});
|
|
113
|
-
setTimeout(() => resolve(result), 5000);
|
|
114
|
-
});
|
|
115
|
-
await savedClient.inbox.open({
|
|
116
|
-
messageId: messageId,
|
|
117
|
-
});
|
|
118
|
-
return { messageId: messageId };
|
|
119
|
-
},
|
|
120
|
-
clickMessage: async (params) => {
|
|
121
|
-
if (!savedClient) {
|
|
122
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
123
|
-
}
|
|
124
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
125
|
-
const result = await ExampleServer.sendTest({
|
|
126
|
-
authKey: Env.authKey,
|
|
127
|
-
userId: savedClient.options.userId,
|
|
128
|
-
channel: 'inbox',
|
|
129
|
-
});
|
|
130
|
-
setTimeout(() => resolve(result), 5000);
|
|
131
|
-
});
|
|
132
|
-
await savedClient.inbox.click({
|
|
133
|
-
messageId: messageId,
|
|
134
|
-
trackingId: params.trackingId ?? 'test-tracking-id',
|
|
135
|
-
});
|
|
136
|
-
return { messageId: messageId };
|
|
137
|
-
},
|
|
138
|
-
readMessage: async (params) => {
|
|
139
|
-
if (!savedClient) {
|
|
140
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
141
|
-
}
|
|
142
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
143
|
-
const result = await ExampleServer.sendTest({
|
|
144
|
-
authKey: Env.authKey,
|
|
145
|
-
userId: savedClient.options.userId,
|
|
146
|
-
channel: 'inbox',
|
|
147
|
-
});
|
|
148
|
-
setTimeout(() => resolve(result), 5000);
|
|
149
|
-
});
|
|
150
|
-
await savedClient.inbox.read({
|
|
151
|
-
messageId: messageId,
|
|
152
|
-
});
|
|
153
|
-
return { messageId: messageId };
|
|
154
|
-
},
|
|
155
|
-
unreadMessage: async (params) => {
|
|
156
|
-
if (!savedClient) {
|
|
157
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
158
|
-
}
|
|
159
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
160
|
-
const result = await ExampleServer.sendTest({
|
|
161
|
-
authKey: Env.authKey,
|
|
162
|
-
userId: savedClient.options.userId,
|
|
163
|
-
channel: 'inbox',
|
|
164
|
-
});
|
|
165
|
-
setTimeout(() => resolve(result), 5000);
|
|
166
|
-
});
|
|
167
|
-
await savedClient.inbox.unread({
|
|
168
|
-
messageId: messageId,
|
|
169
|
-
});
|
|
170
|
-
return { messageId: messageId };
|
|
171
|
-
},
|
|
172
|
-
archiveMessage: async (params) => {
|
|
173
|
-
if (!savedClient) {
|
|
174
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
175
|
-
}
|
|
176
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
177
|
-
const result = await ExampleServer.sendTest({
|
|
178
|
-
authKey: Env.authKey,
|
|
179
|
-
userId: savedClient.options.userId,
|
|
180
|
-
channel: 'inbox',
|
|
181
|
-
});
|
|
182
|
-
setTimeout(() => resolve(result), 5000);
|
|
183
|
-
});
|
|
184
|
-
await savedClient.inbox.archive({
|
|
185
|
-
messageId: messageId,
|
|
186
|
-
});
|
|
187
|
-
return { messageId: messageId };
|
|
188
|
-
},
|
|
189
|
-
readAllMessages: async () => {
|
|
190
|
-
if (!savedClient) {
|
|
191
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
192
|
-
}
|
|
193
|
-
await savedClient.inbox.readAll();
|
|
194
|
-
},
|
|
195
|
-
testGetPreferences: async () => {
|
|
196
|
-
if (!savedClient) {
|
|
197
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
198
|
-
}
|
|
199
|
-
return await savedClient.preferences.getUserPreferences();
|
|
200
|
-
},
|
|
201
|
-
testUpdatePreferences: async (params) => {
|
|
202
|
-
if (!savedClient) {
|
|
203
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
204
|
-
}
|
|
205
|
-
await savedClient.preferences.putUserPreferenceTopic({
|
|
206
|
-
topicId: params.topicId,
|
|
207
|
-
status: params.status,
|
|
208
|
-
hasCustomRouting: params.hasCustomRouting,
|
|
209
|
-
customRouting: params.customRouting.split(',').map(channel => channel.trim()),
|
|
210
|
-
});
|
|
211
|
-
},
|
|
212
|
-
testGetPreferenceTopics: async (params) => {
|
|
213
|
-
if (!savedClient) {
|
|
214
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
215
|
-
}
|
|
216
|
-
return await savedClient.preferences.getUserPreferenceTopic({ topicId: params.topicId });
|
|
217
|
-
},
|
|
218
|
-
testPostTrackingUrl: async (params) => {
|
|
219
|
-
if (!savedClient) {
|
|
220
|
-
throw new Error("Client not initialized. Run createClient first.");
|
|
221
|
-
}
|
|
222
|
-
return await savedClient.tracking.postTrackingUrl({
|
|
223
|
-
url: params.trackingUrl,
|
|
224
|
-
event: params.event,
|
|
225
|
-
});
|
|
226
|
-
},
|
|
227
|
-
testSignIn: async (params) => {
|
|
228
|
-
const token = params.accessToken ?? await ExampleServer.generateJwt({
|
|
229
|
-
authKey: Env.authKey,
|
|
230
|
-
userId: params.userId,
|
|
231
|
-
});
|
|
232
|
-
await Courier.shared.signIn({
|
|
233
|
-
userId: params.userId,
|
|
234
|
-
accessToken: token,
|
|
235
|
-
clientKey: params.clientKey,
|
|
236
|
-
tenantId: params.tenantId,
|
|
237
|
-
showLogs: params.showLogs,
|
|
238
|
-
});
|
|
239
|
-
const client = await Courier.shared.getClient();
|
|
240
|
-
return client?.options;
|
|
241
|
-
},
|
|
242
|
-
testGetUserId: async () => {
|
|
243
|
-
return await Courier.shared.getUserId();
|
|
244
|
-
},
|
|
245
|
-
testGetTenantId: async () => {
|
|
246
|
-
return await Courier.shared.getTenantId();
|
|
247
|
-
},
|
|
248
|
-
testGetIsUserSignedIn: async () => {
|
|
249
|
-
return await Courier.shared.isUserSignedIn();
|
|
250
|
-
},
|
|
251
|
-
testAuthenticationListener: async () => {
|
|
252
|
-
const listener = await Courier.shared.addAuthenticationListener({
|
|
253
|
-
onUserChanged: (userId) => {
|
|
254
|
-
console.log('User changed:', userId);
|
|
255
|
-
},
|
|
256
|
-
});
|
|
257
|
-
listener.remove();
|
|
258
|
-
return listener.listenerId;
|
|
259
|
-
},
|
|
260
|
-
testRemoveAllAuthenticationListeners: async () => {
|
|
261
|
-
return Courier.shared.removeAllAuthenticationListeners();
|
|
262
|
-
},
|
|
263
|
-
testSignOut: async () => {
|
|
264
|
-
await Courier.shared.signOut();
|
|
265
|
-
},
|
|
266
|
-
testGetClient: async () => {
|
|
267
|
-
const client = await Courier.shared.getClient();
|
|
268
|
-
return {
|
|
269
|
-
clientId: client?.clientId,
|
|
270
|
-
options: client?.options,
|
|
271
|
-
};
|
|
272
|
-
},
|
|
273
|
-
testGetAllTokens: async () => {
|
|
274
|
-
const tokens = await Courier.shared.getAllTokens();
|
|
275
|
-
const tokenObject = {};
|
|
276
|
-
tokens.forEach((value, key) => {
|
|
277
|
-
tokenObject[key] = value;
|
|
278
|
-
});
|
|
279
|
-
return tokenObject;
|
|
280
|
-
},
|
|
281
|
-
testGetToken: async (params) => {
|
|
282
|
-
return await Courier.shared.getToken({ key: params.provider });
|
|
283
|
-
},
|
|
284
|
-
testSetToken: async (params) => {
|
|
285
|
-
return await Courier.shared.setToken({ key: params.provider, token: params.token });
|
|
286
|
-
},
|
|
287
|
-
testAddPushNotificationListener: async () => {
|
|
288
|
-
const listener = Courier.shared.addPushNotificationListener({
|
|
289
|
-
onPushNotificationClicked: (push) => {
|
|
290
|
-
console.log('Push notification clicked:', push);
|
|
291
|
-
},
|
|
292
|
-
});
|
|
293
|
-
listener.remove();
|
|
294
|
-
return listener.listenerId;
|
|
295
|
-
},
|
|
296
|
-
testRemoveAllPushNotificationListeners: async () => {
|
|
297
|
-
return Courier.shared.removeAllPushNotificationListeners();
|
|
298
|
-
},
|
|
299
|
-
testSetInboxPaginationLimit: async (params) => {
|
|
300
|
-
await Courier.shared.setInboxPaginationLimit(params.limit);
|
|
301
|
-
},
|
|
302
|
-
testGetInboxPaginationLimit: async () => {
|
|
303
|
-
return await Courier.shared.getInboxPaginationLimit();
|
|
304
|
-
},
|
|
305
|
-
testOpenMessage: async (params) => {
|
|
306
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
307
|
-
const result = await ExampleServer.sendTest({
|
|
308
|
-
authKey: Env.authKey,
|
|
309
|
-
userId: await Courier.shared.getUserId() ?? '',
|
|
310
|
-
channel: 'inbox',
|
|
311
|
-
});
|
|
312
|
-
setTimeout(() => resolve(result), 5000);
|
|
313
|
-
});
|
|
314
|
-
await Courier.shared.openMessage({ messageId: messageId });
|
|
315
|
-
return { messageId: messageId };
|
|
316
|
-
},
|
|
317
|
-
testClickMessage: async (params) => {
|
|
318
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
319
|
-
const result = await ExampleServer.sendTest({
|
|
320
|
-
authKey: Env.authKey,
|
|
321
|
-
userId: await Courier.shared.getUserId() ?? '',
|
|
322
|
-
channel: 'inbox',
|
|
323
|
-
});
|
|
324
|
-
setTimeout(() => resolve(result), 5000);
|
|
325
|
-
});
|
|
326
|
-
await Courier.shared.clickMessage({ messageId: messageId });
|
|
327
|
-
return { messageId: messageId };
|
|
328
|
-
},
|
|
329
|
-
testReadMessage: async (params) => {
|
|
330
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
331
|
-
const result = await ExampleServer.sendTest({
|
|
332
|
-
authKey: Env.authKey,
|
|
333
|
-
userId: await Courier.shared.getUserId() ?? '',
|
|
334
|
-
channel: 'inbox',
|
|
335
|
-
});
|
|
336
|
-
setTimeout(() => resolve(result), 5000);
|
|
337
|
-
});
|
|
338
|
-
await Courier.shared.readMessage({ messageId: messageId });
|
|
339
|
-
return { messageId: messageId };
|
|
340
|
-
},
|
|
341
|
-
testUnreadMessage: async (params) => {
|
|
342
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
343
|
-
const result = await ExampleServer.sendTest({
|
|
344
|
-
authKey: Env.authKey,
|
|
345
|
-
userId: await Courier.shared.getUserId() ?? '',
|
|
346
|
-
channel: 'inbox',
|
|
347
|
-
});
|
|
348
|
-
setTimeout(() => resolve(result), 5000);
|
|
349
|
-
});
|
|
350
|
-
await Courier.shared.unreadMessage({ messageId: messageId });
|
|
351
|
-
return { messageId: messageId };
|
|
352
|
-
},
|
|
353
|
-
testArchiveMessage: async (params) => {
|
|
354
|
-
const messageId = params.messageId ?? await new Promise(async (resolve) => {
|
|
355
|
-
const result = await ExampleServer.sendTest({
|
|
356
|
-
authKey: Env.authKey,
|
|
357
|
-
userId: await Courier.shared.getUserId() ?? '',
|
|
358
|
-
channel: 'inbox',
|
|
359
|
-
});
|
|
360
|
-
setTimeout(() => resolve(result), 5000);
|
|
361
|
-
});
|
|
362
|
-
await Courier.shared.archiveMessage({ messageId: messageId });
|
|
363
|
-
return { messageId: messageId };
|
|
364
|
-
},
|
|
365
|
-
testReadAllInboxMessages: async () => {
|
|
366
|
-
return await Courier.shared.readAllInboxMessages();
|
|
367
|
-
},
|
|
368
|
-
testAddInboxListener: async () => {
|
|
369
|
-
const listener = await Courier.shared.addInboxListener({
|
|
370
|
-
onInitialLoad: () => {
|
|
371
|
-
console.log('Inbox initial load');
|
|
372
|
-
},
|
|
373
|
-
onError: (error) => {
|
|
374
|
-
console.log('Inbox error:', error);
|
|
375
|
-
},
|
|
376
|
-
onFeedChanged: (messageSet) => {
|
|
377
|
-
console.log('Inbox messages changed:', messageSet);
|
|
378
|
-
},
|
|
379
|
-
});
|
|
380
|
-
await listener.remove();
|
|
381
|
-
return listener;
|
|
382
|
-
},
|
|
383
|
-
testRemoveAllInboxListeners: async () => {
|
|
384
|
-
return Courier.shared.removeAllInboxListeners();
|
|
385
|
-
},
|
|
386
|
-
testRefreshInbox: async () => {
|
|
387
|
-
return await Courier.shared.refreshInbox();
|
|
388
|
-
},
|
|
389
|
-
testFetchNextPageOfMessages: async () => {
|
|
390
|
-
return await Courier.shared.fetchNextPageOfMessages({ inboxMessageFeed: 'feed' });
|
|
391
|
-
},
|
|
392
|
-
testRequestPushNotificationPermission: async () => {
|
|
393
|
-
return await Courier.requestNotificationPermission();
|
|
394
|
-
},
|
|
395
|
-
testGetPushNotificationPermissionStatus: async () => {
|
|
396
|
-
return await Courier.getNotificationPermissionStatus();
|
|
397
|
-
},
|
|
398
|
-
testSetIOSForegroundPresentationOptions: async (params) => {
|
|
399
|
-
return Courier.setIOSForegroundPresentationOptions({ options: params.options });
|
|
400
|
-
},
|
|
401
|
-
testOpenSettingsForApp: async () => {
|
|
402
|
-
return Courier.openSettingsForApp();
|
|
403
|
-
},
|
|
404
|
-
testSendInboxMessage: async (params) => {
|
|
405
|
-
const messageId = await ExampleServer.sendTest({
|
|
406
|
-
authKey: Env.authKey,
|
|
407
|
-
userId: params.userId,
|
|
408
|
-
channel: 'inbox',
|
|
409
|
-
title: params.title ?? 'Test',
|
|
410
|
-
body: params.body ?? 'Body',
|
|
411
|
-
});
|
|
412
|
-
return { messageId: messageId };
|
|
413
|
-
},
|
|
414
|
-
testSendApnMessage: async (params) => {
|
|
415
|
-
const messageId = await ExampleServer.sendTest({
|
|
416
|
-
authKey: Env.authKey,
|
|
417
|
-
userId: params.userId,
|
|
418
|
-
channel: 'apn',
|
|
419
|
-
title: params.title ?? 'Test',
|
|
420
|
-
body: params.body ?? 'Body',
|
|
421
|
-
});
|
|
422
|
-
return { messageId: messageId };
|
|
423
|
-
},
|
|
424
|
-
testSendFcmMessage: async (params) => {
|
|
425
|
-
const messageId = await ExampleServer.sendTest({
|
|
426
|
-
authKey: Env.authKey,
|
|
427
|
-
userId: params.userId,
|
|
428
|
-
channel: 'firebase-fcm',
|
|
429
|
-
title: params.title ?? 'Test',
|
|
430
|
-
body: params.body ?? 'Body',
|
|
431
|
-
});
|
|
432
|
-
return { messageId: messageId };
|
|
433
|
-
},
|
|
434
|
-
};
|
|
435
|
-
const getTestSections = async () => [
|
|
436
|
-
{
|
|
437
|
-
title: 'Client Management',
|
|
438
|
-
tests: [
|
|
439
|
-
{
|
|
440
|
-
name: 'Create Client',
|
|
441
|
-
testId: 'createClient',
|
|
442
|
-
defaultParams: { userId: Utils.generateUUID(), clientKey: Env.clientKey, showLogs: true, tenantId: undefined, connectionId: undefined },
|
|
443
|
-
runOrder: 'normal'
|
|
444
|
-
},
|
|
445
|
-
{
|
|
446
|
-
name: 'Remove Client',
|
|
447
|
-
testId: 'removeClient',
|
|
448
|
-
defaultParams: { clientId: savedClient?.clientId },
|
|
449
|
-
runOrder: 'skip'
|
|
450
|
-
},
|
|
451
|
-
]
|
|
452
|
-
},
|
|
453
|
-
{
|
|
454
|
-
title: 'Tokens',
|
|
455
|
-
tests: [
|
|
456
|
-
{
|
|
457
|
-
name: 'Put Token',
|
|
458
|
-
testId: 'testPutToken',
|
|
459
|
-
defaultParams: { token: 'test-token', provider: 'test-provider' },
|
|
460
|
-
runOrder: 'normal'
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
name: 'Delete Token',
|
|
464
|
-
testId: 'testDeleteToken',
|
|
465
|
-
defaultParams: { token: 'test-token' },
|
|
466
|
-
runOrder: 'normal'
|
|
467
|
-
},
|
|
468
|
-
]
|
|
469
|
-
},
|
|
470
|
-
{
|
|
471
|
-
title: 'Brands',
|
|
472
|
-
tests: [
|
|
473
|
-
{
|
|
474
|
-
name: 'Get Brand',
|
|
475
|
-
testId: 'testGetBrands',
|
|
476
|
-
defaultParams: { brandId: Env.brandId },
|
|
477
|
-
runOrder: 'normal'
|
|
478
|
-
},
|
|
479
|
-
]
|
|
480
|
-
},
|
|
481
|
-
{
|
|
482
|
-
title: 'Inbox',
|
|
483
|
-
tests: [
|
|
484
|
-
{
|
|
485
|
-
name: 'Get Messages',
|
|
486
|
-
testId: 'testMessages',
|
|
487
|
-
defaultParams: { paginationLimit: 10, paginationCursor: undefined },
|
|
488
|
-
runOrder: 'normal'
|
|
489
|
-
},
|
|
490
|
-
{
|
|
491
|
-
name: 'Get Unread Count',
|
|
492
|
-
testId: 'testUnreadCount',
|
|
493
|
-
defaultParams: {},
|
|
494
|
-
runOrder: 'normal'
|
|
495
|
-
},
|
|
496
|
-
{
|
|
497
|
-
name: 'Get Archived Messages',
|
|
498
|
-
testId: 'testArchivedMessages',
|
|
499
|
-
defaultParams: { paginationLimit: 10, paginationCursor: undefined },
|
|
500
|
-
runOrder: 'normal'
|
|
501
|
-
},
|
|
502
|
-
{
|
|
503
|
-
name: 'Get Message By ID',
|
|
504
|
-
testId: 'testMessageById',
|
|
505
|
-
defaultParams: { messageId: undefined },
|
|
506
|
-
runOrder: 'normal'
|
|
507
|
-
},
|
|
508
|
-
{
|
|
509
|
-
name: 'Open Message',
|
|
510
|
-
testId: 'openMessage',
|
|
511
|
-
defaultParams: { messageId: undefined },
|
|
512
|
-
runOrder: 'normal'
|
|
513
|
-
},
|
|
514
|
-
{
|
|
515
|
-
name: 'Click Message',
|
|
516
|
-
testId: 'clickMessage',
|
|
517
|
-
defaultParams: { messageId: undefined, trackingId: undefined },
|
|
518
|
-
runOrder: 'normal'
|
|
519
|
-
},
|
|
520
|
-
{
|
|
521
|
-
name: 'Read Message',
|
|
522
|
-
testId: 'readMessage',
|
|
523
|
-
defaultParams: { messageId: undefined },
|
|
524
|
-
runOrder: 'normal'
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
name: 'Unread Message',
|
|
528
|
-
testId: 'unreadMessage',
|
|
529
|
-
defaultParams: { messageId: undefined },
|
|
530
|
-
runOrder: 'normal'
|
|
531
|
-
},
|
|
532
|
-
{
|
|
533
|
-
name: 'Archive Message',
|
|
534
|
-
testId: 'archiveMessage',
|
|
535
|
-
defaultParams: { messageId: undefined },
|
|
536
|
-
runOrder: 'normal'
|
|
537
|
-
},
|
|
538
|
-
{
|
|
539
|
-
name: 'Read All Messages',
|
|
540
|
-
testId: 'readAllMessages',
|
|
541
|
-
defaultParams: {},
|
|
542
|
-
runOrder: 'normal'
|
|
543
|
-
},
|
|
544
|
-
]
|
|
545
|
-
},
|
|
546
|
-
{
|
|
547
|
-
title: 'Preferences',
|
|
548
|
-
tests: [
|
|
549
|
-
{
|
|
550
|
-
name: 'Get Preferences',
|
|
551
|
-
testId: 'testGetPreferences',
|
|
552
|
-
defaultParams: { paginationCursor: undefined },
|
|
553
|
-
runOrder: 'normal'
|
|
554
|
-
},
|
|
555
|
-
{
|
|
556
|
-
name: 'Update Preferences',
|
|
557
|
-
testId: 'testUpdatePreferences',
|
|
558
|
-
defaultParams: { topicId: Env.topicId, status: 'OPTED_IN', hasCustomRouting: true, customRouting: 'push,sms,email' },
|
|
559
|
-
runOrder: 'normal'
|
|
560
|
-
},
|
|
561
|
-
{
|
|
562
|
-
name: 'Get Preference Topics',
|
|
563
|
-
testId: 'testGetPreferenceTopics',
|
|
564
|
-
defaultParams: { topicId: Env.topicId },
|
|
565
|
-
runOrder: 'normal'
|
|
566
|
-
},
|
|
567
|
-
]
|
|
568
|
-
},
|
|
569
|
-
{
|
|
570
|
-
title: 'Tracking',
|
|
571
|
-
tests: [
|
|
572
|
-
{
|
|
573
|
-
name: 'Post Tracking Url',
|
|
574
|
-
testId: 'testPostTrackingUrl',
|
|
575
|
-
defaultParams: { trackingUrl: 'https://af6303be-0e1e-40b5-bb80-e1d9299cccff.ct0.app/t/tzgspbr4jcmcy1qkhw96m0034bvy', event: 'delivered' },
|
|
576
|
-
runOrder: 'normal'
|
|
577
|
-
},
|
|
578
|
-
]
|
|
579
|
-
},
|
|
580
|
-
{
|
|
581
|
-
title: 'Shared Authentication',
|
|
582
|
-
tests: [
|
|
583
|
-
{
|
|
584
|
-
name: 'Sign In',
|
|
585
|
-
testId: 'testSignIn',
|
|
586
|
-
defaultParams: { userId: Utils.generateUUID(), accessToken: undefined, clientKey: Env.clientKey, tenantId: undefined, showLogs: true },
|
|
587
|
-
runOrder: 'normal'
|
|
588
|
-
},
|
|
589
|
-
{
|
|
590
|
-
name: 'Get User ID',
|
|
591
|
-
testId: 'testGetUserId',
|
|
592
|
-
defaultParams: {},
|
|
593
|
-
runOrder: 'normal'
|
|
594
|
-
},
|
|
595
|
-
{
|
|
596
|
-
name: 'Get Tenant ID',
|
|
597
|
-
testId: 'testGetTenantId',
|
|
598
|
-
defaultParams: {},
|
|
599
|
-
runOrder: 'normal'
|
|
600
|
-
},
|
|
601
|
-
{
|
|
602
|
-
name: 'Get Is User Signed In',
|
|
603
|
-
testId: 'testGetIsUserSignedIn',
|
|
604
|
-
defaultParams: {},
|
|
605
|
-
runOrder: 'normal'
|
|
606
|
-
},
|
|
607
|
-
{
|
|
608
|
-
name: 'Add Authentication Listener',
|
|
609
|
-
testId: 'testAuthenticationListener',
|
|
610
|
-
defaultParams: {},
|
|
611
|
-
runOrder: 'normal'
|
|
612
|
-
},
|
|
613
|
-
{
|
|
614
|
-
name: 'Remove All Authentication Listeners',
|
|
615
|
-
testId: 'testRemoveAllAuthenticationListeners',
|
|
616
|
-
defaultParams: {},
|
|
617
|
-
runOrder: 'normal'
|
|
618
|
-
},
|
|
619
|
-
{
|
|
620
|
-
name: 'Sign Out',
|
|
621
|
-
testId: 'testSignOut',
|
|
622
|
-
defaultParams: {},
|
|
623
|
-
runOrder: 'skip'
|
|
624
|
-
}
|
|
625
|
-
]
|
|
626
|
-
},
|
|
627
|
-
{
|
|
628
|
-
title: 'Shared Client',
|
|
629
|
-
tests: [
|
|
630
|
-
{
|
|
631
|
-
name: 'Get Client',
|
|
632
|
-
testId: 'testGetClient',
|
|
633
|
-
defaultParams: {},
|
|
634
|
-
runOrder: 'normal'
|
|
635
|
-
}
|
|
636
|
-
]
|
|
637
|
-
},
|
|
638
|
-
{
|
|
639
|
-
title: 'Shared Push',
|
|
640
|
-
tests: [
|
|
641
|
-
{
|
|
642
|
-
name: 'Set Token',
|
|
643
|
-
testId: 'testSetToken',
|
|
644
|
-
defaultParams: { provider: 'expo', token: 'test-token' },
|
|
645
|
-
runOrder: 'normal'
|
|
646
|
-
},
|
|
647
|
-
{
|
|
648
|
-
name: 'Get Token',
|
|
649
|
-
testId: 'testGetToken',
|
|
650
|
-
defaultParams: { provider: 'expo' },
|
|
651
|
-
runOrder: 'normal'
|
|
652
|
-
},
|
|
653
|
-
{
|
|
654
|
-
name: 'Get All Tokens',
|
|
655
|
-
testId: 'testGetAllTokens',
|
|
656
|
-
defaultParams: {},
|
|
657
|
-
runOrder: 'normal'
|
|
658
|
-
},
|
|
659
|
-
{
|
|
660
|
-
name: 'Add Push Notification Listener',
|
|
661
|
-
testId: 'testAddPushNotificationListener',
|
|
662
|
-
defaultParams: {},
|
|
663
|
-
runOrder: 'normal'
|
|
664
|
-
},
|
|
665
|
-
{
|
|
666
|
-
name: 'Remove All Push Notification Listeners',
|
|
667
|
-
testId: 'testRemoveAllPushNotificationListeners',
|
|
668
|
-
defaultParams: {},
|
|
669
|
-
runOrder: 'skip'
|
|
670
|
-
}
|
|
671
|
-
]
|
|
672
|
-
},
|
|
673
|
-
{
|
|
674
|
-
title: 'Shared Inbox',
|
|
675
|
-
tests: [
|
|
676
|
-
{
|
|
677
|
-
name: 'Set Inbox Pagination Limit',
|
|
678
|
-
testId: 'testSetInboxPaginationLimit',
|
|
679
|
-
defaultParams: { limit: 20 },
|
|
680
|
-
runOrder: 'normal'
|
|
681
|
-
},
|
|
682
|
-
{
|
|
683
|
-
name: 'Get Inbox Pagination Limit',
|
|
684
|
-
testId: 'testGetInboxPaginationLimit',
|
|
685
|
-
defaultParams: {},
|
|
686
|
-
runOrder: 'normal'
|
|
687
|
-
},
|
|
688
|
-
{
|
|
689
|
-
name: 'Open Message',
|
|
690
|
-
testId: 'testOpenMessage',
|
|
691
|
-
defaultParams: { messageId: undefined },
|
|
692
|
-
runOrder: 'normal'
|
|
693
|
-
},
|
|
694
|
-
{
|
|
695
|
-
name: 'Click Message',
|
|
696
|
-
testId: 'testClickMessage',
|
|
697
|
-
defaultParams: { messageId: undefined },
|
|
698
|
-
runOrder: 'normal'
|
|
699
|
-
},
|
|
700
|
-
{
|
|
701
|
-
name: 'Read Message',
|
|
702
|
-
testId: 'testReadMessage',
|
|
703
|
-
defaultParams: { messageId: undefined },
|
|
704
|
-
runOrder: 'normal'
|
|
705
|
-
},
|
|
706
|
-
{
|
|
707
|
-
name: 'Unread Message',
|
|
708
|
-
testId: 'testUnreadMessage',
|
|
709
|
-
defaultParams: { messageId: undefined },
|
|
710
|
-
runOrder: 'normal'
|
|
711
|
-
},
|
|
712
|
-
{
|
|
713
|
-
name: 'Archive Message',
|
|
714
|
-
testId: 'testArchiveMessage',
|
|
715
|
-
defaultParams: { messageId: undefined },
|
|
716
|
-
runOrder: 'normal'
|
|
717
|
-
},
|
|
718
|
-
{
|
|
719
|
-
name: 'Read All Inbox Messages',
|
|
720
|
-
testId: 'testReadAllInboxMessages',
|
|
721
|
-
defaultParams: {},
|
|
722
|
-
runOrder: 'normal'
|
|
723
|
-
},
|
|
724
|
-
{
|
|
725
|
-
name: 'Add Inbox Listener',
|
|
726
|
-
testId: 'testAddInboxListener',
|
|
727
|
-
defaultParams: {},
|
|
728
|
-
runOrder: 'normal'
|
|
729
|
-
},
|
|
730
|
-
{
|
|
731
|
-
name: 'Remove All Inbox Listeners',
|
|
732
|
-
testId: 'testRemoveAllInboxListeners',
|
|
733
|
-
defaultParams: {},
|
|
734
|
-
runOrder: 'skip'
|
|
735
|
-
},
|
|
736
|
-
{
|
|
737
|
-
name: 'Refresh Inbox',
|
|
738
|
-
testId: 'testRefreshInbox',
|
|
739
|
-
defaultParams: {},
|
|
740
|
-
runOrder: 'normal'
|
|
741
|
-
},
|
|
742
|
-
{
|
|
743
|
-
name: 'Fetch Next Page of Messages',
|
|
744
|
-
testId: 'testFetchNextPageOfMessages',
|
|
745
|
-
defaultParams: {},
|
|
746
|
-
runOrder: 'normal'
|
|
747
|
-
}
|
|
748
|
-
]
|
|
749
|
-
},
|
|
750
|
-
{
|
|
751
|
-
title: 'System',
|
|
752
|
-
tests: [
|
|
753
|
-
{
|
|
754
|
-
name: 'Request Push Notification Permission',
|
|
755
|
-
testId: 'testRequestPushNotificationPermission',
|
|
756
|
-
defaultParams: {},
|
|
757
|
-
runOrder: 'normal'
|
|
758
|
-
},
|
|
759
|
-
{
|
|
760
|
-
name: 'Get Push Notification Permission Status',
|
|
761
|
-
testId: 'testGetPushNotificationPermissionStatus',
|
|
762
|
-
defaultParams: {},
|
|
763
|
-
runOrder: 'normal'
|
|
764
|
-
},
|
|
765
|
-
{
|
|
766
|
-
name: 'Set iOS Foreground Presentation Options',
|
|
767
|
-
testId: 'testSetIOSForegroundPresentationOptions',
|
|
768
|
-
defaultParams: { options: 'badge,sound,list,banner' },
|
|
769
|
-
runOrder: 'normal'
|
|
770
|
-
},
|
|
771
|
-
{
|
|
772
|
-
name: 'Open Settings for App',
|
|
773
|
-
testId: 'testOpenSettingsForApp',
|
|
774
|
-
defaultParams: {},
|
|
775
|
-
runOrder: 'normal'
|
|
776
|
-
},
|
|
777
|
-
]
|
|
778
|
-
},
|
|
779
|
-
{
|
|
780
|
-
title: 'Send',
|
|
781
|
-
tests: [
|
|
782
|
-
{
|
|
783
|
-
name: 'Send Inbox Message',
|
|
784
|
-
testId: 'testSendInboxMessage',
|
|
785
|
-
defaultParams: {
|
|
786
|
-
userId: await Courier.shared.getUserId() ?? savedClient?.options.userId,
|
|
787
|
-
title: 'Test',
|
|
788
|
-
body: 'Body'
|
|
789
|
-
},
|
|
790
|
-
runOrder: 'normal'
|
|
791
|
-
},
|
|
792
|
-
{
|
|
793
|
-
name: 'Send APN Message',
|
|
794
|
-
testId: 'testSendApnMessage',
|
|
795
|
-
defaultParams: {
|
|
796
|
-
userId: await Courier.shared.getUserId() ?? savedClient?.options.userId,
|
|
797
|
-
title: 'Test',
|
|
798
|
-
body: 'Body'
|
|
799
|
-
},
|
|
800
|
-
runOrder: 'normal'
|
|
801
|
-
},
|
|
802
|
-
{
|
|
803
|
-
name: 'Send FCM Message',
|
|
804
|
-
testId: 'testSendFcmMessage',
|
|
805
|
-
defaultParams: {
|
|
806
|
-
userId: await Courier.shared.getUserId() ?? savedClient?.options.userId,
|
|
807
|
-
title: 'Test',
|
|
808
|
-
body: 'Body'
|
|
809
|
-
},
|
|
810
|
-
runOrder: 'normal'
|
|
811
|
-
}
|
|
812
|
-
]
|
|
813
|
-
}
|
|
814
|
-
];
|
|
815
|
-
const TestItem = ({ item, onPress }) => (React.createElement(TouchableOpacity, { onPress: onPress },
|
|
816
|
-
React.createElement(View, { style: [styles.testItem, item.status === 'running' && styles.runningTestItem] },
|
|
817
|
-
React.createElement(View, { style: styles.testItemContent },
|
|
818
|
-
React.createElement(Text, { style: styles.testItemTitle }, item.name),
|
|
819
|
-
item.status !== undefined && item.status !== 'running' && (React.createElement(Text, { style: styles.testItemResult }, item.result !== undefined ? (typeof item.result === 'number' ?
|
|
820
|
-
item.result.toString() :
|
|
821
|
-
JSON.stringify(item.result, null, 2)) : 'No Response'))),
|
|
822
|
-
React.createElement(View, { style: styles.testItemStatus }, item.status === undefined ? (React.createElement(Text, { style: styles.statusEmoji }, "\uD83E\uDDEA")) : item.status === 'running' ? (React.createElement(ActivityIndicator, { size: "small" })) : item.status === 'skipped' ? (React.createElement(Text, { style: styles.statusEmoji }, "\u26A0\uFE0F")) : (React.createElement(Text, { style: styles.statusEmoji }, item.status === 'success' ? '✅' : '❌'))))));
|
|
823
|
-
const SectionHeader = ({ title }) => (React.createElement(View, { style: styles.sectionHeader },
|
|
824
|
-
React.createElement(Text, { style: styles.sectionHeaderText }, title)));
|
|
825
|
-
const Tests = () => {
|
|
826
|
-
const navigation = useNavigation();
|
|
827
|
-
const [testSections, setTestSections] = useState([]);
|
|
828
|
-
const [testResults, setTestResults] = useState([]);
|
|
829
|
-
const [isRunning, setIsRunning] = useState(false);
|
|
830
|
-
const [currentTestIndex, setCurrentTestIndex] = useState(0);
|
|
831
|
-
const [totalTests, setTotalTests] = useState(0);
|
|
832
|
-
useEffect(() => {
|
|
833
|
-
const loadTests = async () => {
|
|
834
|
-
const sections = await getTestSections();
|
|
835
|
-
setTestSections(sections);
|
|
836
|
-
setTestResults(sections.flatMap(section => section.tests.map(test => ({
|
|
837
|
-
name: test.name,
|
|
838
|
-
runOrder: test.runOrder
|
|
839
|
-
}))));
|
|
840
|
-
setTotalTests(sections.flatMap(section => section.tests).length);
|
|
841
|
-
};
|
|
842
|
-
loadTests();
|
|
843
|
-
}, []);
|
|
844
|
-
useEffect(() => {
|
|
845
|
-
navigation.setOptions({
|
|
846
|
-
headerRight: () => (React.createElement(TouchableOpacity, { onPress: runAllTests, disabled: isRunning, style: { marginRight: 22 } }, isRunning ? (React.createElement(ActivityIndicator, { size: "small" })) : (React.createElement(Text, { style: [styles.runTestsButton, isRunning && styles.disabledButton] }, "Run Tests")))),
|
|
847
|
-
headerTitle: isRunning ? `Running Test ${currentTestIndex + 1}/${totalTests}` : 'Tests',
|
|
848
|
-
});
|
|
849
|
-
}, [isRunning, currentTestIndex]);
|
|
850
|
-
const handleTestError = (error) => {
|
|
851
|
-
let errorMessage = 'An unknown error occurred';
|
|
852
|
-
let errorDetails = {};
|
|
853
|
-
if (error instanceof Error) {
|
|
854
|
-
errorMessage = error.message;
|
|
855
|
-
errorDetails = {
|
|
856
|
-
name: error.name,
|
|
857
|
-
};
|
|
858
|
-
}
|
|
859
|
-
else if (typeof error === 'object' && error !== null) {
|
|
860
|
-
errorMessage = String(error);
|
|
861
|
-
errorDetails = { ...error };
|
|
862
|
-
}
|
|
863
|
-
else if (typeof error === 'string') {
|
|
864
|
-
errorMessage = error;
|
|
865
|
-
}
|
|
866
|
-
return { errorMessage, errorDetails };
|
|
867
|
-
};
|
|
868
|
-
const runAllTests = async () => {
|
|
869
|
-
if (isRunning)
|
|
870
|
-
return;
|
|
871
|
-
setTestResults(prev => prev.map(item => ({
|
|
872
|
-
...item,
|
|
873
|
-
status: undefined,
|
|
874
|
-
result: undefined
|
|
875
|
-
})));
|
|
876
|
-
setIsRunning(true);
|
|
877
|
-
setCurrentTestIndex(0);
|
|
878
|
-
const normalTests = testSections.flatMap(section => section.tests.filter(test => test.runOrder === 'normal'));
|
|
879
|
-
const endTests = testSections.flatMap(section => section.tests.filter(test => test.runOrder === 'run at end'));
|
|
880
|
-
const skipTests = testSections.flatMap(section => section.tests.filter(test => test.runOrder === 'skip'));
|
|
881
|
-
for (let i = 0; i < normalTests.length; i++) {
|
|
882
|
-
setCurrentTestIndex(i);
|
|
883
|
-
await runSingleTest(normalTests[i]);
|
|
884
|
-
}
|
|
885
|
-
for (let i = 0; i < endTests.length; i++) {
|
|
886
|
-
setCurrentTestIndex(normalTests.length + i);
|
|
887
|
-
await runSingleTest(endTests[i]);
|
|
888
|
-
}
|
|
889
|
-
for (const test of skipTests) {
|
|
890
|
-
setTestResults(prev => prev.map(t => t.name === test.name ? { ...t, status: 'skipped' } : t));
|
|
891
|
-
}
|
|
892
|
-
setIsRunning(false);
|
|
893
|
-
setCurrentTestIndex(0);
|
|
894
|
-
};
|
|
895
|
-
const runSingleTest = async (test) => {
|
|
896
|
-
setTestResults(prev => prev.map(t => t.name === test.name ? { ...t, status: 'running', result: undefined } : t));
|
|
897
|
-
setModalVisible(false); // Close the modal when the test starts
|
|
898
|
-
try {
|
|
899
|
-
const testFunction = IntegrationTests[test.testId];
|
|
900
|
-
if (typeof testFunction === 'function') {
|
|
901
|
-
const result = await testFunction(test.defaultParams);
|
|
902
|
-
setTestResults(prev => prev.map(t => t.name === test.name ? { ...t, result, status: 'success' } : t));
|
|
903
|
-
}
|
|
904
|
-
else {
|
|
905
|
-
throw new Error(`Test function '${test.testId}' not found`);
|
|
906
|
-
}
|
|
907
|
-
}
|
|
908
|
-
catch (error) {
|
|
909
|
-
const { errorMessage, errorDetails } = handleTestError(error);
|
|
910
|
-
console.log('Test failed:', {
|
|
911
|
-
testName: test.name,
|
|
912
|
-
errorMessage,
|
|
913
|
-
errorDetails,
|
|
914
|
-
});
|
|
915
|
-
setTestResults(prev => prev.map(t => t.name === test.name
|
|
916
|
-
? {
|
|
917
|
-
...t,
|
|
918
|
-
result: {
|
|
919
|
-
errorMessage,
|
|
920
|
-
errorDetails,
|
|
921
|
-
},
|
|
922
|
-
status: 'failure'
|
|
923
|
-
}
|
|
924
|
-
: t));
|
|
925
|
-
}
|
|
926
|
-
};
|
|
927
|
-
const [modalVisible, setModalVisible] = useState(false);
|
|
928
|
-
const [selectedTest, setSelectedTest] = useState(null);
|
|
929
|
-
const [testParams, setTestParams] = useState({});
|
|
930
|
-
const onTestItemPress = (item) => {
|
|
931
|
-
if (isRunning)
|
|
932
|
-
return;
|
|
933
|
-
setSelectedTest(item);
|
|
934
|
-
setTestParams({ ...item.defaultParams });
|
|
935
|
-
setModalVisible(true);
|
|
936
|
-
};
|
|
937
|
-
const handleParamChange = (key, value) => {
|
|
938
|
-
setTestParams(prev => ({ ...prev, [key]: value }));
|
|
939
|
-
};
|
|
940
|
-
const handleRunTest = async () => {
|
|
941
|
-
if (selectedTest) {
|
|
942
|
-
const testToRun = { ...selectedTest, defaultParams: testParams };
|
|
943
|
-
await runSingleTest(testToRun);
|
|
944
|
-
}
|
|
945
|
-
setModalVisible(false);
|
|
946
|
-
};
|
|
947
|
-
const handleModalClose = () => {
|
|
948
|
-
setModalVisible(false);
|
|
949
|
-
setSelectedTest(null);
|
|
950
|
-
setTestParams({});
|
|
951
|
-
};
|
|
952
|
-
return (React.createElement(View, { style: styles.container },
|
|
953
|
-
React.createElement(FlatList, { data: testSections, renderItem: ({ item: section }) => (React.createElement(React.Fragment, null,
|
|
954
|
-
React.createElement(SectionHeader, { title: section.title }),
|
|
955
|
-
section.tests.map((test) => (React.createElement(TestItem, { key: test.name, item: testResults.find(r => r.name === test.name) || { name: test.name, runOrder: test.runOrder }, onPress: () => onTestItemPress(test) }))))), keyExtractor: (item) => item.title }),
|
|
956
|
-
React.createElement(Modal, { visible: modalVisible, animationType: "slide", transparent: true },
|
|
957
|
-
React.createElement(TouchableWithoutFeedback, { onPress: Keyboard.dismiss },
|
|
958
|
-
React.createElement(View, { style: styles.modalContainer },
|
|
959
|
-
React.createElement(View, { style: styles.modalContent },
|
|
960
|
-
React.createElement(Text, null,
|
|
961
|
-
"Run Test: ",
|
|
962
|
-
selectedTest?.name),
|
|
963
|
-
Object.entries(testParams).map(([key, value]) => (React.createElement(View, { key: key, style: styles.inputContainer },
|
|
964
|
-
React.createElement(Text, { style: styles.inputLabel },
|
|
965
|
-
key,
|
|
966
|
-
":"),
|
|
967
|
-
typeof value === 'boolean' ? (React.createElement(Switch, { value: value, onValueChange: (newValue) => handleParamChange(key, newValue) })) : typeof value === 'number' ? (React.createElement(TextInput, { style: styles.input, value: value !== undefined ? String(value) : '', onChangeText: (text) => {
|
|
968
|
-
const numValue = Number(text);
|
|
969
|
-
handleParamChange(key, isNaN(numValue) ? undefined : numValue);
|
|
970
|
-
}, keyboardType: "numeric", autoCapitalize: "none", autoCorrect: false })) : (React.createElement(TextInput, { style: styles.input, value: value !== undefined ? String(value) : '', onChangeText: (text) => handleParamChange(key, text || undefined), autoCapitalize: "none", autoCorrect: false }))))),
|
|
971
|
-
React.createElement(Button, { title: "Run", onPress: handleRunTest }),
|
|
972
|
-
React.createElement(Button, { title: "Cancel", onPress: handleModalClose })))))));
|
|
973
|
-
};
|
|
974
|
-
const styles = StyleSheet.create({
|
|
975
|
-
container: {
|
|
976
|
-
flex: 1,
|
|
977
|
-
},
|
|
978
|
-
testItem: {
|
|
979
|
-
flexDirection: 'row',
|
|
980
|
-
justifyContent: 'space-between',
|
|
981
|
-
alignItems: 'flex-start',
|
|
982
|
-
padding: 20,
|
|
983
|
-
borderBottomWidth: 1,
|
|
984
|
-
borderBottomColor: '#ccc',
|
|
985
|
-
},
|
|
986
|
-
runningTestItem: {
|
|
987
|
-
backgroundColor: '#e6f3ff',
|
|
988
|
-
},
|
|
989
|
-
testItemContent: {
|
|
990
|
-
flex: 1,
|
|
991
|
-
marginRight: 10,
|
|
992
|
-
},
|
|
993
|
-
testItemTitle: {
|
|
994
|
-
fontFamily: Platform.select({
|
|
995
|
-
ios: 'Courier',
|
|
996
|
-
android: 'monospace',
|
|
997
|
-
default: 'monospace',
|
|
998
|
-
}),
|
|
999
|
-
fontSize: 16,
|
|
1000
|
-
fontWeight: 'bold',
|
|
1001
|
-
marginBottom: 8,
|
|
1002
|
-
},
|
|
1003
|
-
testItemStatus: {
|
|
1004
|
-
width: 24,
|
|
1005
|
-
alignItems: 'center',
|
|
1006
|
-
justifyContent: 'center',
|
|
1007
|
-
},
|
|
1008
|
-
testItemResult: {
|
|
1009
|
-
fontFamily: Platform.select({
|
|
1010
|
-
ios: 'Courier',
|
|
1011
|
-
android: 'monospace',
|
|
1012
|
-
default: 'monospace',
|
|
1013
|
-
}),
|
|
1014
|
-
fontSize: 14,
|
|
1015
|
-
},
|
|
1016
|
-
statusEmoji: {
|
|
1017
|
-
fontSize: 16,
|
|
1018
|
-
lineHeight: 24,
|
|
1019
|
-
},
|
|
1020
|
-
runTestsButton: {
|
|
1021
|
-
fontSize: 16,
|
|
1022
|
-
},
|
|
1023
|
-
disabledButton: {
|
|
1024
|
-
opacity: 0.5,
|
|
1025
|
-
},
|
|
1026
|
-
sectionHeader: {
|
|
1027
|
-
backgroundColor: '#f0f0f0',
|
|
1028
|
-
padding: 20,
|
|
1029
|
-
},
|
|
1030
|
-
sectionHeaderText: {
|
|
1031
|
-
fontFamily: Platform.select({
|
|
1032
|
-
ios: 'Courier',
|
|
1033
|
-
android: 'monospace',
|
|
1034
|
-
default: 'monospace',
|
|
1035
|
-
}),
|
|
1036
|
-
fontWeight: 'bold',
|
|
1037
|
-
fontSize: 24,
|
|
1038
|
-
paddingTop: 20,
|
|
1039
|
-
},
|
|
1040
|
-
modalContainer: {
|
|
1041
|
-
flex: 1,
|
|
1042
|
-
justifyContent: 'center',
|
|
1043
|
-
alignItems: 'center',
|
|
1044
|
-
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
1045
|
-
},
|
|
1046
|
-
modalContent: {
|
|
1047
|
-
backgroundColor: 'white',
|
|
1048
|
-
padding: 20,
|
|
1049
|
-
borderRadius: 10,
|
|
1050
|
-
width: '80%',
|
|
1051
|
-
},
|
|
1052
|
-
inputContainer: {
|
|
1053
|
-
flexDirection: 'row',
|
|
1054
|
-
alignItems: 'center',
|
|
1055
|
-
marginBottom: 10,
|
|
1056
|
-
},
|
|
1057
|
-
inputLabel: {
|
|
1058
|
-
width: 100,
|
|
1059
|
-
marginRight: 10,
|
|
1060
|
-
},
|
|
1061
|
-
input: {
|
|
1062
|
-
flex: 1,
|
|
1063
|
-
borderWidth: 1,
|
|
1064
|
-
borderColor: '#ccc',
|
|
1065
|
-
padding: 5,
|
|
1066
|
-
},
|
|
1067
|
-
});
|
|
1068
|
-
export default Tests;
|