Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
wxiaoguang committed Sep 22, 2021
1 parent cc8a453 commit c258ca3
Show file tree
Hide file tree
Showing 10 changed files with 17 additions and 16 deletions.
4 changes: 2 additions & 2 deletions integrations/api_user_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestUserOrgs(t *testing.T) {
ID: 3,
UserName: user3.Name,
FullName: user3.FullName,
AvatarURL: user3.AvatarLinkDefaultSize(),
AvatarURL: user3.AvatarLink(),
Description: "",
Website: "",
Location: "",
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestMyOrgs(t *testing.T) {
ID: 3,
UserName: user3.Name,
FullName: user3.FullName,
AvatarURL: user3.AvatarLinkDefaultSize(),
AvatarURL: user3.AvatarLink(),
Description: "",
Website: "",
Location: "",
Expand Down
2 changes: 1 addition & 1 deletion integrations/user_avatar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestUserAvatar(t *testing.T) {

user2 = db.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of the repo3, is an org

req = NewRequest(t, "GET", user2.AvatarLinkDefaultSize())
req = NewRequest(t, "GET", user2.AvatarLink())
resp := session.MakeRequest(t, req, http.StatusFound)
location := resp.Header().Get("Location")
if !strings.HasPrefix(location, "/avatars") {
Expand Down
7 changes: 4 additions & 3 deletions models/avatars/avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,11 +154,12 @@ func generateEmailAvatarLink(email string, size int, final bool) string {
return DefaultAvatarLink()
}

avatarURL.Query().Set("d", "identicon")
urlQuery := avatarURL.Query()
urlQuery.Set("d", "identicon")
if size > 0 {
avatarURL.Query().Set("s", strconv.Itoa(size))
urlQuery.Set("s", strconv.Itoa(size))
}
avatarURL.RawQuery = avatarURL.Query().Encode()
avatarURL.RawQuery = urlQuery.Encode()
return avatarURL.String()
}

Expand Down
4 changes: 2 additions & 2 deletions models/repo_activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int)
}
users := make(map[int64]*ActivityAuthorData)
var unknownUserID int64
unknownUserAvatarLink := NewGhostUser().AvatarLinkDefaultSize()
unknownUserAvatarLink := NewGhostUser().AvatarLink()
for _, v := range code.Authors {
if len(v.Email) == 0 {
continue
Expand All @@ -116,7 +116,7 @@ func GetActivityStatsTopAuthors(repo *Repository, timeFrom time.Time, count int)
users[u.ID] = &ActivityAuthorData{
Name: u.DisplayName(),
Login: u.LowerName,
AvatarLink: u.AvatarLinkDefaultSize(),
AvatarLink: u.AvatarLink(),
HomeLink: u.HomeLink(),
Commits: v.Commits,
}
Expand Down
4 changes: 2 additions & 2 deletions models/user_avatar.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ func (u *User) AvatarLinkWithSize(size int) string {
return avatars.GenerateEmailAvatarFastLink(u.AvatarEmail, size)
}

// AvatarLinkDefaultSize returns a avatar link with default size
func (u *User) AvatarLinkDefaultSize() string {
// AvatarLink returns a avatar link with default size
func (u *User) AvatarLink() string {
return u.AvatarLinkWithSize(avatars.DefaultAvatarSize)
}

Expand Down
2 changes: 1 addition & 1 deletion modules/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
func ToOrganization(org *models.User) *api.Organization {
return &api.Organization{
ID: org.ID,
AvatarURL: org.AvatarLinkDefaultSize(),
AvatarURL: org.AvatarLink(),
UserName: org.Name,
FullName: org.FullName,
Description: org.Description,
Expand Down
2 changes: 1 addition & 1 deletion modules/convert/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func toUser(user *models.User, signed, authed bool) *api.User {
UserName: user.Name,
FullName: markup.Sanitize(user.FullName),
Email: user.GetEmail(),
AvatarURL: user.AvatarLinkDefaultSize(),
AvatarURL: user.AvatarLink(),
Created: user.CreatedUnix.AsTime(),
Restricted: user.IsRestricted,
Location: user.Location,
Expand Down
2 changes: 1 addition & 1 deletion routers/web/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -2606,5 +2606,5 @@ func handleTeamMentions(ctx *context.Context) {

ctx.Data["MentionableTeams"] = ctx.Repo.Owner.Teams
ctx.Data["MentionableTeamsOrg"] = ctx.Repo.Owner.Name
ctx.Data["MentionableTeamsOrgAvatar"] = ctx.Repo.Owner.AvatarLinkDefaultSize()
ctx.Data["MentionableTeamsOrgAvatar"] = ctx.Repo.Owner.AvatarLink()
}
4 changes: 2 additions & 2 deletions routers/web/user/oauth.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ func newAccessTokenResponse(grant *models.OAuth2Grant, serverKey, clientKey oaut
idToken.Name = user.FullName
idToken.PreferredUsername = user.Name
idToken.Profile = user.HTMLURL()
idToken.Picture = user.AvatarLinkDefaultSize()
idToken.Picture = user.AvatarLink()
idToken.Website = user.Website
idToken.Locale = user.Language
idToken.UpdatedAt = user.UpdatedUnix
Expand Down Expand Up @@ -245,7 +245,7 @@ func InfoOAuth(ctx *context.Context) {
Name: ctx.User.FullName,
Username: ctx.User.Name,
Email: ctx.User.Email,
Picture: ctx.User.AvatarLinkDefaultSize(),
Picture: ctx.User.AvatarLink(),
}
ctx.JSON(http.StatusOK, response)
}
Expand Down
2 changes: 1 addition & 1 deletion routers/web/user/oauth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestNewAccessTokenResponse_OIDCToken(t *testing.T) {
assert.Equal(t, user.FullName, oidcToken.Name)
assert.Equal(t, user.Name, oidcToken.PreferredUsername)
assert.Equal(t, user.HTMLURL(), oidcToken.Profile)
assert.Equal(t, user.AvatarLinkDefaultSize(), oidcToken.Picture)
assert.Equal(t, user.AvatarLink(), oidcToken.Picture)
assert.Equal(t, user.Website, oidcToken.Website)
assert.Equal(t, user.UpdatedUnix, oidcToken.UpdatedAt)
assert.Equal(t, user.Email, oidcToken.Email)
Expand Down

0 comments on commit c258ca3

Please sign in to comment.