From 454011d941fa2529a025c32d951c2480b51f458f Mon Sep 17 00:00:00 2001 From: Lucas Leblow Date: Thu, 7 Mar 2024 20:56:52 -0800 Subject: [PATCH] Fixups --- .../connections-manager.service.spec.ts | 20 +++++++++++++++++++ .../connections-manager.service.ts | 6 ++++-- packages/desktop/package.json | 2 +- .../communities/communities.selectors.test.ts | 2 +- 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/nest/connections-manager/connections-manager.service.spec.ts b/packages/backend/src/nest/connections-manager/connections-manager.service.spec.ts index 4e3905442c..0e7dd4eed9 100644 --- a/packages/backend/src/nest/connections-manager/connections-manager.service.spec.ts +++ b/packages/backend/src/nest/connections-manager/connections-manager.service.spec.ts @@ -134,6 +134,26 @@ describe('ConnectionsManagerService', () => { expect(launchCommunitySpy).not.toHaveBeenCalled() }) + it('community is only launched once', async () => { + const launchCommunityPayload = { + community: community, + network: { + peerId: userIdentity.peerId, + hiddenService: userIdentity.hiddenService, + } + } + + //@ts-ignore + const launchSpy = jest.spyOn(connectionsManagerService, 'launch').mockResolvedValue('address') + + await Promise.all([ + connectionsManagerService.launchCommunity(launchCommunityPayload), + connectionsManagerService.launchCommunity(launchCommunityPayload), + ]) + + expect(launchSpy).toBeCalledTimes(1) + }) + it('Bug reproduction - Error on startup - Error: TOR: Connection already established - Trigger launchCommunity from backend and state manager', async () => { await localDbService.setCommunity(community) await localDbService.setCurrentCommunityId(community.id) diff --git a/packages/backend/src/nest/connections-manager/connections-manager.service.ts b/packages/backend/src/nest/connections-manager/connections-manager.service.ts index 8fdfdccf88..6989b49570 100644 --- a/packages/backend/src/nest/connections-manager/connections-manager.service.ts +++ b/packages/backend/src/nest/connections-manager/connections-manager.service.ts @@ -604,10 +604,12 @@ export class ConnectionsManagerService extends EventEmitter implements OnModuleI const community = await this.localDbService.getCurrentCommunity() if (meta && community) { - await this.localDbService.setCommunity({ + const updatedCommunity = { ...community, ownerOrbitDbIdentity: meta.ownerOrbitDbIdentity, - }) + } + await this.localDbService.setCommunity(updatedCommunity) + this.serverIoProvider.io.emit(SocketActionTypes.COMMUNITY_UPDATED, updatedCommunity) } callback(meta) } diff --git a/packages/desktop/package.json b/packages/desktop/package.json index f858bdda9d..f7a2a2b9ed 100644 --- a/packages/desktop/package.json +++ b/packages/desktop/package.json @@ -97,7 +97,7 @@ "type-check": "tsc -p tsconfig.build.json --noEmit", "test": "jest --runInBand", "test:watch": "jest --watchAll", - "rtl-test": "jest ./src/rtl-tests/community.create.test.tsx", + "rtl-test": "jest ./src/rtl-tests", "regression-test:update": "cypress install && ./node_modules/.bin/cypress run --component --env type=base --config screenshotsFolder=cypress/snapshots/base-local", "regression-test": "./node_modules/.bin/cypress run --component --env type=actual,SNAPSHOT_BASE_DIRECTORY=cypress/snapshots/base-local", "regression-test:ci": "cypress install && ./node_modules/.bin/cypress run --component --env type=actual", diff --git a/packages/state-manager/src/sagas/communities/communities.selectors.test.ts b/packages/state-manager/src/sagas/communities/communities.selectors.test.ts index ea59207fa6..16ee02a6cb 100644 --- a/packages/state-manager/src/sagas/communities/communities.selectors.test.ts +++ b/packages/state-manager/src/sagas/communities/communities.selectors.test.ts @@ -39,7 +39,7 @@ describe('communitiesSelectors', () => { expect(communityId).toBe(communityAlpha.id) }) - it.only('select current community', () => { + it('select current community', () => { const community = communitiesSelectors.currentCommunity(store.getState()) expect(community).toEqual({ ...communityAlpha, ownerCertificate: identity.userCertificate }) })