Skip to content

Commit

Permalink
Use all attributes of the user model
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmoran committed Apr 2, 2015
1 parent 1425a8a commit 4773097
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 51 deletions.
65 changes: 41 additions & 24 deletions internal/fakes/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,22 @@ import (
)

type User struct {
ID string
UserName string
CreatedAt time.Time
UpdatedAt time.Time
Version int
Emails []string
Groups []Group
Active bool
Verified bool
Origin string
Password string
ID string
ExternalID string
UserName string
FormattedName string
FamilyName string
GivenName string
MiddleName string
CreatedAt time.Time
UpdatedAt time.Time
Version int
Emails []string
Groups []Group
Active bool
Verified bool
Origin string
Password string
}

func newUserFromCreateDocument(request documents.CreateUserRequest) User {
Expand Down Expand Up @@ -49,16 +54,21 @@ func newUserFromUpdateDocument(request documents.UpdateUserRequest) User {
}

return User{
ID: request.ID,
UserName: request.UserName,
CreatedAt: request.Meta.Created,
UpdatedAt: request.Meta.LastModified,
Version: request.Meta.Version,
Emails: emails,
Groups: make([]Group, 0),
Active: true,
Verified: false,
Origin: Origin,
ID: request.ID,
ExternalID: request.ExternalID,
UserName: request.UserName,
FormattedName: request.Name.Formatted,
FamilyName: request.Name.FamilyName,
GivenName: request.Name.GivenName,
MiddleName: request.Name.MiddleName,
CreatedAt: request.Meta.Created,
UpdatedAt: request.Meta.LastModified,
Version: request.Meta.Version,
Emails: emails,
Groups: make([]Group, 0),
Active: true,
Verified: false,
Origin: Origin,
}
}

Expand All @@ -76,9 +86,16 @@ func (u User) ToDocument() documents.UserResponse {
}

return documents.UserResponse{
Schemas: Schemas,
ID: u.ID,
UserName: u.UserName,
Schemas: Schemas,
ID: u.ID,
ExternalID: u.ExternalID,
UserName: u.UserName,
Name: documents.UserName{
Formatted: u.FormattedName,
FamilyName: u.FamilyName,
GivenName: u.GivenName,
MiddleName: u.MiddleName,
},
Meta: documents.Meta{
Version: u.Version,
Created: u.CreatedAt,
Expand Down
1 change: 0 additions & 1 deletion internal/network/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

// TODO: do not use os.Getenv

func (c Client) printRequest(request *http.Request) {
if os.Getenv("TRACE") != "" {
bodyCopy := bytes.NewBuffer([]byte{})
Expand Down
46 changes: 28 additions & 18 deletions user.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@ import (
)

type User struct {
ID string
UserName string
CreatedAt time.Time
UpdatedAt time.Time
Version int
Emails []string
Groups []Group
Active bool
Verified bool
Origin string
ID string
ExternalID string
UserName string
FormattedName string
FamilyName string
GivenName string
MiddleName string
CreatedAt time.Time
UpdatedAt time.Time
Version int
Emails []string
Groups []Group
Active bool
Verified bool
Origin string
}

func newUserFromResponse(config Config, response documents.UserResponse) User {
Expand All @@ -26,13 +31,18 @@ func newUserFromResponse(config Config, response documents.UserResponse) User {
}

return User{
ID: response.ID,
UserName: response.UserName,
Emails: emails,
CreatedAt: response.Meta.Created,
UpdatedAt: response.Meta.LastModified,
Active: response.Active,
Verified: response.Verified,
Origin: response.Origin,
ID: response.ID,
ExternalID: response.ExternalID,
UserName: response.UserName,
FormattedName: response.Name.Formatted,
FamilyName: response.Name.FamilyName,
GivenName: response.Name.GivenName,
MiddleName: response.Name.MiddleName,
Emails: emails,
CreatedAt: response.Meta.Created,
UpdatedAt: response.Meta.LastModified,
Active: response.Active,
Verified: response.Verified,
Origin: response.Origin,
}
}
16 changes: 8 additions & 8 deletions users_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,15 +197,15 @@ func newUpdateUserDocumentFromUser(user User) documents.UpdateUserRequest {
}

return documents.UpdateUserRequest{
Schemas: Schemas,
ID: user.ID,
UserName: user.UserName,
//ExternalID: user.ExternalID, // TODO
Schemas: Schemas,
ID: user.ID,
UserName: user.UserName,
ExternalID: user.ExternalID,
Name: documents.UserName{
//Formatted: user.FormattedName, // TODO
//FamilyName: user.FamilyName,
//GivenName: user.GivenName,
//MiddleName: user.MiddleName,
Formatted: user.FormattedName,
FamilyName: user.FamilyName,
GivenName: user.GivenName,
MiddleName: user.MiddleName,
},
Emails: emails,
Meta: documents.Meta{
Expand Down
25 changes: 25 additions & 0 deletions users_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ var _ = Describe("UsersService", func() {
Expect(user.Active).To(BeTrue())
Expect(user.Verified).To(BeFalse())
Expect(user.Origin).To(Equal("uaa"))
Expect(user.ExternalID).To(Equal(""))
Expect(user.FormattedName).To(Equal(""))
Expect(user.FamilyName).To(Equal(""))
Expect(user.GivenName).To(Equal(""))
Expect(user.MiddleName).To(Equal(""))

fetchedUser, err := service.Get(user.ID, token)
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -145,6 +150,26 @@ var _ = Describe("UsersService", func() {
Expect(fetchedUser).To(Equal(updatedUser))
})

It("allows fields to be updated", func() {
user.ExternalID = "external-id"
user.FormattedName = "James Tiberius Kirk"
user.FamilyName = "Kirk"
user.GivenName = "James"
user.MiddleName = "Tiberius"

updatedUser, err := service.Update(user, token)
Expect(err).NotTo(HaveOccurred())
Expect(updatedUser.ExternalID).To(Equal(user.ExternalID))
Expect(updatedUser.FormattedName).To(Equal(user.FormattedName))
Expect(updatedUser.FamilyName).To(Equal(user.FamilyName))
Expect(updatedUser.GivenName).To(Equal(user.GivenName))
Expect(updatedUser.MiddleName).To(Equal(user.MiddleName))

fetchedUser, err := service.Get(user.ID, token)
Expect(err).NotTo(HaveOccurred())
Expect(fetchedUser).To(Equal(updatedUser))
})

It("requires the scim.write scope", func() {
token = fakeUAAServer.ClientTokenFor("admin", []string{"scim.banana"}, []string{"scim"})
_, err := service.Update(user, token)
Expand Down

0 comments on commit 4773097

Please sign in to comment.