diff --git a/me.go b/me.go index 75ffd39..e76f8c5 100644 --- a/me.go +++ b/me.go @@ -19,35 +19,29 @@ type ( User struct { Auth []string `json:"auth,omitempty"` City *string `json:"city,omitempty"` - Country string `json:"country,omitempty"` - CreateTime string `json:"create_time,omitempty"` + Country *string `json:"country,omitempty"` + CreateTime *string `json:"create_time,omitempty"` Department *string `json:"department,omitempty"` - Features Features `json:"features,omitempty"` - Intercom Intercom `json:"intercom,omitempty"` - Invitations []interface{} `json:"invitations,omitempty"` + Features map[string]any `json:"features,omitempty"` + Intercom Intercom `json:"intercom"` + Invitations []interface{} `json:"invitations"` JobTitle *string `json:"job_title,omitempty"` - ManagedBySCIM bool `json:"managed_by_scim,omitempty"` + ManagedBySCIM *bool `json:"managed_by_scim,omitempty"` ManagingOrganizationID *string `json:"managing_organization_id,omitempty"` ProjectMembership map[string]interface{} `json:"project_membership,omitempty"` ProjectMemberships map[string]interface{} `json:"project_memberships,omitempty"` - Projects []interface{} `json:"projects,omitempty"` - RealName string `json:"real_name,omitempty"` - State string `json:"state,omitempty"` + Projects []string `json:"projects"` + RealName *string `json:"real_name"` + State *string `json:"state"` TokenValidityBegin *string `json:"token_validity_begin,omitempty"` - User string `json:"user,omitempty"` - UserID string `json:"user_id,omitempty"` + User *string `json:"user"` + UserID *string `json:"user_id"` ViewedIndicators []string `json:"viewed_indicators,omitempty"` } - Features struct { - FreeTierEnabled bool `json:"free_tier_enabled,omitempty"` - ReferralEnabled bool `json:"referral_enabled,omitempty"` - ShowConfigDetailsStep bool `json:"show_config_details_step,omitempty"` - } - Intercom struct { - AppID string `json:"app_id,omitempty"` - HMAC string `json:"hmac,omitempty"` + AppID string `json:"app_id"` + HMAC string `json:"hmac"` } ) diff --git a/me_test.go b/me_test.go deleted file mode 100644 index c105642..0000000 --- a/me_test.go +++ /dev/null @@ -1,155 +0,0 @@ -package aiven - -import ( - "context" - "encoding/json" - "net/http" - "net/http/httptest" - "reflect" - - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" -) - -var _ = Describe("UserProfileHandler", func() { - var ( - client *Client - tearDown func() - ctx context.Context - handler *UserProfileHandler - ) - - BeforeEach(func() { - client, tearDown = setupUserProfileHandlerTestCase() - ctx = context.Background() - handler = &UserProfileHandler{client: client} - }) - - AfterEach(func() { - tearDown() - }) - - Context("Me", func() { - It("should return the current user's profile", func() { - expectedUser := &User{ - Auth: []string{"auth1", "auth2"}, - City: ptrToString("Helsinki"), - Country: "FI", - CreateTime: "2022-01-01T00:00:00Z", - Department: ptrToString("Engineering"), - Features: Features{FreeTierEnabled: true, ReferralEnabled: true, ShowConfigDetailsStep: true}, - Intercom: Intercom{AppID: "app_id", HMAC: "hmac_value"}, - Invitations: []interface{}{}, - JobTitle: ptrToString("Software Engineer"), - ManagedBySCIM: true, - ManagingOrganizationID: ptrToString("org_id"), - ProjectMembership: map[string]interface{}{"project1": "admin"}, - ProjectMemberships: map[string]interface{}{"project1": "admin"}, - Projects: []interface{}{"project1"}, - RealName: "John Doe", - State: "active", - TokenValidityBegin: ptrToString("2022-01-01T00:00:00Z"), - User: "john.doe", - UserID: "user_id", - ViewedIndicators: []string{"indicator1", "indicator2"}, - } - - user, err := handler.Me(ctx) - Expect(err).NotTo(HaveOccurred()) - Expect(compareUsers(user, expectedUser)).To(BeTrue()) - }) - }) -}) - -func setupUserProfileHandlerTestCase() (*Client, func()) { - const ( - UserName = "test@aiven.io" - UserPassword = "testabcd" - AccessToken = "some-random-token" - ) - - // Mock server to simulate Aiven API responses - ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - if r.URL.Path == "/me" { - w.Header().Set("Content-Type", "application/json") - w.WriteHeader(http.StatusOK) - err := json.NewEncoder(w).Encode(CurrentUserProfileResponse{ - APIResponse: APIResponse{}, - User: User{ - Auth: []string{"auth1", "auth2"}, - City: ptrToString("Helsinki"), - Country: "FI", - CreateTime: "2022-01-01T00:00:00Z", - Department: ptrToString("Engineering"), - Features: Features{FreeTierEnabled: true, ReferralEnabled: true, ShowConfigDetailsStep: true}, - Intercom: Intercom{AppID: "app_id", HMAC: "hmac_value"}, - Invitations: []interface{}{}, - JobTitle: ptrToString("Software Engineer"), - ManagedBySCIM: true, - ManagingOrganizationID: ptrToString("org_id"), - ProjectMembership: map[string]interface{}{"project1": "admin"}, - ProjectMemberships: map[string]interface{}{"project1": "admin"}, - Projects: []interface{}{"project1"}, - RealName: "John Doe", - State: "active", - TokenValidityBegin: ptrToString("2022-01-01T00:00:00Z"), - User: "john.doe", - UserID: "user_id", - ViewedIndicators: []string{"indicator1", "indicator2"}, - }, - }) - - if err != nil { - w.WriteHeader(http.StatusInternalServerError) - } - return - } - })) - - apiUrl = ts.URL - c, err := NewUserClient(UserName, UserPassword, "aiven-go-client-test/"+Version()) - if err != nil { - Fail("user authentication error: " + err.Error()) - } - - return c, func() { - ts.Close() - } -} - -func ptrToString(s string) *string { - return &s -} - -func derefStringPtr(ptr *string) string { - if ptr != nil { - return *ptr - } - return "" -} - -func compareUsers(got, want *User) bool { - if !reflect.DeepEqual(got.Auth, want.Auth) || - derefStringPtr(got.City) != derefStringPtr(want.City) || - got.Country != want.Country || - got.CreateTime != want.CreateTime || - derefStringPtr(got.Department) != derefStringPtr(want.Department) || - !reflect.DeepEqual(got.Features, want.Features) || - !reflect.DeepEqual(got.Intercom, want.Intercom) || - !reflect.DeepEqual(got.Invitations, want.Invitations) || - derefStringPtr(got.JobTitle) != derefStringPtr(want.JobTitle) || - got.ManagedBySCIM != want.ManagedBySCIM || - derefStringPtr(got.ManagingOrganizationID) != derefStringPtr(want.ManagingOrganizationID) || - !reflect.DeepEqual(got.ProjectMembership, want.ProjectMembership) || - !reflect.DeepEqual(got.ProjectMemberships, want.ProjectMemberships) || - !reflect.DeepEqual(got.Projects, want.Projects) || - got.RealName != want.RealName || - got.State != want.State || - derefStringPtr(got.TokenValidityBegin) != derefStringPtr(want.TokenValidityBegin) || - got.User != want.User || - got.UserID != want.UserID || - !reflect.DeepEqual(got.ViewedIndicators, want.ViewedIndicators) { - return false - } - return true -}