-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathPushMessageParser.test.ts
More file actions
87 lines (79 loc) · 2.17 KB
/
Copy pathPushMessageParser.test.ts
File metadata and controls
87 lines (79 loc) · 2.17 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
import { describe, expect, it } from '@jest/globals'
import type { FirebaseMessagingTypes } from '@react-native-firebase/messaging'
import { parsePushMessage } from '../util/PushMessageParser'
// The parser only uses `showDevError` from AirshipInstance; stub it so the test
// avoids pulling in the native Airship module.
jest.mock('../components/services/AirshipInstance', () => ({
showDevError: () => undefined
}))
/**
* Builds a minimal RemoteMessage; the parser only reads `data` and
* `notification`.
*/
function makeMessage(
data: Record<string, string> | undefined,
notification?: { title?: string; body?: string }
): FirebaseMessagingTypes.RemoteMessage {
return {
data,
notification
} as unknown as FirebaseMessagingTypes.RemoteMessage
}
describe('parsePushMessage', () => {
it('captures the campaignId from a marketing payload', () => {
expect(
parsePushMessage(makeMessage({ type: 'marketing', campaignId: 'abc123' }))
).toEqual({
type: 'marketing',
campaignId: 'abc123',
link: undefined
})
})
it('parses an optional deep-link url into a nested navigation link', () => {
expect(
parsePushMessage(
makeMessage({
type: 'marketing',
campaignId: 'abc123',
url: 'edge://swap'
})
)
).toEqual({
type: 'marketing',
campaignId: 'abc123',
link: { type: 'swap' }
})
})
it('degrades to track-only when the url is unparseable', () => {
expect(
parsePushMessage(
makeMessage({
type: 'marketing',
campaignId: 'abc123',
url: 'not a url'
})
)
).toEqual({
type: 'marketing',
campaignId: 'abc123',
link: undefined
})
})
it('ignores a non-marketing payload', () => {
expect(parsePushMessage(makeMessage({ foo: 'bar' }))).toBeUndefined()
})
it('still parses a price-change payload', () => {
expect(
parsePushMessage(
makeMessage(
{ type: 'price-change', pluginId: 'bitcoin' },
{ body: 'BTC is up' }
)
)
).toEqual({
type: 'price-change',
pluginId: 'bitcoin',
body: 'BTC is up'
})
})
})