Skip to content

Commit

Permalink
chore: refactor invitation data mocking
Browse files Browse the repository at this point in the history
  • Loading branch information
siepra committed Nov 14, 2023
1 parent 3582b5d commit bbc4e0e
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 33 deletions.
20 changes: 7 additions & 13 deletions packages/common/src/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ export const validInvitationCodeTestData: InvitationData[] = [
}
]

export const validInvitationUrlTestData = [
{
shareUrl: () => composeInvitationShareUrl(validInvitationCodeTestData[0]),
deepUrl: () => composeInvitationDeepUrl(validInvitationCodeTestData[0]),
code: () => composeInvitationShareUrl(validInvitationCodeTestData[0]).split(QUIET_JOIN_PAGE + '#')[1],
data: validInvitationCodeTestData[0],
},
{
shareUrl: () => composeInvitationShareUrl(validInvitationCodeTestData[1]),
deepUrl: () => composeInvitationDeepUrl(validInvitationCodeTestData[1]),
code: () => composeInvitationShareUrl(validInvitationCodeTestData[1]).split(QUIET_JOIN_PAGE + '#')[1],
data: validInvitationCodeTestData[1],
export const getValidInvitationUrlTestData = (data: InvitationData) => {
return {
shareUrl: () => composeInvitationShareUrl(data),
deepUrl: () => composeInvitationDeepUrl(data),
code: () => composeInvitationShareUrl(data).split(QUIET_JOIN_PAGE + '#')[1],
data: data,
}
]
}
4 changes: 2 additions & 2 deletions packages/desktop/src/main/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { autoUpdater } from 'electron-updater'
import { BrowserWindow, app, ipcMain, Menu } from 'electron'
import { waitFor } from '@testing-library/dom'
import path from 'path'
import { composeInvitationDeepUrl, validInvitationUrlTestData } from '@quiet/common'
import { composeInvitationDeepUrl, getValidInvitationUrlTestData, validInvitationCodeTestData } from '@quiet/common'
import { InvitationData } from '@quiet/types'

// eslint-disable-next-line
Expand Down Expand Up @@ -241,7 +241,7 @@ describe('Invitation code', () => {
let codes: InvitationData

beforeEach(() => {
codes = { ...validInvitationUrlTestData[0].data }
codes = { ...getValidInvitationUrlTestData(validInvitationCodeTestData[0]).data }
})

it('handles invitation code on open-url event (on macos)', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ import PerformCommunityActionComponent from '../PerformCommunityActionComponent'
import { inviteLinkField } from '../../../forms/fields/communityFields'
import { InviteLinkErrors } from '../../../forms/fieldsErrors'
import { CommunityOwnership } from '@quiet/types'
import { Site, QUIET_JOIN_PAGE, validInvitationUrlTestData, PSK_PARAM_KEY } from '@quiet/common'
import { Site, QUIET_JOIN_PAGE, validInvitationCodeTestData, getValidInvitationUrlTestData, PSK_PARAM_KEY } from '@quiet/common'

describe('join community', () => {
const validCode = validInvitationUrlTestData[0].code()
const validData = validInvitationUrlTestData[0].data
const psk = validInvitationUrlTestData[0].data.psk
const { code, data } = getValidInvitationUrlTestData(validInvitationCodeTestData[0])

const validCode = code()

it('users switches from join to create', async () => {
const { store } = await prepareStore({
Expand Down Expand Up @@ -127,7 +127,7 @@ describe('join community', () => {
expect(submitButton).toBeEnabled()
await userEvent.click(submitButton)

await waitFor(() => expect(handleCommunityAction).toBeCalledWith(validData))
await waitFor(() => expect(handleCommunityAction).toBeCalledWith(data))
})

it.each([[`${QUIET_JOIN_PAGE}#${validCode}`], [`${QUIET_JOIN_PAGE}/#${validCode}`]])(
Expand Down Expand Up @@ -161,7 +161,7 @@ describe('join community', () => {
expect(submitButton).toBeEnabled()
await userEvent.click(submitButton)

await waitFor(() => expect(handleCommunityAction).toBeCalledWith(validData))
await waitFor(() => expect(handleCommunityAction).toBeCalledWith(data))
}
)

Expand Down Expand Up @@ -194,12 +194,12 @@ describe('join community', () => {
expect(submitButton).toBeEnabled()
await userEvent.click(submitButton)

await waitFor(() => expect(handleCommunityAction).toBeCalledWith(validData))
await waitFor(() => expect(handleCommunityAction).toBeCalledWith(data))
})

it.each([
[`http://${validCode}`, InviteLinkErrors.InvalidCode],
[`QmZoiJNAvCffeEHBjk766nLuKVdkxkAT7wfFJDPPLsbKSE=bbb&${PSK_PARAM_KEY}=${psk}`, InviteLinkErrors.InvalidCode],
[`QmZoiJNAvCffeEHBjk766nLuKVdkxkAT7wfFJDPPLsbKSE=bbb&${PSK_PARAM_KEY}=${data.psk}`, InviteLinkErrors.InvalidCode],
['bbb=y7yczmugl2tekami7sbdz5pfaemvx7bahwthrdvcbzw5vex2crsr26qd', InviteLinkErrors.InvalidCode],
['QmZoiJNAvCffeEHBjk766nLuKVdkxkAT7wfFJDPPLsbKSE= ', InviteLinkErrors.InvalidCode],
['nqnw4kc4c77fb47lk52m5l57h4tc', InviteLinkErrors.InvalidCode],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { prepareStore } from '../../testUtils/prepareStore'
import { StoreKeys } from '../../store/store.keys'
import { modalsActions } from '../modals/modals.slice'
import { ModalName } from '../modals/modals.types'
import { validInvitationUrlTestData } from '@quiet/common'
import { validInvitationCodeTestData, getValidInvitationUrlTestData } from '@quiet/common'

describe('Handle invitation code', () => {
let store: Store
Expand All @@ -27,7 +27,8 @@ describe('Handle invitation code', () => {
).store

factory = await getFactory(store)
validInvitationData = validInvitationUrlTestData[0].data

validInvitationData = getValidInvitationUrlTestData(validInvitationCodeTestData[0]).data
})

it('creates network if code is valid', async () => {
Expand Down
10 changes: 7 additions & 3 deletions packages/mobile/src/store/init/deepLink/deepLink.saga.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ 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 { composeInvitationShareUrl, validInvitationUrlTestData } from '@quiet/common'
import { composeInvitationShareUrl, validInvitationCodeTestData, getValidInvitationUrlTestData } from '@quiet/common'

describe('deepLinkSaga', () => {
let store: Store

const { code, data } = getValidInvitationUrlTestData(validInvitationCodeTestData[0])

const validCode = code()
const validData = data

const id = '00d045ab'
const validData: InvitationData = validInvitationUrlTestData[0].data
const validCode = validInvitationUrlTestData[0].code()

const community: Community = {
id,
name: '',
Expand Down
6 changes: 3 additions & 3 deletions packages/mobile/src/tests/deep.linking.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ioMock } from '../setupTests'
import { prepareStore } from './utils/prepareStore'
import { renderComponent } from './utils/renderComponent'
import { initActions } from '../store/init/init.slice'
import { validInvitationUrlTestData } from '@quiet/common'
import { validInvitationCodeTestData, getValidInvitationUrlTestData } from '@quiet/common'
import { communities } from '@quiet/state-manager'

describe('Deep linking', () => {
Expand Down Expand Up @@ -36,13 +36,13 @@ describe('Deep linking', () => {
store
)

store.dispatch(initActions.deepLink(validInvitationUrlTestData[0].code()))
store.dispatch(initActions.deepLink(getValidInvitationUrlTestData(validInvitationCodeTestData[0]).code()))
await act(async () => {})

const originalPair = communities.selectors.invitationCodes(store.getState())

// Redo the action to provoke renewed saga runs
store.dispatch(initActions.deepLink(validInvitationUrlTestData[1].code()))
store.dispatch(initActions.deepLink(getValidInvitationUrlTestData(validInvitationCodeTestData[1]).code()))
await act(async () => {})

const currentPair = communities.selectors.invitationCodes(store.getState())
Expand Down
4 changes: 2 additions & 2 deletions packages/mobile/src/tests/splash.screen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { ScreenNames } from '../const/ScreenNames.enum'
import { initActions } from '../store/init/init.slice'
import { take } from 'typed-redux-saga'
import { navigationActions } from '../store/navigation/navigation.slice'
import { validInvitationUrlTestData } from '@quiet/common'
import { validInvitationCodeTestData, getValidInvitationUrlTestData } from '@quiet/common'

describe('Splash screen', () => {
let socket: MockedSocket
Expand All @@ -23,7 +23,7 @@ describe('Splash screen', () => {
test('waits for redux store to become ready, before storing invitation code', async () => {
const { store, root, runSaga } = await prepareStore({}, socket)

const invitationCode = validInvitationUrlTestData[0].code()
const invitationCode = getValidInvitationUrlTestData(validInvitationCodeTestData[0]).code()

const route: { key: string; name: ScreenNames.SplashScreen; path: string } = {
key: '',
Expand Down

0 comments on commit bbc4e0e

Please sign in to comment.