Skip to content

Commit

Permalink
Add test for user profile selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Leblow committed Nov 6, 2023
1 parent 1eb1ec9 commit c7e03c9
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ describe('saveUserProfileSaga', () => {
// We are testing browser-targeting code in NodeJS and this
// version of NodeJS doesn't have a File class, so we are using a
// Blob instead.
// @ts-ignore
await expectSaga(
saveUserProfileSaga,
socket as unknown as Socket,
// @ts-ignore
usersActions.saveUserProfile({ photo: new Blob([]) })
)
.withState(store.getState())
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { combineReducers, createStore, type Store } from '@reduxjs/toolkit'
import { StoreKeys } from '../../store.keys'

import { createUserCsr, pubKeyFromCsr } from '@quiet/identity'
import { type Identity, type UserCsr, type UserProfile } from '@quiet/types'

import { communitiesReducer, CommunitiesState } from '../../communities/communities.slice'
import { usersReducer, UsersState } from '../users.slice'
import { identityReducer, IdentityState } from '../../identity/identity.slice'
import { identityAdapter } from '../../identity/identity.adapter'
import { userProfileSelectors } from './userProfile.selectors'

describe('user profile selectors', () => {
let csr: UserCsr
let identity: Identity
let pubKey: string
let profile: UserProfile

let store: Store

beforeAll(async () => {
csr = await createUserCsr({
nickname: '',
commonName: '',
peerId: '',
dmPublicKey: '',
signAlg: '',
hashAlg: '',
})

identity = {
id: 'communityId',
userCsr: csr,
} as Identity

profile = {
profile: { photo: 'test' },
} as UserProfile

pubKey = pubKeyFromCsr(csr.userCsr)
})

beforeEach(() => {
store = createStore(
combineReducers({
[StoreKeys.Communities]: communitiesReducer,
[StoreKeys.Users]: usersReducer,
[StoreKeys.Identity]: identityReducer,
}),
{
[StoreKeys.Communities]: {
...new CommunitiesState(),
currentCommunity: 'communityId',
},
[StoreKeys.Users]: {
...new UsersState(),
userProfiles: { [pubKey]: profile },
},
[StoreKeys.Identity]: {
...new IdentityState(),
identities: identityAdapter.setAll(identityAdapter.getInitialState(), [identity]),
},
}
)
})

it("myUserProfile returns the current user's profile", async () => {
const userProfile = userProfileSelectors.myUserProfile(store.getState())
expect(userProfile).toEqual(profile)
})
})

export {}

0 comments on commit c7e03c9

Please sign in to comment.