From ffdd901e41fc14b02f105435f6423d242d7069a6 Mon Sep 17 00:00:00 2001 From: Emi Date: Wed, 25 Oct 2023 17:38:16 +0200 Subject: [PATCH] fix: mobile deep link saga - check if invitation code is parseable before handling it to joincommunityscreen --- .../store/init/deepLink/deepLink.saga.test.ts | 30 ++++++++++++++++--- .../src/store/init/deepLink/deepLink.saga.ts | 20 ++++++------- 2 files changed, 36 insertions(+), 14 deletions(-) diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts index 55534ca36b..02be128194 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts @@ -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 @@ -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, @@ -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, diff --git a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts index 0d268173ba..dba6abbb0b 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.ts @@ -41,20 +41,11 @@ export function* deepLinkSaga(action: PayloadAction