-
Notifications
You must be signed in to change notification settings - Fork 1.5k
fix: resolve deep links by room id for channels and groups #7111
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
32 commits
Select commit
Hold shift + click to select a range
b0c8994
use getRoomByTypeAndName to get more info
Rohit3523 76c5ec9
Merge branch 'develop' into private-channel-deeplink-fail
Rohit3523 32ea305
improve
Rohit3523 1af2c27
chore: format code and fix lint issues
Rohit3523 252c6b2
Added E2E test
Rohit3523 2f3c851
Merge branch 'private-channel-deeplink-fail' of https://github.com/Ro…
Rohit3523 4607327
chore: format code and fix lint issues
Rohit3523 180d1b8
Move group link to assorted
Rohit3523 97fc070
Merge branch 'private-channel-deeplink-fail' of https://github.com/Ro…
Rohit3523 9d42eca
update
Rohit3523 9e73065
Merge branch 'develop' into private-channel-deeplink-fail
Rohit3523 e2caede
Merge branch 'develop' into private-channel-deeplink-fail
Rohit3523 ceb8a17
Added typing for groups.open
Rohit3523 6fa65c4
remove ts-ignore
Rohit3523 b62c0dc
added test
Rohit3523 8e8e55f
chore: format code and fix lint issues
Rohit3523 198b39c
Merge branch 'develop' into private-channel-deeplink-fail
Rohit3523 f059b8f
using getinfo for channel too
Rohit3523 2d1a8f0
Merge branch 'develop' into private-channel-deeplink-fail
Rohit3523 01c8598
test update
Rohit3523 f27c93c
rerun ci
Rohit3523 3ef413e
revert
Rohit3523 a992162
Merge branch 'develop' into private-channel-deeplink-fail
OtavioStasiak 86e45ac
Merge branch 'develop' into private-channel-deeplink-fail
OtavioStasiak 1a2b919
Merge branch 'develop' into private-channel-deeplink-fail
Rohit3523 7140ddb
added deeplink test in sniffler
Rohit3523 5da8ebf
create channel and group using test account
Rohit3523 af98bc4
test fix
Rohit3523 387ec21
Merge branch 'develop' into private-channel-deeplink-fail
Rohit3523 bcfc461
chore: format code and fix lint issues
Rohit3523 84ac63a
improve code
Rohit3523 1441239
Merge branch 'develop' into private-channel-deeplink-fail
Rohit3523 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,63 @@ | ||
| appId: ${APP_ID} | ||
| name: Channel Deeplink | ||
| onFlowStart: | ||
| - runFlow: '../../helpers/setup.yaml' | ||
| onFlowComplete: | ||
| - evalScript: ${output.utils.deleteCreatedUsers()} | ||
| tags: | ||
| - test-12 | ||
|
|
||
| --- | ||
| - evalScript: ${output.user = output.utils.createUser()} | ||
| - evalScript: ${output.group = output.utils.createRandomRoom(output.user.username, output.user.password, 'p')} | ||
| - evalScript: ${output.channel = output.utils.createRandomRoom(output.user.username, output.user.password, 'c')} | ||
|
|
||
| - runFlow: | ||
| file: '../../helpers/login-with-deeplink.yaml' | ||
| env: | ||
| USERNAME: ${output.user.username} | ||
| PASSWORD: ${output.user.password} | ||
|
|
||
| # open group using name | ||
| - killApp | ||
| - runFlow: | ||
| file: '../../helpers/open-deeplink.yaml' | ||
| env: | ||
| link: ${output.utils.getDeepLink('room', output.data.server, 'path=group/', output.group.name)} | ||
| - extendedWaitUntil: | ||
| visible: | ||
| id: 'room-view-title-${output.group.name}' | ||
| timeout: 60000 | ||
|
|
||
| # open group using id | ||
| - killApp | ||
| - runFlow: | ||
| file: '../../helpers/open-deeplink.yaml' | ||
| env: | ||
| link: ${output.utils.getDeepLink('room', output.data.server, 'path=group/', output.group._id)} | ||
| - extendedWaitUntil: | ||
| visible: | ||
| id: 'room-view-title-${output.group.name}' | ||
| timeout: 60000 | ||
|
|
||
| # open channel using name | ||
| - killApp | ||
| - runFlow: | ||
| file: '../../helpers/open-deeplink.yaml' | ||
| env: | ||
| link: ${output.utils.getDeepLink('room', output.data.server, 'path=channel/', output.channel.name)} | ||
| - extendedWaitUntil: | ||
| visible: | ||
| id: 'room-view-title-${output.channel.name}' | ||
| timeout: 60000 | ||
|
|
||
| # open channel using id | ||
| - killApp | ||
| - runFlow: | ||
| file: '../../helpers/open-deeplink.yaml' | ||
| env: | ||
| link: ${output.utils.getDeepLink('room', output.data.server, 'path=channel/', output.channel._id)} | ||
| - extendedWaitUntil: | ||
| visible: | ||
| id: 'room-view-title-${output.channel.name}' | ||
| timeout: 60000 | ||
This file contains hidden or 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 hidden or 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 hidden or 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,152 @@ | ||
| import { canOpenRoom } from './canOpenRoom'; | ||
| import sdk from '../services/sdk'; | ||
| import { getRoomByTypeAndName } from '../services/restApi'; | ||
|
|
||
| jest.mock('../services/sdk', () => ({ | ||
| __esModule: true, | ||
| default: { | ||
| post: jest.fn() | ||
| } | ||
| })); | ||
|
|
||
| jest.mock('../services/restApi', () => ({ | ||
| getRoomByTypeAndName: jest.fn() | ||
| })); | ||
|
|
||
| const mockedSdkPost = sdk.post as jest.Mock; | ||
| const mockedGetRoomByTypeAndName = getRoomByTypeAndName as jest.Mock; | ||
|
|
||
| beforeEach(() => { | ||
| jest.clearAllMocks(); | ||
| }); | ||
|
|
||
| describe('canOpenRoom — GROUP deeplink', () => { | ||
| const roomFixture = { _id: 'group-id-1', name: 'test-group', t: 'p' }; | ||
|
|
||
| it('returns room when getRoomByTypeAndName succeeds and groups.open succeeds', async () => { | ||
| mockedGetRoomByTypeAndName.mockResolvedValue(roomFixture); | ||
| mockedSdkPost.mockResolvedValue({ success: true }); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'group/test-group' }); | ||
|
|
||
| expect(mockedGetRoomByTypeAndName).toHaveBeenCalledWith('p', 'test-group'); | ||
| expect(mockedSdkPost).toHaveBeenCalledWith('groups.open', { roomId: 'group-id-1' }); | ||
| expect(result).toEqual({ ...roomFixture, rid: 'group-id-1' }); | ||
| }); | ||
|
|
||
| it('returns room when the path holds a room id instead of a room name', async () => { | ||
| mockedGetRoomByTypeAndName.mockResolvedValue(roomFixture); | ||
| mockedSdkPost.mockResolvedValue({ success: true }); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'group/6997e23f362b278aeb3d369b' }); | ||
|
|
||
| expect(mockedGetRoomByTypeAndName).toHaveBeenCalledWith('p', '6997e23f362b278aeb3d369b'); | ||
| expect(mockedSdkPost).toHaveBeenCalledWith('groups.open', { roomId: 'group-id-1' }); | ||
| expect(result).toEqual({ ...roomFixture, rid: 'group-id-1' }); | ||
| }); | ||
|
|
||
| it('returns room when groups.open reports the group is already open', async () => { | ||
| mockedGetRoomByTypeAndName.mockResolvedValue(roomFixture); | ||
| mockedSdkPost.mockRejectedValue({ data: { error: 'The private group, test-group, is already open for the sender' } }); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'group/test-group' }); | ||
|
|
||
| expect(result).toEqual({ ...roomFixture, rid: 'group-id-1' }); | ||
| }); | ||
|
|
||
| it('opens the group by rid without resolving the path segment', async () => { | ||
| mockedSdkPost.mockResolvedValue({ success: true }); | ||
|
|
||
| const result = await canOpenRoom({ rid: 'group-id-1', path: 'group/test-group' }); | ||
|
|
||
| expect(mockedGetRoomByTypeAndName).not.toHaveBeenCalled(); | ||
| expect(mockedSdkPost).toHaveBeenCalledWith('groups.open', { roomId: 'group-id-1' }); | ||
| expect(result).toEqual({ rid: 'group-id-1' }); | ||
| }); | ||
|
|
||
| it('returns false when getRoomByTypeAndName returns null', async () => { | ||
| mockedGetRoomByTypeAndName.mockResolvedValue(null); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'group/test-group' }); | ||
|
|
||
| expect(mockedSdkPost).not.toHaveBeenCalled(); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when getRoomByTypeAndName returns object without _id', async () => { | ||
| mockedGetRoomByTypeAndName.mockResolvedValue({}); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'group/test-group' }); | ||
|
|
||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when getRoomByTypeAndName throws', async () => { | ||
| mockedGetRoomByTypeAndName.mockRejectedValue(new Error('not found')); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'group/test-group' }); | ||
|
|
||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when groups.open throws a non-already-open error', async () => { | ||
| mockedGetRoomByTypeAndName.mockResolvedValue(roomFixture); | ||
| mockedSdkPost.mockRejectedValue({ data: { error: 'forbidden' } }); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'group/test-group' }); | ||
|
|
||
| expect(result).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('canOpenRoom — CHANNEL deeplink', () => { | ||
| const roomFixture = { _id: 'channel-id-1', name: 'test-channel', t: 'c' }; | ||
|
|
||
| it('returns room when the path holds a room name', async () => { | ||
| mockedGetRoomByTypeAndName.mockResolvedValue(roomFixture); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'channel/test-channel' }); | ||
|
|
||
| expect(mockedGetRoomByTypeAndName).toHaveBeenCalledWith('c', 'test-channel'); | ||
| expect(mockedSdkPost).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({ ...roomFixture, rid: 'channel-id-1' }); | ||
| }); | ||
|
|
||
| it('returns room when the path holds a room id instead of a room name', async () => { | ||
| mockedGetRoomByTypeAndName.mockResolvedValue(roomFixture); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'channel/6997e23f362b278aeb3d369b' }); | ||
|
|
||
| expect(mockedGetRoomByTypeAndName).toHaveBeenCalledWith('c', '6997e23f362b278aeb3d369b'); | ||
| expect(result).toEqual({ ...roomFixture, rid: 'channel-id-1' }); | ||
| }); | ||
|
|
||
| it('returns the rid without resolving the path segment when rid is provided', async () => { | ||
| const result = await canOpenRoom({ rid: 'channel-id-1', path: 'channel/test-channel' }); | ||
|
|
||
| expect(mockedGetRoomByTypeAndName).not.toHaveBeenCalled(); | ||
| expect(mockedSdkPost).not.toHaveBeenCalled(); | ||
| expect(result).toEqual({ rid: 'channel-id-1' }); | ||
| }); | ||
|
|
||
| it('returns false when getRoomByTypeAndName throws', async () => { | ||
| mockedGetRoomByTypeAndName.mockRejectedValue(new Error('not found')); | ||
|
|
||
| const result = await canOpenRoom({ rid: '', path: 'channel/test-channel' }); | ||
|
|
||
| expect(result).toBe(false); | ||
| }); | ||
| }); | ||
|
|
||
| describe('canOpenRoom — other paths', () => { | ||
| it('returns false when no path and no rid', async () => { | ||
| const result = await canOpenRoom({ rid: '', path: '' }); | ||
| expect(result).toBe(false); | ||
| }); | ||
|
|
||
| it('returns false when path does not match any type', async () => { | ||
| const result = await canOpenRoom({ rid: '', path: 'unknown/foo' }); | ||
| expect(mockedGetRoomByTypeAndName).not.toHaveBeenCalled(); | ||
| expect(result).toBe(false); | ||
| }); | ||
| }); |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.