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

feat(api): Replace projectId with name and slug in workspace-role response. #432

Merged
merged 7 commits into from
Sep 17, 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
28 changes: 25 additions & 3 deletions apps/api/src/workspace-role/service/workspace-role.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,13 @@ export class WorkspaceRoleService {
include: {
projects: {
select: {
projectId: true
project: {
select: {
id: true,
slug: true,
name: true
}
}
}
}
}
Expand Down Expand Up @@ -228,7 +234,13 @@ export class WorkspaceRoleService {
include: {
projects: {
select: {
projectId: true
project: {
select: {
id: true,
slug: true,
name: true
}
}
}
}
}
Expand Down Expand Up @@ -443,7 +455,17 @@ export class WorkspaceRoleService {
slug: workspaceRoleSlug
},
include: {
projects: true
projects: {
select: {
project: {
select: {
id: true,
slug: true,
name: true
}
}
}
}
}
})) as WorkspaceRoleWithProjects

Expand Down
24 changes: 20 additions & 4 deletions apps/api/src/workspace-role/workspace-role.e2e.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -607,10 +607,18 @@ describe('Workspace Role Controller Tests', () => {
updatedAt: expect.any(String),
projects: expect.arrayContaining([
{
projectId: projects[0].id
project: {
id: projects[0].id,
name: projects[0].name,
slug: projects[0].slug
}
},
{
projectId: projects[1].id
project: {
id: projects[1].id,
name: projects[1].name,
slug: projects[1].slug
}
}
])
})
Expand Down Expand Up @@ -654,10 +662,18 @@ describe('Workspace Role Controller Tests', () => {
hasAdminAuthority: true,
projects: expect.arrayContaining([
{
projectId: projects[0].id
project: {
id: projects[0].id,
name: projects[0].name,
slug: projects[0].slug
}
},
{
projectId: projects[1].id
project: {
id: projects[1].id,
name: projects[1].name,
slug: projects[1].slug
}
}
])
})
Expand Down
6 changes: 5 additions & 1 deletion apps/api/src/workspace-role/workspace-role.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import { Project, WorkspaceRole } from '@prisma/client'

export interface WorkspaceRoleWithProjects extends WorkspaceRole {
projects: {
projectId: Project['id']
project: {
id: Project['id']
name: Project['name']
slug: Project['slug']
}
}[]
}
6 changes: 5 additions & 1 deletion packages/api-client/src/types/workspace-role.types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ interface WorkspaceRole {
authorities: string[]
workspaceId: string
projects: {
projectId: string
project: {
id: string
name: string
slug: string
}[]
}[]
}

Expand Down
59 changes: 58 additions & 1 deletion packages/api-client/tests/workspace-role.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ describe('Workspace Role Controller Tests', () => {
const email = '[email protected]'
let workspaceSlug: string | null
let workspaceRoleSlug: string | null
let projectSlug: string | null

beforeAll(async () => {
// Create a workspace for the tests
Expand All @@ -24,9 +25,26 @@ describe('Workspace Role Controller Tests', () => {
).json()) as any

workspaceSlug = workspaceResponse.slug

// Create a project for the tests
const projectResponse = (await (
await client.post(
`/api/workspace/${workspaceSlug}/projects`,
{ name: 'My Project' },
{ 'x-e2e-user-email': email }
)
).json()) as any

projectSlug = projectResponse.slug
})

afterAll(async () => {
await client.delete(
`/api/workspace/${workspaceSlug}/projects/${projectSlug}`,
{
'x-e2e-user-email': email
}
)
// Delete the workspace after tests
await client.delete(`/api/workspace/${workspaceSlug}`, {
'x-e2e-user-email': email
Expand All @@ -41,7 +59,7 @@ describe('Workspace Role Controller Tests', () => {
description: 'Role for developers',
colorCode: '#FF0000',
authorities: ['READ_WORKSPACE', 'READ_PROJECT'],
projectSlugs: []
projectSlugs: [projectSlug!]
}

const createWorkspaceRoleResponse = (
Expand Down Expand Up @@ -177,4 +195,43 @@ describe('Workspace Role Controller Tests', () => {

expect(roleExists.exists).toBe(true)
})

it('should create a new workspace role with a project', async () => {
const createWorkspaceRoleRequest: CreateWorkspaceRoleRequest = {
workspaceSlug: workspaceSlug!,
name: 'ReadOnly',
description: 'Role with project access',
colorCode: '#0000FF',
authorities: ['READ_WORKSPACE'],
projectSlugs: [projectSlug!]
}

const createRoleResponse = (
await workspaceRoleController.createWorkspaceRole(
createWorkspaceRoleRequest,
{ 'x-e2e-user-email': email }
)
).data

expect(createRoleResponse.name).toBe('ReadOnly')
expect(createRoleResponse.projects[0].project[0].slug).toBe(projectSlug)

// Delete the newly created role
await workspaceRoleController.deleteWorkspaceRole(
{ workspaceRoleSlug: createRoleResponse.slug },
{ 'x-e2e-user-email': email }
)
})

it('should fetch a workspace role with its assigned project', async () => {
const role = (
await workspaceRoleController.getWorkspaceRole(
{ workspaceRoleSlug: workspaceRoleSlug! },
{ 'x-e2e-user-email': email }
)
).data

expect(role.slug).toBe(workspaceRoleSlug)
expect(role.projects[0].project[0].slug).toBe(projectSlug)
})
})
Loading