Skip to content

Commit

Permalink
fix: mobile tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EmiM committed Apr 9, 2024
1 parent cd863db commit 0ce7c15
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 16 deletions.
1 change: 0 additions & 1 deletion packages/desktop/src/renderer/testUtils/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from './generateMessages'
export * from './prepareStore'
export * from './renderComponent'
export * from './socket'
1 change: 0 additions & 1 deletion packages/desktop/src/renderer/testUtils/socket.ts

This file was deleted.

2 changes: 1 addition & 1 deletion packages/desktop/src/rtl-tests/channel.add.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/rtl-tests/channel.main.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/rtl-tests/community.create.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion packages/desktop/src/rtl-tests/community.join.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 22 additions & 6 deletions packages/mobile/src/tests/deep.linking.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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",
]
`)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'

Expand All @@ -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 | {
Expand Down
1 change: 1 addition & 0 deletions packages/types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './message'
export * from './files'
export * from './channel'
export * from './network'
export * from './test'

0 comments on commit 0ce7c15

Please sign in to comment.