Verified Commit 515323de authored by Zubeen's avatar Zubeen 🤖 Committed by GitLab
Browse files

feat(users): add profile fields to the User struct

Changelog: Improvements
parent 4075b0f3
Loading
Loading
Loading
Loading
+2
Changes for enterprise_users_test.go: 2 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ func TestEnterpriseUsers_ListEnterpriseUsers(t *testing.T) {
			TwoFactorEnabled:      false,
			External:              false,
			PrivateProfile:        false,
			CommitEmail:           "user22@example.org",
		},
	}

@@ -143,6 +144,7 @@ func TestEnterpriseUsers_GetEnterpriseUser(t *testing.T) {
		TwoFactorEnabled: false,
		External:         false,
		PrivateProfile:   false,
		CommitEmail:      "user22@example.org",
	}

	user, resp, err := client.EnterpriseUsers.GetEnterpriseUser(1, 66)
+13
Changes for testdata/get_user_profile_fields.json: 13 added lines, 0 removed lines.
Original line number Diff line number Diff line
{
  "id": 1,
  "username": "john_smith",
  "name": "John Smith",
  "state": "active",
  "discord": "john#1234",
  "github": "john-smith",
  "pronouns": "he/him",
  "work_information": "Operations Specialist at Smith Inc",
  "local_time": "3:38 PM",
  "commit_email": "john@users.noreply.example.com",
  "preferred_language": "en"
}
+7
Changes for users.go: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -425,9 +425,14 @@ type User struct {
	Skype                          string             `json:"skype"`
	Linkedin                       string             `json:"linkedin"`
	Twitter                        string             `json:"twitter"`
	Discord                        string             `json:"discord"`
	WebsiteURL                     string             `json:"website_url"`
	Github                         string             `json:"github"`
	Organization                   string             `json:"organization"`
	JobTitle                       string             `json:"job_title"`
	Pronouns                       string             `json:"pronouns"`
	WorkInformation                string             `json:"work_information"`
	LocalTime                      string             `json:"local_time"`
	ExternUID                      string             `json:"extern_uid"`
	Provider                       string             `json:"provider"`
	ThemeID                        int64              `json:"theme_id"`
@@ -451,6 +456,8 @@ type User struct {
	SCIMIdentities                 []*SCIMIdentity    `json:"scim_identities"`
	External                       bool               `json:"external"`
	PrivateProfile                 bool               `json:"private_profile"`
	CommitEmail                    string             `json:"commit_email"`
	PreferredLanguage              string             `json:"preferred_language"`
	SharedRunnersMinutesLimit      int64              `json:"shared_runners_minutes_limit"`
	ExtraSharedRunnersMinutesLimit int64              `json:"extra_shared_runners_minutes_limit"`
	UsingLicenseSeat               bool               `json:"using_license_seat"`
+33
Changes for users_test.go: 33 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -156,6 +156,7 @@ func TestGetUserAdmin(t *testing.T) {
		LastSignInIP:     &lastSignInIP,
		ConfirmedAt:      new(time.Date(2012, time.May, 23, 9, 5, 22, 0, time.UTC)),
		TwoFactorEnabled: true,
		CommitEmail:      "john-codes@example.com",
		Note:             "DMCA Request: 2018-11-05 | DMCA Violation | Abuse | https://gitlab.zendesk.com/agent/tickets/123",
		Identities:       []*UserIdentity{{Provider: "github", ExternUID: "2435223452345"}},
		SCIMIdentities:   []*SCIMIdentity{{ExternUID: "be20d8dcc028677c931e04f387", GroupID: 1, Active: true}},
@@ -190,6 +191,7 @@ func TestCreatedBy(t *testing.T) {
		CreatedAt:   new(time.Date(2012, time.May, 23, 8, 0, 58, 0, time.UTC)),
		Bot:         true,
		PublicEmail: "john@example.com",
		CommitEmail: "project_1_bot_3cca1d029554e372cf8f39df76bf507d@example.com",
		// Bio:          "Bio of John Smith",
		// Location:     "USA",
		// Skype:        "john_smith",
@@ -746,6 +748,37 @@ func TestDisableUser2FA(t *testing.T) {
	assert.NotNil(t, resp)
}

func TestGetUser_ProfileFields(t *testing.T) {
	t.Parallel()
	mux, client := setup(t)

	// GIVEN a server returning a user with the profile fields
	mux.HandleFunc("/api/v4/users/1", func(w http.ResponseWriter, r *http.Request) {
		testMethod(t, r, http.MethodGet)
		mustWriteHTTPResponse(t, w, "testdata/get_user_profile_fields.json")
	})

	// WHEN getting the user
	user, _, err := client.Users.GetUser(1, &GetUserOptions{})

	// THEN the profile fields are decoded
	assert.NoError(t, err)
	want := &User{
		ID:                1,
		Username:          "john_smith",
		Name:              "John Smith",
		State:             "active",
		Discord:           "john#1234",
		Github:            "john-smith",
		Pronouns:          "he/him",
		WorkInformation:   "Operations Specialist at Smith Inc",
		LocalTime:         "3:38 PM",
		CommitEmail:       "john@users.noreply.example.com",
		PreferredLanguage: "en",
	}
	assert.Equal(t, want, user)
}

func TestGetSSHKey_LastUsedAt(t *testing.T) {
	t.Parallel()
	mux, client := setup(t)