Skip to content

Commit

Permalink
Merge pull request #425 from internxt/fix/accept-invite-incorrect-fre…
Browse files Browse the repository at this point in the history
…espace-calculation

[PB-3262]: fix/correctly calculate available space in workspace when accepting an invite
  • Loading branch information
jzunigax2 authored Nov 6, 2024
2 parents c0b10b8 + 8d80314 commit 5c3252c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 19 deletions.
24 changes: 6 additions & 18 deletions src/modules/workspaces/workspaces.usecase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand All @@ -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');
Expand Down Expand Up @@ -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');
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion src/modules/workspaces/workspaces.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 5c3252c

Please sign in to comment.