Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
siepra committed Nov 9, 2023
1 parent f766f97 commit cf0ed9f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 36 deletions.
2 changes: 1 addition & 1 deletion packages/identity/src/test/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const createUserCertificateTestHelper = async (
signAlg: config.signAlg,
hashAlg: config.hashAlg,
})

let userCert

if (rootCA) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ describe('registerUsernameSaga', () => {
const factory = await getFactory(store)

const community = await factory.create<ReturnType<typeof communitiesActions.addNewCommunity>['payload']>(
'Community', {
'Community',
{
CA: null,
rootCa: 'rootCertString'
rootCa: 'rootCertString',
}
)

Expand Down Expand Up @@ -87,9 +88,8 @@ describe('registerUsernameSaga', () => {

const factory = await getFactory(store)

const community = await factory.create<ReturnType<typeof communitiesActions.addNewCommunity>['payload']>(
'Community'
)
const community =
await factory.create<ReturnType<typeof communitiesActions.addNewCommunity>['payload']>('Community')

const oldNickname = 'john'
const newNickname = 'paul'
Expand Down Expand Up @@ -163,9 +163,8 @@ describe('registerUsernameSaga', () => {

const factory = await getFactory(store)

const community = await factory.create<ReturnType<typeof communitiesActions.addNewCommunity>['payload']>(
'Community'
)
const community =
await factory.create<ReturnType<typeof communitiesActions.addNewCommunity>['payload']>('Community')

const userCsr: UserCsr = {
userCsr: 'userCsr',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('publicChannelsSelectors', () => {
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 @@ -321,7 +321,8 @@ 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! }))
// @ts-expect-error - This is statically mocked data so it'll never be undefined
store.dispatch(usersActions.test_remove_user_csr({ csr: elouise.userCsr?.userCsr }))

store.dispatch(
publicChannelsActions.setCurrentChannel({
Expand Down
16 changes: 8 additions & 8 deletions packages/state-manager/src/sagas/users/users.selectors.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ describe('users selectors', () => {
onionAddress: aliceCertificateData.onionAddress,
privateKey: '',
},
peerId: {
id: aliceCertificateData.peerId
peerId: {
id: aliceCertificateData.peerId,
},
dmKeys: {
publicKey: aliceCertificateData.dmPublicKey,
privateKey: ''
}
privateKey: '',
},
})

const parsedAliceCertificate = parseCertificate(alice.userCertificate!)
Expand All @@ -61,7 +61,7 @@ describe('users selectors', () => {
aliceUnregistered = await factory.create<ReturnType<typeof identityActions.addNewIdentity>['payload']>('Identity', {
id: community.id,
nickname: aliceCertificateData.username,
userCertificate: null
userCertificate: null,
})

const parsedAliceUnregisteredCertificationRequest = parseCertificationRequest(aliceUnregistered.userCsr!.userCsr)
Expand Down Expand Up @@ -90,23 +90,23 @@ describe('users selectors', () => {
`)
})

it('gets registered user with proper \'isRegistered\' prop', async () => {
it("gets registered user with proper 'isRegistered' prop", async () => {
const users = usersSelectors.allUsers(store.getState())

expect(users[alicePublicKey]).toMatchObject({
isRegistered: true,
})
})

it('gets unregistered user with proper \'isRegistered\' prop', async () => {
it("gets unregistered user with proper 'isRegistered' prop", async () => {
const users = usersSelectors.allUsers(store.getState())

expect(users[aliceUnregisteredPublicKey]).toMatchObject({
isRegistered: false,
})
})

it('gets all users (registered users don\'t get \'duplicate\' label over unregistered ones)', async () => {
it("gets all users (registered users don't get 'duplicate' label over unregistered ones)", async () => {
const users = usersSelectors.allUsers(store.getState())

expect(users[alicePublicKey]).toMatchObject({
Expand Down
2 changes: 1 addition & 1 deletion packages/state-manager/src/sagas/users/users.selectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export const certificatesMapping = createSelector(certificates, certs => {

export const csrsMapping = createSelector(csrs, csrs => {
const mapping: Record<string, UserData> = {}

Object.keys(csrs).map(pubKey => {
const csr = csrs[pubKey]
if (!csr || csr.subject.typesAndValues.length < 1) {
Expand Down
5 changes: 1 addition & 4 deletions packages/state-manager/src/sagas/users/users.slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export const usersSlice = createSlice({
)
},
test_remove_user_csr: (state, action: PayloadAction<{ csr: string }>) => {
certificatesAdapter.removeOne(
state.csrs,
keyFromCertificate(parseCertificationRequest(action.payload.csr))
)
certificatesAdapter.removeOne(state.csrs, keyFromCertificate(parseCertificationRequest(action.payload.csr)))
},
},
})
Expand Down
25 changes: 13 additions & 12 deletions packages/state-manager/src/utils/tests/factories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ import {

import { ChannelMessage, FileMetadata, MessageType, SendingStatus } from '@quiet/types'


export const generateMessageFactoryContentWithId = (
channelId: string,
type?: MessageType,
media?: FileMetadata
): ChannelMessage => {
return {
): ChannelMessage => {
return {
id: (Math.random() * 10 ** 18).toString(36),
type: type || MessageType.Basic,
message: (Math.random() * 10 ** 18).toString(36),
Expand Down Expand Up @@ -107,7 +106,7 @@ export const getFactory = async (store: Store) => {
afterBuild: async (action: ReturnType<typeof identity.actions.addNewIdentity>) => {
const createCsr = action.payload.userCsr === undefined
const requestCertificate = action.payload.userCertificate === undefined

const community = communities.selectors.selectEntities(store.getState())[action.payload.id]!

const userCertData = await createUserCertificateTestHelper(
Expand All @@ -124,19 +123,21 @@ export const getFactory = async (store: Store) => {
action.payload.userCsr = userCertData.userCsr

const csrsObjects = users.selectors.csrs(store.getState())

// TODO: Converting CertificationRequest to string can be an util method
const csrsStrings = Object.values(csrsObjects).map(obj => {
if (!(obj instanceof CertificationRequest)) return
return Buffer.from(obj.toSchema(true).toBER(false)).toString('base64')
}).filter(Boolean) // Filter out possible `undefined` values
const csrsStrings = Object.values(csrsObjects)
.map(obj => {
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])
csrs: csrsStrings.concat([userCertData.userCsr.userCsr]),
})
}

if (requestCertificate && userCertData.userCert?.userCertString) {
if (requestCertificate && userCertData.userCert?.userCertString) {
action.payload.userCertificate = userCertData.userCert.userCertString

// Store user's certificate even if the user won't be stored itself
Expand All @@ -161,7 +162,7 @@ export const getFactory = async (store: Store) => {
)

factory.define('UserCSR', users.actions.storeCsrs, {
csrs: []
csrs: [],
})

factory.define('UserCertificate', users.actions.storeUserCertificate, {
Expand Down

0 comments on commit cf0ed9f

Please sign in to comment.