-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathMockRNIterableAPI.ts
More file actions
156 lines (116 loc) · 3.89 KB
/
Copy pathMockRNIterableAPI.ts
File metadata and controls
156 lines (116 loc) · 3.89 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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
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 = jest.fn((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 = jest.fn((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 = jest.fn(
(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 pauseAuthRetries = jest.fn();
static generateJwtToken = jest.fn(
async (_opts: {
secret: string;
duration: number;
userId?: string;
email?: string;
}): Promise<string> => {
return await new Promise((resolve) => {
resolve('mock-jwt-token');
});
}
);
static async getInAppMessages(): Promise<IterableInAppMessage[] | undefined> {
return await new Promise((resolve) => {
resolve(MockRNIterableAPI.messages);
});
}
static setAutoDisplayPaused = jest.fn();
static showMessage = jest.fn(
async (
_messageId: string,
_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();
static getInboxMessages = jest.fn(
async (): Promise<IterableInAppMessage[] | undefined> => {
return await new Promise((resolve) => {
resolve(MockRNIterableAPI.messages);
});
}
);
static startSession = jest.fn();
static endSession = jest.fn();
static updateVisibleRows = jest.fn();
static getHtmlInAppContentForMessage = 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;
}
}