-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathMockRNIterableAPI.ts
More file actions
121 lines (88 loc) · 3.13 KB
/
MockRNIterableAPI.ts
File metadata and controls
121 lines (88 loc) · 3.13 KB
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
import { IterableAttributionInfo } from '../core';
import { IterableInAppMessage } from '../inApp';
export class MockRNIterableAPI {
static email?: string;
static userId?: string;
static token?: string;
static lastPushPayload?: unknown;
static attributionInfo?: IterableAttributionInfo;
static messages?: IterableInAppMessage[];
static clickedUrl?: string;
static async getEmail(): Promise<string | undefined> {
return await new Promise((resolve) => {
resolve(MockRNIterableAPI.email);
});
}
static setEmail(email: string, authToken?: string): void {
MockRNIterableAPI.email = email;
MockRNIterableAPI.token = authToken;
}
static async getUserId(): Promise<string | undefined> {
return await new Promise((resolve) => {
resolve(MockRNIterableAPI.userId);
});
}
static setUserId(userId: string, authToken?: string): void {
MockRNIterableAPI.userId = userId;
MockRNIterableAPI.token = authToken;
}
static disableDeviceForCurrentUser = jest.fn();
static trackPushOpenWithCampaignId = jest.fn();
static updateCart = jest.fn();
static trackPurchase = jest.fn();
static trackInAppOpen = jest.fn();
static trackInAppClick = jest.fn();
static trackInAppClose = jest.fn();
static trackEvent = jest.fn();
static async getLastPushPayload(): Promise<unknown | undefined> {
return await new Promise((resolve) => {
resolve(MockRNIterableAPI.lastPushPayload);
});
}
static async getAttributionInfo(): Promise<
IterableAttributionInfo | undefined
> {
return await new Promise((resolve) => {
resolve(MockRNIterableAPI.attributionInfo);
});
}
static setAttributionInfo(attributionInfo?: IterableAttributionInfo): void {
MockRNIterableAPI.attributionInfo = attributionInfo;
}
static initializeWithApiKey = jest.fn().mockResolvedValue(true);
static initialize2WithApiKey = jest.fn().mockResolvedValue(true);
static wakeApp = jest.fn();
static setInAppShowResponse = jest.fn();
static passAlongAuthToken = jest.fn();
static async getInAppMessages(): Promise<IterableInAppMessage[] | undefined> {
return await new Promise((resolve) => {
resolve(MockRNIterableAPI.messages);
});
}
static setAutoDisplayPaused = jest.fn();
static async showMessage(
_message: IterableInAppMessage,
_consume: boolean
): Promise<string | undefined> {
return await new Promise((resolve) => {
resolve(MockRNIterableAPI.clickedUrl);
});
}
static removeMessage = jest.fn();
static setReadForMessage = jest.fn();
static inAppConsume = jest.fn();
static updateUser = jest.fn();
static updateEmail = jest.fn();
static handleAppLink = jest.fn();
static updateSubscriptions = jest.fn();
// set messages function is to set the messages static property
// this is for testing purposes only
static setMessages(messages: IterableInAppMessage[]): void {
MockRNIterableAPI.messages = messages;
}
// setClickedUrl function is to set the messages static property
// this is for testing purposes only
static setClickedUrl(clickedUrl: string): void {
MockRNIterableAPI.clickedUrl = clickedUrl;
}
}