-
Notifications
You must be signed in to change notification settings - Fork 43
Expand file tree
/
Copy pathMockRNIterableAPI.ts
More file actions
144 lines (108 loc) · 3.92 KB
/
Copy pathMockRNIterableAPI.ts
File metadata and controls
144 lines (108 loc) · 3.92 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
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 async getInboxMessages(): Promise<IterableInAppMessage[] | undefined> {
return await new Promise((resolve) => {
// Filter messages that are marked for inbox
const inboxMessages = MockRNIterableAPI.messages?.filter(msg => msg.saveToInbox) || [];
resolve(inboxMessages);
});
}
static async getHtmlInAppContentForMessage(messageId: string): Promise<unknown> {
return await new Promise((resolve) => {
// Mock HTML content for testing
const mockHtmlContent = {
edgeInsets: { top: 10, left: 20, bottom: 30, right: 40 },
html: `<div>Mock HTML content for message ${messageId}</div>`,
};
resolve(mockHtmlContent);
});
}
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();
static startSession = jest.fn();
static endSession = jest.fn();
static updateVisibleRows = 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;
}
}