-
Notifications
You must be signed in to change notification settings - Fork 713
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: adding user RoleAdmin ability to fetch user with projects (#4409)
Signed-off-by: William Johnson dos Santos Okano <[email protected]> Co-authored-by: Saranya Jena <[email protected]> Co-authored-by: Sarthak Jain <[email protected]>
- Loading branch information
1 parent
b2147c5
commit 84b76bd
Showing
2 changed files
with
32 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,7 @@ func TestGetUserWithProject(t *testing.T) { | |
{"username", username}, | ||
} | ||
c.Set("username", username) | ||
c.Set("role", string(entities.RoleUser)) | ||
|
||
user := &entities.User{ | ||
ID: "testUID", | ||
|
@@ -52,6 +53,7 @@ func TestGetUserWithProject(t *testing.T) { | |
{"username", username}, | ||
} | ||
c.Set("username", username) | ||
c.Set("role", string(entities.RoleUser)) | ||
|
||
user := &entities.User{ | ||
ID: "testUID", | ||
|
@@ -68,6 +70,32 @@ func TestGetUserWithProject(t *testing.T) { | |
assert.Equal(t, http.StatusOK, f.Code) | ||
}) | ||
|
||
t.Run("Successfully retrieve user with projects if logged user has admin role", func(t *testing.T) { | ||
service := new(mocks.MockedApplicationService) | ||
username := "testUser" | ||
w := httptest.NewRecorder() | ||
c := GetTestGinContext(w) | ||
c.Params = gin.Params{ | ||
{"username", username}, | ||
} | ||
c.Set("username", "adminusername") | ||
c.Set("role", string(entities.RoleAdmin)) | ||
|
||
user := &entities.User{ | ||
ID: "testUID", | ||
Username: "testUser", | ||
Email: "[email protected]", | ||
Role: entities.RoleAdmin, | ||
} | ||
project := &entities.Project{} | ||
|
||
service.On("FindUserByUsername", "testUser").Return(user, nil) | ||
service.On("GetProjectsByUserID", "testUID", false).Return([]*entities.Project{project}, nil) | ||
|
||
rest.GetUserWithProject(service)(c) | ||
|
||
assert.Equal(t, http.StatusOK, w.Code) | ||
}) | ||
} | ||
|
||
func TestGetProjectsByUserID(t *testing.T) { | ||
|