Skip to content

Commit

Permalink
fix: return workspace name for breadcrumb in Project Details page (#9564
Browse files Browse the repository at this point in the history
)

(cherry picked from commit 2331e5b)
  • Loading branch information
AmanuelAaron authored and keita-determined committed Jun 25, 2024
1 parent 8da67d2 commit ead2232
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
62 changes: 62 additions & 0 deletions master/internal/api_project_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -641,3 +641,65 @@ func TestPatchProjectWithConcurrent(t *testing.T) {
}
require.NoError(t, errgrp.Wait())
}

func TestPatchProjectWithInvalidProjectKey(t *testing.T) {
api, _, ctx := setupAPITest(t, nil)
wresp, werr := api.PostWorkspace(ctx, &apiv1.PostWorkspaceRequest{Name: uuid.New().String()})
require.NoError(t, werr)

projectName := "test-project" + uuid.New().String()
resp, err := api.PostProject(ctx, &apiv1.PostProjectRequest{
Name: projectName, WorkspaceId: wresp.Workspace.Id,
})
require.NoError(t, err)

type TestCase struct {
Description string
Key string
Err string
}
testCases := []TestCase{
{
Description: "empty key",
Key: "",
Err: "project key cannot be empty",
},
{
Description: "key with special characters",
Key: "!@#$%",
Err: "project key can only contain alphanumeric characters",
},
}

for _, tc := range testCases {
t.Run(tc.Description, func(t *testing.T) {
_, err := api.PatchProject(ctx, &apiv1.PatchProjectRequest{
Id: resp.Project.Id,
Project: &projectv1.PatchProject{
Key: wrapperspb.String(tc.Key),
},
})
require.Error(t, err)
require.ErrorContains(t, err, tc.Err)
})
}
}

func TestGetProjectByID(t *testing.T) {
api, curUser, ctx := setupAPITest(t, nil)
wresp, werr := api.PostWorkspace(ctx, &apiv1.PostWorkspaceRequest{Name: uuid.New().String()})
require.NoError(t, werr)

projectName := "test-project" + uuid.New().String()
resp, err := api.PostProject(ctx, &apiv1.PostProjectRequest{
Name: projectName, WorkspaceId: wresp.Workspace.Id,
})
require.NoError(t, err)

project, err := api.GetProjectByID(ctx, resp.Project.Id, curUser)
require.NoError(t, err)
require.Equal(t, wresp.Workspace.Name, project.WorkspaceName)
require.Equal(t, wresp.Workspace.Id, project.WorkspaceId)
require.Equal(t, projectName, project.Name)
require.Equal(t, resp.Project.Id, project.Id)
}
1 change: 1 addition & 0 deletions master/internal/project/postgres_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ func getProjectColumns(q *bun.SelectQuery) *bun.SelectQuery {
ColumnExpr("(SELECT username FROM users WHERE id = p.user_id) AS username").
ColumnExpr("p.user_id").
ColumnExpr("p.key").
ColumnExpr("w.name as workspace_name").
Join("INNER JOIN workspaces w ON w.id = p.workspace_id")
}

Expand Down

0 comments on commit ead2232

Please sign in to comment.