-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(deeplinks): get url from the correct field for CT events (#6356)
### Description Per this [update](https://github.com/CleverTap/clevertap-react-native/blob/2c2ab9664b9e83cde936d14b511896d7edd5ecdc/docs/callbackPayloadFormat.md?plain=1#L12) in clever tap docs, this likely slipped through on a clevertap package upgrade ### Test plan Can't easily test CT push notifications with a dev build, but this has been working on Android, where the url was extracted correctly, and also confirmed with logging on iOS that the deeplink field is present at the top level of the event. Also tested the 2 callbacks being called scenario by updating the code to call handleOpenUrl twice (one with isSecureOrigin: false and the other with true) in the Linking event listener, the 2nd call mimics the call that would've been done by the CT push notification listener callback, and also introducing a delay in the saga (to mimic slow sagas, which can be killed by `takeLatest` if another event of the same action type is fired). On opening a deeplink on the browser with an openScreen deeplink and the app backgrounded, confirmed that the navigation to the correct screen happens. ### Related issues - Fixes ACT-1469 ### Backwards compatibility Yes ### Network scalability N/A
- Loading branch information
1 parent
9350ff8
commit f52bc0f
Showing
5 changed files
with
103 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,13 @@ | ||
const getInitialLink = jest.fn() | ||
const buildShortLink = jest.fn() | ||
const buildLink = jest.fn() | ||
const onLink = jest.fn() | ||
|
||
export default function links() { | ||
return { | ||
getInitialLink, | ||
buildShortLink, | ||
buildLink, | ||
onLink, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { act, renderHook } from '@testing-library/react-native' | ||
import CleverTap from 'clevertap-react-native' | ||
import React from 'react' | ||
import { Linking } from 'react-native' | ||
import { Provider } from 'react-redux' | ||
import { useDeepLinks } from 'src/app/useDeepLinks' | ||
import { createMockStore } from 'test/utils' | ||
|
||
describe('useDeepLinks', () => { | ||
let cleverTapListenerCallback: Function | ||
let linkingListenerCallback: Function | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
jest.mocked(CleverTap.addListener).mockImplementation((event, callback) => { | ||
if (event === 'CleverTapPushNotificationClicked') { | ||
cleverTapListenerCallback = callback | ||
} | ||
}) | ||
jest.mocked(Linking.addEventListener).mockImplementation((event, callback) => { | ||
if (event === 'url') { | ||
linkingListenerCallback = callback | ||
} | ||
return { | ||
remove: jest.fn(), | ||
} as any | ||
}) | ||
}) | ||
|
||
it('should handle clevertap push notifications with deep links', async () => { | ||
const store = createMockStore() | ||
renderHook(() => useDeepLinks(), { | ||
wrapper: (component) => ( | ||
<Provider store={store}>{component?.children ? component.children : component}</Provider> | ||
), | ||
}) | ||
|
||
await act(() => { | ||
cleverTapListenerCallback({ wzrk_dl: 'some-link' }) | ||
}) | ||
|
||
expect(store.getActions()).toEqual([ | ||
{ | ||
deepLink: 'some-link', | ||
isSecureOrigin: true, | ||
type: 'APP/OPEN_DEEP_LINK', | ||
}, | ||
]) | ||
}) | ||
|
||
it('should not open deeplink if clevertap event does not have a deep link', async () => { | ||
const store = createMockStore() | ||
renderHook(() => useDeepLinks(), { | ||
wrapper: (component) => ( | ||
<Provider store={store}>{component?.children ? component.children : component}</Provider> | ||
), | ||
}) | ||
|
||
await act(() => { | ||
cleverTapListenerCallback({}) | ||
}) | ||
|
||
expect(store.getActions()).toEqual([]) | ||
}) | ||
|
||
it('should handle linking events with deep links', async () => { | ||
const store = createMockStore() | ||
renderHook(() => useDeepLinks(), { | ||
wrapper: (component) => ( | ||
<Provider store={store}>{component?.children ? component.children : component}</Provider> | ||
), | ||
}) | ||
|
||
await act(() => { | ||
linkingListenerCallback({ url: 'some-link' }) | ||
}) | ||
|
||
expect(store.getActions()).toEqual([ | ||
{ | ||
deepLink: 'some-link', | ||
isSecureOrigin: false, | ||
type: 'APP/OPEN_DEEP_LINK', | ||
}, | ||
]) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters