Skip to content

Commit

Permalink
Merge pull request #367 from internxt/fix/workspace-billing-address
Browse files Browse the repository at this point in the history
[PB-2353]: feat/add endpoint to edit workspace billing address
  • Loading branch information
apsantiso authored Jul 19, 2024
2 parents a45c0b6 + 6a842cd commit ef23605
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/modules/workspaces/domains/workspaces.domain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ export class Workspace implements WorkspaceAttributes {
defaultTeamId: this.defaultTeamId,
avatar: this.avatar,
workspaceUserId: this.workspaceUserId,
numberOfSeats: this.numberOfSeats,
setupCompleted: this.setupCompleted,
createdAt: this.createdAt,
updatedAt: this.updatedAt,
};
Expand Down
4 changes: 4 additions & 0 deletions src/modules/workspaces/dto/edit-workspace-details-dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ export class EditWorkspaceDetailsDto {
@IsString()
@Length(0, 150)
description?: Workspace['description'];
@IsOptional()
@IsString()
@Length(5, 255)
address?: Workspace['address'];
}
22 changes: 21 additions & 1 deletion src/modules/workspaces/workspaces.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,18 @@ describe('Workspace Controller', () => {
workspacesController.editWorkspaceDetails(workspace.id, user, {
name: 'new name',
description: 'new description',
address: 'new address',
}),
).resolves.toBeUndefined();

expect(workspacesUsecases.editWorkspaceDetails).toHaveBeenCalledWith(
workspace.id,
user,
{ name: 'new name' },
{
name: 'new name',
description: 'new description',
address: 'new address',
},
);
});
});
Expand Down Expand Up @@ -590,4 +595,19 @@ describe('Workspace Controller', () => {
);
});
});

describe('GET /:workspaceId', () => {
it('When a workspace is requested, then it should return the workspace data', async () => {
const user = newUser();
const workspace = newWorkspace();

jest
.spyOn(workspacesUsecases, 'getWorkspaceDetails')
.mockResolvedValueOnce(workspace.toJSON());

await expect(
workspacesController.getWorkspaceDetails(workspace.id, user),
).resolves.toEqual(workspace.toJSON());
});
});
});
19 changes: 19 additions & 0 deletions src/modules/workspaces/workspaces.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -958,4 +958,23 @@ export class WorkspacesController {
workspaceId,
);
}

@Get(':workspaceId')
@ApiBearerAuth()
@ApiOperation({
summary: 'Get workspace details',
})
@ApiParam({ name: 'workspaceId', type: String, required: true })
@ApiOkResponse({
description: 'Workspace details',
})
@UseGuards(WorkspaceGuard)
@WorkspaceRequiredAccess(AccessContext.WORKSPACE, WorkspaceRole.MEMBER)
async getWorkspaceDetails(
@Param('workspaceId', ValidateUUIDPipe)
workspaceId: WorkspaceAttributes['id'],
@UserDecorator() user: User,
) {
return this.workspaceUseCases.getWorkspaceDetails(workspaceId);
}
}
22 changes: 22 additions & 0 deletions src/modules/workspaces/workspaces.usecase.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,34 @@ describe('WorkspacesUsecases', () => {
});
});

describe('getWorkspaceDetails', () => {
it('When workspace does not exist, then it should throw', async () => {
jest.spyOn(workspaceRepository, 'findById').mockResolvedValueOnce(null);

await expect(service.getWorkspaceDetails(v4())).rejects.toThrow(
NotFoundException,
);
});

it('When workspace exists, then it should return the workspace details', async () => {
const workspace = newWorkspace();
jest
.spyOn(workspaceRepository, 'findById')
.mockResolvedValueOnce(workspace);

const result = await service.getWorkspaceDetails(workspace.id);

expect(result).toEqual(workspace.toJSON());
});
});

describe('editWorkspaceDetails', () => {
const user = newUser();
const workspace = newWorkspace({ owner: user });
const editWorkspaceDto: EditWorkspaceDetailsDto = {
name: 'Test Workspace',
description: 'Workspace description',
address: 'Workspace Address',
};
it('When workspace does not exist, then it should throw', async () => {
jest.spyOn(workspaceRepository, 'findById').mockResolvedValueOnce(null);
Expand Down
10 changes: 10 additions & 0 deletions src/modules/workspaces/workspaces.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,16 @@ export class WorkspacesUsecases {
}
}

async getWorkspaceDetails(workspaceId: Workspace['id']) {
const workspace = await this.workspaceRepository.findById(workspaceId);

if (!workspace) {
throw new NotFoundException('Workspace not found');
}

return workspace.toJSON();
}

async setupWorkspace(
user: User,
workspaceId: WorkspaceAttributes['id'],
Expand Down

0 comments on commit ef23605

Please sign in to comment.