Skip to content

Commit

Permalink
feat(jest): 94% coverage for store/conversation/action (#3297)
Browse files Browse the repository at this point in the history
  • Loading branch information
drepram committed May 25, 2022
1 parent 974956c commit 82872d7
Showing 1 changed file with 243 additions and 0 deletions.
243 changes: 243 additions & 0 deletions store/conversation/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { createFromPubKey } from 'peer-id'
import { ConversationConnection, ConversationActivity } from './types'
import * as actions from '~/store/conversation/actions'
import { RegistrationStatus } from '~/store/accounts/types'
import { DataStateType } from '~/store/dataState/types'
import { CaptureMouseTypes } from '~/store/settings/types'
import { RootState } from '~/types/store/store'

jest.mock('peer-id')
createFromPubKey.mockImplementation(() => 'testpubkey')

describe('actions.default.initialize', () => {
test('0', () => {
Expand Down Expand Up @@ -100,3 +109,237 @@ describe('actions.default.setConversation', () => {
expect(result).toMatchSnapshot()
})
})

describe('misc', () => {
const initialRootState: RootState = {
accounts: {
storePin: true,
loading: true,
locked: true,
pin: '',
pinHash: '',
active: 'true',
gasPrice: '',
phrase: '',
error: '',
encryptedPhrase: '',
registered: true,
details: {
name: '',
address: '',
status: '',
state: 'idle',
unreadCount: 123,
profilePicture: '',
badge: 'community',
userAccount: '',
mailboxId: '',
textilePubkey: '',
},
registrationStatus: RegistrationStatus.IN_PROGRESS,
lastVisited: '',
},
dataState: {
files: DataStateType.Empty,
friends: DataStateType.Loading,
search: DataStateType.Ready,
},
friends: {
incomingRequests: [
{
requestId: '',
account: {
accountId: '',
from: '',
status: 123,
fromMailboxId: '',
toMailboxId: '',
to: '',
},
pending: true,
from: '',
userInfo: {
name: '',
servers: {},
status: '',
photoHash: '',
},
},
],
outgoingRequests: [
{
to: '',
requestId: '',
account: {
accountId: '',
from: '',
status: 123,
fromMailboxId: '',
toMailboxId: '',
to: '',
},
pending: true,
},
],
all: [
{
publicKey: 'NoWiFi4you',
typingState: 'NOT_TYPING',
item: {},
pending: true,
encryptedTextilePubkey: '',
name: 'Taurus Nix',
address: 'QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi', // ADDRESS FOR PEER ID
account: {
accountId: 'Checking Account',
from: '.',
status: 429,
fromMailboxId: '12345',
toMailboxId: 'v4.0.0-rc.4',
to: './path/to/file',
},
textilePubkey: 'https://accounts.google.com/o/oauth2/revoke?token=%s',
status: '',
state: 'idle',
unreadCount: 123,
profilePicture: '',
badge: 'community',
userAccount: '',
mailboxId: '',
},
],
},
textile: {
initialized: true,
conversations: {},
conversationLoading: true,
messageLoading: true,
uploadProgress: {
abc: {
progress: 42,
finished: false,
name: 'file.pdf',
},
},
},
webrtc: {
initialized: true,
incomingCall: undefined,
activeCall: undefined,
streamMuted: {},
},
settings: {
audioInput: '',
audioOutput: '',
videoInput: '',
captureMouse: CaptureMouseTypes.always,
noiseSuppression: true,
echoCancellation: true,
bitrate: 96000,
sampleSize: 24,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
userHasGivenAudioAccess: false,
userDeniedAudioAccess: false,
keybinds: {
toggleMute: 'alt+m',
toggleDeafen: 'alt+d',
openSettings: 'alt+s',
callActiveChat: 'alt+c',
},
embeddedLinks: true,
displayCurrentActivity: true,
},
conversation: {
id: '',
type: 'friend',
calling: false,
participants: [
{
peerId: 'peerId2',
address: 'QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi',
name: 'name2',
profilePicture: 'profilePicture2',
state: ConversationConnection.CONNECTED,
activity: ConversationActivity.ACTIVE,
updatedAt: 123,
},
],
},
}
test('actions.default.setCalling true', () => {
const commit = jest.fn()
const argument = true

actions.default.setCalling({ commit }, argument)
expect(commit).toHaveBeenCalledWith('setCalling', true)
})
test('actions.default.setCalling false', () => {
const commit = jest.fn()
const argument = false

actions.default.setCalling({ commit }, argument)
expect(commit).toHaveBeenCalledWith('setCalling', false)
})
test('actions.default.addParticipants 2 entry', () => {
const dispatch = jest.fn()
const participant = {
peerId: 'peerId',
address: 'address',
name: 'name',
profilePicture: 'profilePicture',
state: ConversationConnection.CONNECTED,
activity: ConversationActivity.ACTIVE,
updatedAt: 123,
}
const participant2 = {
peerId: 'peerId2',
address: 'address2',
name: 'name2',
profilePicture: 'profilePicture2',
state: ConversationConnection.CONNECTED,
activity: ConversationActivity.ACTIVE,
updatedAt: 123,
}
const argument: string[] = [participant.address, participant2.address]

actions.default.addParticipants({ dispatch }, argument)
expect(dispatch).toHaveBeenCalledWith('addParticipant', participant.address)
expect(dispatch).toHaveBeenCalledWith(
'addParticipant',
participant2.address,
)
})
test('actions.default.addParticipant', () => {
const commit = jest.fn()
const rootState = { ...initialRootState }
const state = { ...initialRootState.conversation }
const argument = 'QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi'

actions.default.addParticipant({ commit, state, rootState }, argument)
expect(commit).toHaveBeenCalledWith('updateParticipant', {
address: 'QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi',
name: 'Taurus Nix',
peerId: 'peerId2',
profilePicture: 'profilePicture2',
state: 'DISCONNECTED',
textilePubkey: 'https://accounts.google.com/o/oauth2/revoke?token=%s',
})
})
test.skip('actions.default.addParticipant no peer id', () => {
const commit = jest.fn()
const rootState = { ...initialRootState }
const state = { ...initialRootState.conversation }
state.participants[0].peerId = null
const argument = 'text' // How to pass correct argument? Right now error is: nvalid public key input

actions.default.addParticipant({ commit, state, rootState }, argument)
expect(commit).toHaveBeenCalledWith('updateParticipant', {
address: 'QmckZzdVd72h9QUFuJJpQqhsZqGLwjhh81qSvZ9BhB2FQi',
name: 'Taurus Nix',
peerId: 'peerId2',
profilePicture: 'profilePicture2',
state: 'DISCONNECTED',
textilePubkey: 'https://accounts.google.com/o/oauth2/revoke?token=%s',
})
})
})

0 comments on commit 82872d7

Please sign in to comment.