Skip to content

Commit

Permalink
fix: mobile deep link saga - check if invitation code is parseable be…
Browse files Browse the repository at this point in the history
…fore handling it to joincommunityscreen
  • Loading branch information
EmiM committed Oct 25, 2023
1 parent c00c8f9 commit ffdd901
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 14 deletions.
30 changes: 26 additions & 4 deletions packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,13 @@ import { combineReducers } from '@reduxjs/toolkit'
import { reducers } from '../../root.reducer'
import { Store } from '../../store.types'
import { prepareStore } from '../../../tests/utils/prepareStore'
import { communities, connection, getInvitationCodes, identity } from '@quiet/state-manager'
import { communities, connection, identity } from '@quiet/state-manager'
import { initActions } from '../init.slice'
import { navigationActions } from '../../navigation/navigation.slice'
import { ScreenNames } from '../../../const/ScreenNames.enum'
import { deepLinkSaga } from './deepLink.saga'
import { type Community, CommunityOwnership, ConnectionProcessInfo, type Identity, InvitationData } from '@quiet/types'
import { Site, composeInvitationShareUrl } from '@quiet/common'
import { appImages } from '../../../assets'
import { replaceScreen } from '../../../RootNavigation'
import { composeInvitationShareUrl } from '@quiet/common'

describe('deepLinkSaga', () => {
let store: Store
Expand Down Expand Up @@ -136,6 +134,18 @@ describe('deepLinkSaga', () => {
await expectSaga(deepLinkSaga, initActions.deepLink(validCode))
.withReducer(reducer)
.withState(store.getState())
.put.like({
action: {
type: navigationActions.replaceScreen.type,
payload: {
screen: ScreenNames.ErrorScreen,
params: {
title: 'You already belong to a community',
message: "We're sorry but for now you can only be a member of a single community at a time",
},
},
},
})
.not.put(
communities.actions.createNetwork({
ownership: CommunityOwnership.User,
Expand Down Expand Up @@ -166,6 +176,18 @@ describe('deepLinkSaga', () => {
await expectSaga(deepLinkSaga, initActions.deepLink(invalidCode))
.withReducer(reducer)
.withState(store.getState())
.put.like({
action: {
type: navigationActions.replaceScreen.type,
payload: {
screen: ScreenNames.ErrorScreen,
params: {
title: 'Invalid invitation link',
message: 'Please check your invitation link and try again',
},
},
},
})
.not.put(
communities.actions.createNetwork({
ownership: CommunityOwnership.User,
Expand Down
20 changes: 10 additions & 10 deletions packages/mobile/src/store/init/deepLink/deepLink.saga.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,20 +41,11 @@ export function* deepLinkSaga(action: PayloadAction<ReturnType<typeof initAction
return
}

yield* put(
navigationActions.replaceScreen({
screen: ScreenNames.JoinCommunityScreen,
params: {
code,
},
})
)

let data: InvitationData
try {
data = getInvitationCodes(code)
} catch (e) {
console.error(e.message)
console.warn(e.message)
yield* put(
navigationActions.replaceScreen({
screen: ScreenNames.ErrorScreen,
Expand All @@ -69,6 +60,15 @@ export function* deepLinkSaga(action: PayloadAction<ReturnType<typeof initAction
return
}

yield* put(
navigationActions.replaceScreen({
screen: ScreenNames.JoinCommunityScreen,
params: {
code,
},
})
)

const payload: CreateNetworkPayload = {
ownership: CommunityOwnership.User,
peers: data.pairs,
Expand Down

0 comments on commit ffdd901

Please sign in to comment.