diff --git a/packages/desktop/src/renderer/testUtils/index.ts b/packages/desktop/src/renderer/testUtils/index.ts index 2a8f54c14e..8138beb934 100644 --- a/packages/desktop/src/renderer/testUtils/index.ts +++ b/packages/desktop/src/renderer/testUtils/index.ts @@ -1,4 +1,3 @@ export * from './generateMessages' export * from './prepareStore' export * from './renderComponent' -export * from './socket' diff --git a/packages/desktop/src/renderer/testUtils/socket.ts b/packages/desktop/src/renderer/testUtils/socket.ts deleted file mode 100644 index 5076c87c71..0000000000 --- a/packages/desktop/src/renderer/testUtils/socket.ts +++ /dev/null @@ -1 +0,0 @@ -export type socketEventData = [...T] diff --git a/packages/desktop/src/rtl-tests/channel.add.test.tsx b/packages/desktop/src/rtl-tests/channel.add.test.tsx index 06534239b6..027949c65c 100644 --- a/packages/desktop/src/rtl-tests/channel.add.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.add.test.tsx @@ -6,7 +6,7 @@ import { act } from 'react-dom/test-utils' import { take } from 'typed-redux-saga' import MockedSocket from 'socket.io-mock' import { ioMock } from '../shared/setupTests' -import { socketEventData } from '../renderer/testUtils/socket' +import { socketEventData } from '@quiet/types' import { renderComponent } from '../renderer/testUtils/renderComponent' import { prepareStore } from '../renderer/testUtils/prepareStore' import { StoreKeys } from '../renderer/store/store.keys' diff --git a/packages/desktop/src/rtl-tests/channel.main.test.tsx b/packages/desktop/src/rtl-tests/channel.main.test.tsx index 924111e61b..c4148b6ac0 100644 --- a/packages/desktop/src/rtl-tests/channel.main.test.tsx +++ b/packages/desktop/src/rtl-tests/channel.main.test.tsx @@ -6,7 +6,7 @@ import { apply, take } from 'typed-redux-saga' import userEvent from '@testing-library/user-event' import MockedSocket from 'socket.io-mock' import { ioMock } from '../shared/setupTests' -import { socketEventData } from '../renderer/testUtils/socket' +import { socketEventData } from '@quiet/types' import { renderComponent } from '../renderer/testUtils/renderComponent' import { prepareStore } from '../renderer/testUtils/prepareStore' import Channel from '../renderer/components/Channel/Channel' diff --git a/packages/desktop/src/rtl-tests/community.create.test.tsx b/packages/desktop/src/rtl-tests/community.create.test.tsx index 44653b7730..a90f5660fb 100644 --- a/packages/desktop/src/rtl-tests/community.create.test.tsx +++ b/packages/desktop/src/rtl-tests/community.create.test.tsx @@ -13,7 +13,7 @@ import { ModalName } from '../renderer/sagas/modals/modals.types' import { CreateCommunityDictionary } from '../renderer/components/CreateJoinCommunity/community.dictionary' import MockedSocket from 'socket.io-mock' import { ioMock } from '../shared/setupTests' -import { socketEventData } from '../renderer/testUtils/socket' +import { socketEventData } from '@quiet/types' import { Community, type InitCommunityPayload, diff --git a/packages/desktop/src/rtl-tests/community.join.test.tsx b/packages/desktop/src/rtl-tests/community.join.test.tsx index a8c469bae0..cb6f613a99 100644 --- a/packages/desktop/src/rtl-tests/community.join.test.tsx +++ b/packages/desktop/src/rtl-tests/community.join.test.tsx @@ -13,7 +13,7 @@ import { ModalName } from '../renderer/sagas/modals/modals.types' import { JoinCommunityDictionary } from '../renderer/components/CreateJoinCommunity/community.dictionary' import MockedSocket from 'socket.io-mock' import { ioMock } from '../shared/setupTests' -import { socketEventData } from '../renderer/testUtils/socket' +import { socketEventData } from '@quiet/types' import { communities, RegisterUserCertificatePayload, 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 a954dcff94..a74e6f8eb2 100644 --- a/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts +++ b/packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts @@ -125,12 +125,12 @@ describe('deepLinkSaga', () => { }) ) + community.psk = validData.psk + store.dispatch(communities.actions.addNewCommunity(community)) store.dispatch(communities.actions.setCurrentCommunity(community.id)) - store.dispatch(communities.actions.savePSK(validData.psk)) - const reducer = combineReducers(reducers) await expectSaga(deepLinkSaga, initActions.deepLink(validCode)) .withReducer(reducer) diff --git a/packages/mobile/src/tests/deep.linking.test.tsx b/packages/mobile/src/tests/deep.linking.test.tsx index d3aa036fdf..651ec706d2 100644 --- a/packages/mobile/src/tests/deep.linking.test.tsx +++ b/packages/mobile/src/tests/deep.linking.test.tsx @@ -9,16 +9,32 @@ import { prepareStore } from './utils/prepareStore' import { renderComponent } from './utils/renderComponent' import { initActions } from '../store/init/init.slice' import { validInvitationCodeTestData, getValidInvitationUrlTestData } from '@quiet/common' -import { communities } from '@quiet/state-manager' +import { communities, createPeerIdTestHelper } from '@quiet/state-manager' +import { NetworkInfo, SocketActionTypes, socketEventData } from '@quiet/types' + +const mockEmitImpl = async (...input: [SocketActionTypes, ...socketEventData<[any]>]) => { + const action = input[0] + if (action === SocketActionTypes.CREATE_NETWORK) { + const data: NetworkInfo = { + hiddenService: { + onionAddress: 'onionAddress', + privateKey: 'privateKey', + }, + peerId: createPeerIdTestHelper(), + } + return data + } +} describe('Deep linking', () => { let socket: MockedSocket beforeEach(async () => { socket = new MockedSocket() - // @ts-ignore - socket.emitWithAck = jest.fn() ioMock.mockImplementation(() => socket) + jest.spyOn(socket, 'emit').mockImplementation(mockEmitImpl) + // @ts-ignore + socket.emitWithAck = mockEmitImpl }) test('does not override network data if triggered twice', async () => { @@ -55,13 +71,13 @@ describe('Deep linking', () => { "Communities/joinNetwork", "Communities/createNetwork", "Navigation/replaceScreen", - "Communities/setInvitationCodes", - "Communities/savePSK", "Communities/addNewCommunity", - "Navigation/replaceScreen", "Communities/setCurrentCommunity", "Communities/setInvitationCodes", + "Identity/addNewIdentity", "Init/deepLink", + "Init/resetDeepLink", + "Navigation/replaceScreen", ] `) diff --git a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts index ed84a06819..1247bcfb16 100644 --- a/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts +++ b/packages/state-manager/src/sagas/communities/createNetwork/createNetwork.saga.ts @@ -5,7 +5,7 @@ import { generateId } from '../../../utils/cryptography/cryptography' import { communitiesActions } from '../communities.slice' import { identityActions } from '../../identity/identity.slice' import { createRootCA } from '@quiet/identity' -import { type Community, CommunityOwnership, type Identity, SocketActionTypes } from '@quiet/types' +import { type Community, CommunityOwnership, type Identity, SocketActionTypes, NetworkInfo } from '@quiet/types' import { generateDmKeyPair } from '../../../utils/cryptography/cryptography' import { Socket, applyEmitParams } from '../../../types' @@ -18,7 +18,11 @@ export function* createNetworkSaga( // Community IDs are only local identifiers const id = yield* call(generateId) - const network = yield* apply(socket, socket.emitWithAck, applyEmitParams(SocketActionTypes.CREATE_NETWORK, id)) + const network: NetworkInfo = yield* apply( + socket, + socket.emitWithAck, + applyEmitParams(SocketActionTypes.CREATE_NETWORK, id) + ) // TODO: Move CA generation to backend when creating Community let CA: null | { diff --git a/packages/types/src/index.ts b/packages/types/src/index.ts index 3d16fdbe16..0a7902637e 100644 --- a/packages/types/src/index.ts +++ b/packages/types/src/index.ts @@ -9,3 +9,4 @@ export * from './message' export * from './files' export * from './channel' export * from './network' +export * from './test'