From 8d80314549733ed6dcd3b3d44a4898ebd75c92a4 Mon Sep 17 00:00:00 2001 From: jzunigax2 <125698953+jzunigax2@users.noreply.github.com> Date: Wed, 6 Nov 2024 11:01:49 -0600 Subject: [PATCH] fix: correctly calculate available space in workspace when accepting an invite --- .../workspaces/workspaces.usecase.spec.ts | 24 +++++-------------- src/modules/workspaces/workspaces.usecase.ts | 2 +- 2 files changed, 7 insertions(+), 19 deletions(-) diff --git a/src/modules/workspaces/workspaces.usecase.spec.ts b/src/modules/workspaces/workspaces.usecase.spec.ts index 79d054bf..62a39b1c 100644 --- a/src/modules/workspaces/workspaces.usecase.spec.ts +++ b/src/modules/workspaces/workspaces.usecase.spec.ts @@ -1289,9 +1289,7 @@ describe('WorkspacesUsecases', () => { jest .spyOn(userRepository, 'findByUuid') .mockResolvedValueOnce(workspaceUser); - jest - .spyOn(service, 'getAssignableSpaceInWorkspace') - .mockResolvedValueOnce(3000); + jest.spyOn(service, 'getOwnerAvailableSpace').mockResolvedValueOnce(3000); await expect( service.acceptWorkspaceInvite(invitedUser, 'anyUuid'), @@ -1317,9 +1315,7 @@ describe('WorkspacesUsecases', () => { jest .spyOn(userRepository, 'findByUuid') .mockResolvedValueOnce(workspaceUser); - jest - .spyOn(service, 'getAssignableSpaceInWorkspace') - .mockResolvedValueOnce(3000); + jest.spyOn(service, 'getOwnerAvailableSpace').mockResolvedValueOnce(3000); jest.spyOn(service, 'adjustOwnerStorage').mockResolvedValueOnce(); await service.acceptWorkspaceInvite(invitedUser, 'anyUuid'); @@ -1356,9 +1352,7 @@ describe('WorkspacesUsecases', () => { jest .spyOn(userRepository, 'findByUuid') .mockResolvedValueOnce(workspaceUser); - jest - .spyOn(service, 'getAssignableSpaceInWorkspace') - .mockResolvedValueOnce(3000); + jest.spyOn(service, 'getOwnerAvailableSpace').mockResolvedValueOnce(3000); jest.spyOn(service, 'adjustOwnerStorage').mockResolvedValueOnce(); await service.acceptWorkspaceInvite(invitedUser, 'anyUuid'); @@ -1389,9 +1383,7 @@ describe('WorkspacesUsecases', () => { jest .spyOn(userRepository, 'findByUuid') .mockResolvedValueOnce(workspaceUser); - jest - .spyOn(service, 'getAssignableSpaceInWorkspace') - .mockResolvedValueOnce(3000); + jest.spyOn(service, 'getOwnerAvailableSpace').mockResolvedValueOnce(3000); jest .spyOn(teamRepository, 'addUserToTeam') .mockRejectedValueOnce( @@ -1432,9 +1424,7 @@ describe('WorkspacesUsecases', () => { jest .spyOn(userRepository, 'findByUuid') .mockResolvedValueOnce(workspaceUser); - jest - .spyOn(service, 'getAssignableSpaceInWorkspace') - .mockResolvedValueOnce(3000); + jest.spyOn(service, 'getOwnerAvailableSpace').mockResolvedValueOnce(3000); jest .spyOn(workspaceRepository, 'addUserToWorkspace') .mockRejectedValueOnce( @@ -1474,9 +1464,7 @@ describe('WorkspacesUsecases', () => { jest .spyOn(userRepository, 'findByUuid') .mockResolvedValueOnce(workspaceUser); - jest - .spyOn(service, 'getAssignableSpaceInWorkspace') - .mockResolvedValueOnce(3000); + jest.spyOn(service, 'getOwnerAvailableSpace').mockResolvedValueOnce(3000); jest.spyOn(service, 'adjustOwnerStorage').mockResolvedValueOnce(); await service.acceptWorkspaceInvite(invitedUser, 'anyUuid'); diff --git a/src/modules/workspaces/workspaces.usecase.ts b/src/modules/workspaces/workspaces.usecase.ts index 603f7c71..30457cb1 100644 --- a/src/modules/workspaces/workspaces.usecase.ts +++ b/src/modules/workspaces/workspaces.usecase.ts @@ -1525,7 +1525,7 @@ export class WorkspacesUsecases { ); } - const spaceLeft = await this.getAssignableSpaceInWorkspace(workspace); + const spaceLeft = await this.getOwnerAvailableSpace(workspace); if (invite.spaceLimit > spaceLeft) { throw new BadRequestException(