From 40470088cd569c87d8d21eff905b7c323a22c8cb Mon Sep 17 00:00:00 2001 From: NIL2000 Date: Sun, 15 Sep 2024 11:01:12 +0530 Subject: [PATCH 1/4] fix(API): Replace projectId with name and slug in workspace-role response --- .../service/workspace-role.service.ts | 28 +++++++++++++++++-- .../workspace-role/workspace-role.e2e.spec.ts | 16 ++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/apps/api/src/workspace-role/service/workspace-role.service.ts b/apps/api/src/workspace-role/service/workspace-role.service.ts index 2b5367b7..c8d3b610 100644 --- a/apps/api/src/workspace-role/service/workspace-role.service.ts +++ b/apps/api/src/workspace-role/service/workspace-role.service.ts @@ -97,7 +97,13 @@ export class WorkspaceRoleService { include: { projects: { select: { - projectId: true + projectId: true, + project: { + select: { + slug: true, + name: true + } + } } } } @@ -228,7 +234,13 @@ export class WorkspaceRoleService { include: { projects: { select: { - projectId: true + projectId: true, + project: { + select: { + slug: true, + name: true + } + } } } } @@ -443,7 +455,17 @@ export class WorkspaceRoleService { slug: workspaceRoleSlug }, include: { - projects: true + projects: { + select: { + projectId: true, + project: { + select: { + slug: true, + name: true + } + } + } + } } })) as WorkspaceRoleWithProjects diff --git a/apps/api/src/workspace-role/workspace-role.e2e.spec.ts b/apps/api/src/workspace-role/workspace-role.e2e.spec.ts index e3e89ef2..48651fb2 100644 --- a/apps/api/src/workspace-role/workspace-role.e2e.spec.ts +++ b/apps/api/src/workspace-role/workspace-role.e2e.spec.ts @@ -607,10 +607,14 @@ describe('Workspace Role Controller Tests', () => { updatedAt: expect.any(String), projects: expect.arrayContaining([ { - projectId: projects[0].id + projectId: projects[0].id, + slug: projects[0].slug, + name: projects[0].name }, { - projectId: projects[1].id + projectId: projects[1].id, + slug: projects[1].slug, + name: projects[1].name } ]) }) @@ -654,10 +658,14 @@ describe('Workspace Role Controller Tests', () => { hasAdminAuthority: true, projects: expect.arrayContaining([ { - projectId: projects[0].id + projectId: projects[0].id, + slug: projects[0].slug, + name: projects[0].name }, { - projectId: projects[1].id + projectId: projects[1].id, + slug: projects[1].slug, + name: projects[1].name } ]) }) From b563185661d214b7b6de4002c0a02f874a9d2e8e Mon Sep 17 00:00:00 2001 From: NIL2000 Date: Sun, 15 Sep 2024 11:01:12 +0530 Subject: [PATCH 2/4] fix(API): Replace projectId with name and slug in workspace-role response --- .../service/workspace-role.service.ts | 28 +++++++++++++++++-- .../workspace-role/workspace-role.e2e.spec.ts | 16 ++++++++--- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/apps/api/src/workspace-role/service/workspace-role.service.ts b/apps/api/src/workspace-role/service/workspace-role.service.ts index 2b5367b7..c8d3b610 100644 --- a/apps/api/src/workspace-role/service/workspace-role.service.ts +++ b/apps/api/src/workspace-role/service/workspace-role.service.ts @@ -97,7 +97,13 @@ export class WorkspaceRoleService { include: { projects: { select: { - projectId: true + projectId: true, + project: { + select: { + slug: true, + name: true + } + } } } } @@ -228,7 +234,13 @@ export class WorkspaceRoleService { include: { projects: { select: { - projectId: true + projectId: true, + project: { + select: { + slug: true, + name: true + } + } } } } @@ -443,7 +455,17 @@ export class WorkspaceRoleService { slug: workspaceRoleSlug }, include: { - projects: true + projects: { + select: { + projectId: true, + project: { + select: { + slug: true, + name: true + } + } + } + } } })) as WorkspaceRoleWithProjects diff --git a/apps/api/src/workspace-role/workspace-role.e2e.spec.ts b/apps/api/src/workspace-role/workspace-role.e2e.spec.ts index e3e89ef2..48651fb2 100644 --- a/apps/api/src/workspace-role/workspace-role.e2e.spec.ts +++ b/apps/api/src/workspace-role/workspace-role.e2e.spec.ts @@ -607,10 +607,14 @@ describe('Workspace Role Controller Tests', () => { updatedAt: expect.any(String), projects: expect.arrayContaining([ { - projectId: projects[0].id + projectId: projects[0].id, + slug: projects[0].slug, + name: projects[0].name }, { - projectId: projects[1].id + projectId: projects[1].id, + slug: projects[1].slug, + name: projects[1].name } ]) }) @@ -654,10 +658,14 @@ describe('Workspace Role Controller Tests', () => { hasAdminAuthority: true, projects: expect.arrayContaining([ { - projectId: projects[0].id + projectId: projects[0].id, + slug: projects[0].slug, + name: projects[0].name }, { - projectId: projects[1].id + projectId: projects[1].id, + slug: projects[1].slug, + name: projects[1].name } ]) }) From 4ef78702729a131a9abd2db0188be67113b87dd1 Mon Sep 17 00:00:00 2001 From: NIL2000 Date: Sun, 15 Sep 2024 12:15:53 +0530 Subject: [PATCH 3/4] Updated changes --- .../service/workspace-role.service.ts | 6 ++-- .../workspace-role/workspace-role.e2e.spec.ts | 32 ++++++++++++------- .../workspace-role/workspace-role.types.ts | 6 +++- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/apps/api/src/workspace-role/service/workspace-role.service.ts b/apps/api/src/workspace-role/service/workspace-role.service.ts index c8d3b610..1f58a091 100644 --- a/apps/api/src/workspace-role/service/workspace-role.service.ts +++ b/apps/api/src/workspace-role/service/workspace-role.service.ts @@ -97,9 +97,9 @@ export class WorkspaceRoleService { include: { projects: { select: { - projectId: true, project: { select: { + id: true, slug: true, name: true } @@ -234,9 +234,9 @@ export class WorkspaceRoleService { include: { projects: { select: { - projectId: true, project: { select: { + id: true, slug: true, name: true } @@ -457,9 +457,9 @@ export class WorkspaceRoleService { include: { projects: { select: { - projectId: true, project: { select: { + id: true, slug: true, name: true } diff --git a/apps/api/src/workspace-role/workspace-role.e2e.spec.ts b/apps/api/src/workspace-role/workspace-role.e2e.spec.ts index 48651fb2..3ca44d07 100644 --- a/apps/api/src/workspace-role/workspace-role.e2e.spec.ts +++ b/apps/api/src/workspace-role/workspace-role.e2e.spec.ts @@ -607,14 +607,18 @@ describe('Workspace Role Controller Tests', () => { updatedAt: expect.any(String), projects: expect.arrayContaining([ { - projectId: projects[0].id, - slug: projects[0].slug, - name: projects[0].name + project: { + id: projects[0].id, + name: projects[0].name, + slug: projects[0].slug + } }, { - projectId: projects[1].id, - slug: projects[1].slug, - name: projects[1].name + project: { + id: projects[1].id, + name: projects[1].name, + slug: projects[1].slug + } } ]) }) @@ -658,14 +662,18 @@ describe('Workspace Role Controller Tests', () => { hasAdminAuthority: true, projects: expect.arrayContaining([ { - projectId: projects[0].id, - slug: projects[0].slug, - name: projects[0].name + project: { + id: projects[0].id, + name: projects[0].name, + slug: projects[0].slug + } }, { - projectId: projects[1].id, - slug: projects[1].slug, - name: projects[1].name + project: { + id: projects[1].id, + name: projects[1].name, + slug: projects[1].slug + } } ]) }) diff --git a/apps/api/src/workspace-role/workspace-role.types.ts b/apps/api/src/workspace-role/workspace-role.types.ts index a0f2eab5..3b879760 100644 --- a/apps/api/src/workspace-role/workspace-role.types.ts +++ b/apps/api/src/workspace-role/workspace-role.types.ts @@ -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'] + } }[] } From 3323adaddde762822947b85b6abd4f4cbefb33ee Mon Sep 17 00:00:00 2001 From: NIL2000 Date: Mon, 16 Sep 2024 22:27:39 +0530 Subject: [PATCH 4/4] Changed api-client package and added test to support the changes --- .../src/types/workspace-role.types.d.ts | 6 +- .../api-client/tests/workspace-role.spec.ts | 59 ++++++++++++++++++- 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/packages/api-client/src/types/workspace-role.types.d.ts b/packages/api-client/src/types/workspace-role.types.d.ts index 7547ec17..47116229 100644 --- a/packages/api-client/src/types/workspace-role.types.d.ts +++ b/packages/api-client/src/types/workspace-role.types.d.ts @@ -12,7 +12,11 @@ interface WorkspaceRole { authorities: string[] workspaceId: string projects: { - projectId: string + project: { + id: string + name: string + slug: string + }[] }[] } diff --git a/packages/api-client/tests/workspace-role.spec.ts b/packages/api-client/tests/workspace-role.spec.ts index aa8a40d6..6469e58c 100644 --- a/packages/api-client/tests/workspace-role.spec.ts +++ b/packages/api-client/tests/workspace-role.spec.ts @@ -12,6 +12,7 @@ describe('Workspace Role Controller Tests', () => { const email = 'johndoe@example.com' let workspaceSlug: string | null let workspaceRoleSlug: string | null + let projectSlug: string | null beforeAll(async () => { // Create a workspace for the tests @@ -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 @@ -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 = ( @@ -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) + }) })