Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PB-2353]: feat/add endpoint to edit workspace billing address #367

Merged
merged 5 commits into from
Jul 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading