This repository has been archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.spec.test.js
75 lines (58 loc) · 2.13 KB
/
index.spec.test.js
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
jest.mock('react-native', () => ({
NativeModules: {
RNResponsysBridge: {
registerUserId: jest.fn(),
trackEvent: jest.fn(),
setDeviceToken: jest.fn(),
registerApp: jest.fn(),
getDeviceId: jest.fn(),
getUserId: jest.fn(),
},
},
}))
import { NativeModules } from 'react-native'
import ResponsysBridge from './index'
const { RNResponsysBridge } = NativeModules
beforeEach(() => {
for (const property in NativeModules.RNResponsysBridge) {
NativeModules.RNResponsysBridge[property].mockClear()
}
})
test('Should register user ID', () => {
const userId = 'some-user-id'
ResponsysBridge.registerUserId(userId)
expect(RNResponsysBridge.registerUserId).toHaveBeenCalledWith(userId)
})
test('Should trackt event', () => {
const trackEvent = 'some-track-event'
ResponsysBridge.trackEvent(trackEvent)
expect(RNResponsysBridge.trackEvent).toHaveBeenCalledWith(trackEvent)
})
test('Should configure device token', () => {
const deviceToken = 'some-device-token'
ResponsysBridge.configureDeviceToken(deviceToken)
expect(RNResponsysBridge.setDeviceToken).toHaveBeenCalledWith(deviceToken)
})
test('Should register app with default location', () => {
ResponsysBridge.registerApp()
expect(RNResponsysBridge.registerApp).toHaveBeenCalledWith(false)
})
test('Should register app using device location', () => {
const useLocation = true
ResponsysBridge.registerApp(useLocation)
expect(RNResponsysBridge.registerApp).toHaveBeenCalledWith(useLocation)
})
test('Should retrieve device ID', () => {
const fakeDeviceId = 'fake-device-id'
NativeModules.RNResponsysBridge.getDeviceId.mockReturnValue(fakeDeviceId)
const retrievedDeviceId = ResponsysBridge.retrieveDeviceId()
expect(RNResponsysBridge.getDeviceId).toHaveBeenCalled()
expect(retrievedDeviceId).toEqual(fakeDeviceId)
})
test('Should retrieve user ID', () => {
const fakeUserId = 'fake-user-id'
NativeModules.RNResponsysBridge.getUserId.mockReturnValue(fakeUserId)
const retrieveUserId = ResponsysBridge.retrieveUserId()
expect(RNResponsysBridge.getUserId).toHaveBeenCalled()
expect(retrieveUserId).toEqual(fakeUserId)
})