Skip to content

Commit

Permalink
fix: public channel selectors test
Browse files Browse the repository at this point in the history
  • Loading branch information
siepra committed Nov 9, 2023
1 parent ad7e457 commit 46fda7f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,18 @@ describe('publicChannelsSelectors', () => {
id: community.id,
nickname: 'alice',
})

const generalChannelState = publicChannelsSelectors.generalChannel(store.getState())
if (generalChannelState) generalChannel = generalChannelState

expect(generalChannel).not.toBeUndefined()

channelIdes = [...channelIdes, generalChannel.id]
john = await factory.create<ReturnType<typeof identityActions.addNewIdentity>['payload']>('Identity', {
id: community.id,
nickname: 'john',
})

store.dispatch(publicChannelsActions.setCurrentChannel({ channelId: generalChannel.id }))
// Setup channels
const channelNames = ['croatia', 'allergies', 'sailing', 'pets', 'antiques']
Expand Down Expand Up @@ -296,7 +300,7 @@ describe('publicChannelsSelectors', () => {
expect(channels).toStrictEqual(['general', 'allergies', 'antiques', 'croatia', 'pets', 'sailing'])
})

it.skip("don't select messages without author", async () => {
it("don't select messages without author", async () => {
const channelId = generateChannelId('utah')
const channel = (
await factory.create<ReturnType<typeof publicChannels.actions.addChannel>['payload']>('PublicChannel', {
Expand All @@ -317,6 +321,7 @@ describe('publicChannelsSelectors', () => {

if (!elouise.userCertificate) throw new Error('no elouise.userCertificate')
store.dispatch(usersActions.test_remove_user_certificate({ certificate: elouise.userCertificate }))
store.dispatch(usersActions.test_remove_user_csr({ csr: elouise.userCsr?.userCsr! }))

store.dispatch(
publicChannelsActions.setCurrentChannel({
Expand Down
6 changes: 6 additions & 0 deletions packages/state-manager/src/sagas/users/users.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export const usersSlice = createSlice({
keyFromCertificate(parseCertificate(action.payload.certificate))
)
},
test_remove_user_csr: (state, action: PayloadAction<{ csr: string }>) => {
certificatesAdapter.removeOne(
state.csrs,
keyFromCertificate(parseCertificationRequest(action.payload.csr))
)
},
},
})

Expand Down
15 changes: 5 additions & 10 deletions packages/state-manager/src/utils/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Store } from '../../sagas/store.types'

import { createMessageSignatureTestHelper, createPeerIdTestHelper } from './helpers'

import { getCrypto } from 'pkijs'
import { CertificationRequest, getCrypto } from 'pkijs'
import { stringToArrayBuffer } from 'pvutils'

import { DateTime } from 'luxon'
Expand Down Expand Up @@ -127,15 +127,10 @@ export const getFactory = async (store: Store) => {

// TODO: Converting CertificationRequest to string can be an util method
const csrsStrings = Object.values(csrsObjects).map(obj => {
let value
try {
value = Buffer.from(obj.toSchema(true).toBER(false)).toString('base64')
} catch {
console.error('ERROR: cannot parse CertificationRequest to base64')
}
return value
})

if (!(obj instanceof CertificationRequest)) return
return Buffer.from(obj.toSchema(true).toBER(false)).toString('base64')
}).filter(Boolean) // Filter out possible `undefined` values

await factory.create('UserCSR', {
csrs: csrsStrings.concat([userCertData.userCsr.userCsr])
})
Expand Down

0 comments on commit 46fda7f

Please sign in to comment.