From cf0ed9ff98704e4291b458de906f2eff55f7de80 Mon Sep 17 00:00:00 2001 From: siepra Date: Thu, 9 Nov 2023 14:50:17 +0100 Subject: [PATCH] fix: lint --- packages/identity/src/test/helpers.ts | 2 +- .../registerUsername.saga.test.ts | 15 ++++++----- .../publicChannels.selectors.test.ts | 5 ++-- .../src/sagas/users/users.selectors.test.ts | 16 ++++++------ .../src/sagas/users/users.selectors.ts | 2 +- .../src/sagas/users/users.slice.ts | 5 +--- .../src/utils/tests/factories.ts | 25 ++++++++++--------- 7 files changed, 34 insertions(+), 36 deletions(-) diff --git a/packages/identity/src/test/helpers.ts b/packages/identity/src/test/helpers.ts index e7bccce525..68760bfbb8 100644 --- a/packages/identity/src/test/helpers.ts +++ b/packages/identity/src/test/helpers.ts @@ -77,7 +77,7 @@ export const createUserCertificateTestHelper = async ( signAlg: config.signAlg, hashAlg: config.hashAlg, }) - + let userCert if (rootCA) { diff --git a/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.test.ts b/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.test.ts index 0cd0e0c9cb..3a10b2ebda 100644 --- a/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.test.ts +++ b/packages/state-manager/src/sagas/identity/registerUsername/registerUsername.saga.test.ts @@ -23,9 +23,10 @@ describe('registerUsernameSaga', () => { const factory = await getFactory(store) const community = await factory.create['payload']>( - 'Community', { + 'Community', + { CA: null, - rootCa: 'rootCertString' + rootCa: 'rootCertString', } ) @@ -87,9 +88,8 @@ describe('registerUsernameSaga', () => { const factory = await getFactory(store) - const community = await factory.create['payload']>( - 'Community' - ) + const community = + await factory.create['payload']>('Community') const oldNickname = 'john' const newNickname = 'paul' @@ -163,9 +163,8 @@ describe('registerUsernameSaga', () => { const factory = await getFactory(store) - const community = await factory.create['payload']>( - 'Community' - ) + const community = + await factory.create['payload']>('Community') const userCsr: UserCsr = { userCsr: 'userCsr', diff --git a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts index df030574fe..f392b997f3 100644 --- a/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts +++ b/packages/state-manager/src/sagas/publicChannels/publicChannels.selectors.test.ts @@ -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'] @@ -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({ diff --git a/packages/state-manager/src/sagas/users/users.selectors.test.ts b/packages/state-manager/src/sagas/users/users.selectors.test.ts index 65564045c3..50af782c63 100644 --- a/packages/state-manager/src/sagas/users/users.selectors.test.ts +++ b/packages/state-manager/src/sagas/users/users.selectors.test.ts @@ -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!) @@ -61,7 +61,7 @@ describe('users selectors', () => { aliceUnregistered = await factory.create['payload']>('Identity', { id: community.id, nickname: aliceCertificateData.username, - userCertificate: null + userCertificate: null, }) const parsedAliceUnregisteredCertificationRequest = parseCertificationRequest(aliceUnregistered.userCsr!.userCsr) @@ -90,7 +90,7 @@ 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({ @@ -98,7 +98,7 @@ describe('users selectors', () => { }) }) - 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({ @@ -106,7 +106,7 @@ describe('users selectors', () => { }) }) - 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({ diff --git a/packages/state-manager/src/sagas/users/users.selectors.ts b/packages/state-manager/src/sagas/users/users.selectors.ts index 11ac89c895..ed29f0a23e 100644 --- a/packages/state-manager/src/sagas/users/users.selectors.ts +++ b/packages/state-manager/src/sagas/users/users.selectors.ts @@ -47,7 +47,7 @@ export const certificatesMapping = createSelector(certificates, certs => { export const csrsMapping = createSelector(csrs, csrs => { const mapping: Record = {} - + Object.keys(csrs).map(pubKey => { const csr = csrs[pubKey] if (!csr || csr.subject.typesAndValues.length < 1) { diff --git a/packages/state-manager/src/sagas/users/users.slice.ts b/packages/state-manager/src/sagas/users/users.slice.ts index b3fb4d3c1e..41add27d6e 100644 --- a/packages/state-manager/src/sagas/users/users.slice.ts +++ b/packages/state-manager/src/sagas/users/users.slice.ts @@ -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))) }, }, }) diff --git a/packages/state-manager/src/utils/tests/factories.ts b/packages/state-manager/src/utils/tests/factories.ts index b25f08662c..f59eb396d6 100644 --- a/packages/state-manager/src/utils/tests/factories.ts +++ b/packages/state-manager/src/utils/tests/factories.ts @@ -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), @@ -107,7 +106,7 @@ export const getFactory = async (store: Store) => { afterBuild: async (action: ReturnType) => { 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( @@ -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 @@ -161,7 +162,7 @@ export const getFactory = async (store: Store) => { ) factory.define('UserCSR', users.actions.storeCsrs, { - csrs: [] + csrs: [], }) factory.define('UserCertificate', users.actions.storeUserCertificate, {