mirror of
https://github.com/gfleury/go-bitbucket-v1.git
synced 2025-05-20 20:24:34 -05:00
Merge pull request #53 from gfleury/GetUsersResponse
Adding GetUsersReponse and modifying Users structure from Email to Em…
This commit is contained in:
commit
e4c8a88c87
@ -80,7 +80,7 @@ type UserWithNameEmail struct {
|
|||||||
|
|
||||||
type UserWithLinks struct {
|
type UserWithLinks struct {
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
Email string `json:"emailAddress,omitempty"`
|
EmailAddress string `json:"emailAddress,omitempty"`
|
||||||
ID int `json:"id,omitempty"`
|
ID int `json:"id,omitempty"`
|
||||||
DisplayName string `json:"displayName,omitempty"`
|
DisplayName string `json:"displayName,omitempty"`
|
||||||
Active bool `json:"active,omitempty"`
|
Active bool `json:"active,omitempty"`
|
||||||
@ -91,12 +91,17 @@ type UserWithLinks struct {
|
|||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Email string `json:"emailAddress"`
|
EmailAddress string `json:"emailAddress"`
|
||||||
ID int `json:"id"`
|
ID int `json:"id"`
|
||||||
DisplayName string `json:"displayName"`
|
DisplayName string `json:"displayName"`
|
||||||
Active bool `json:"active"`
|
Active bool `json:"active"`
|
||||||
Slug string `json:"slug"`
|
Slug string `json:"slug"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
|
DirectoryName string `json:"directoryName"`
|
||||||
|
Deletable bool `json:"deletable"`
|
||||||
|
LastAuthenticationTimestamp int64 `json:"lastAuthenticationTimestamp"`
|
||||||
|
MutableDetails bool `json:"mutableDetails"`
|
||||||
|
MutableGroups bool `json:"mutableGroups"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserWithMetadata struct {
|
type UserWithMetadata struct {
|
||||||
@ -464,6 +469,13 @@ func GetContentResponse(r *APIResponse) (Content, error) {
|
|||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetUsersResponse casts users into structure
|
||||||
|
func GetUsersResponse(r *APIResponse) ([]User, error) {
|
||||||
|
var c []User
|
||||||
|
err := mapstructure.Decode(r.Values["values"], &c)
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
|
|
||||||
// GetUsersPermissionResponse casts user permissions into structure
|
// GetUsersPermissionResponse casts user permissions into structure
|
||||||
func GetUsersPermissionResponse(r *APIResponse) ([]UserPermission, error) {
|
func GetUsersPermissionResponse(r *APIResponse) ([]UserPermission, error) {
|
||||||
var c []UserPermission
|
var c []UserPermission
|
||||||
|
@ -431,7 +431,7 @@ func TestGetPullRequestResponse(t *testing.T) {
|
|||||||
Author: &UserWithMetadata{
|
Author: &UserWithMetadata{
|
||||||
User: UserWithLinks{
|
User: UserWithLinks{
|
||||||
Name: "tom",
|
Name: "tom",
|
||||||
// Email: "tom@example.com",
|
EmailAddress: "tom@example.com",
|
||||||
ID: 115026,
|
ID: 115026,
|
||||||
DisplayName: "Tom",
|
DisplayName: "Tom",
|
||||||
Active: true,
|
Active: true,
|
||||||
@ -446,7 +446,7 @@ func TestGetPullRequestResponse(t *testing.T) {
|
|||||||
{
|
{
|
||||||
User: UserWithLinks{
|
User: UserWithLinks{
|
||||||
Name: "jcitizen",
|
Name: "jcitizen",
|
||||||
// Email: "jane@example.com",
|
EmailAddress: "jane@example.com",
|
||||||
ID: 101,
|
ID: 101,
|
||||||
DisplayName: "Jane Citizen",
|
DisplayName: "Jane Citizen",
|
||||||
Active: true,
|
Active: true,
|
||||||
@ -462,7 +462,7 @@ func TestGetPullRequestResponse(t *testing.T) {
|
|||||||
{
|
{
|
||||||
User: UserWithLinks{
|
User: UserWithLinks{
|
||||||
Name: "dick",
|
Name: "dick",
|
||||||
// Email: "dick@example.com",
|
EmailAddress: "dick@example.com",
|
||||||
ID: 3083181,
|
ID: 3083181,
|
||||||
DisplayName: "Dick",
|
DisplayName: "Dick",
|
||||||
Active: true,
|
Active: true,
|
||||||
@ -476,7 +476,7 @@ func TestGetPullRequestResponse(t *testing.T) {
|
|||||||
{
|
{
|
||||||
User: UserWithLinks{
|
User: UserWithLinks{
|
||||||
Name: "harry",
|
Name: "harry",
|
||||||
// Email: "harry@example.com",
|
EmailAddress: "harry@example.com",
|
||||||
ID: 99049120,
|
ID: 99049120,
|
||||||
DisplayName: "Harry",
|
DisplayName: "Harry",
|
||||||
Active: true,
|
Active: true,
|
||||||
@ -688,10 +688,7 @@ func TestGetUsersPermissionResponse(t *testing.T) {
|
|||||||
"values": []interface{}{map[string]interface{}{
|
"values": []interface{}{map[string]interface{}{
|
||||||
"user": map[string]interface{}{
|
"user": map[string]interface{}{
|
||||||
"name": "jcitizen",
|
"name": "jcitizen",
|
||||||
// TODO: This field should be emailAddress according to the REST API
|
"emailAddress": "jane@example.com",
|
||||||
// documentation, but is defined as Email in the User struct. Mapstruct #
|
|
||||||
// therefore only decodes this when reffered to as 'email', which is plain wrong.
|
|
||||||
// "email": "jane@example.com",
|
|
||||||
"id": 101,
|
"id": 101,
|
||||||
"displayName": "Jane Citizen",
|
"displayName": "Jane Citizen",
|
||||||
"active": true,
|
"active": true,
|
||||||
@ -707,7 +704,7 @@ func TestGetUsersPermissionResponse(t *testing.T) {
|
|||||||
UserPermission{
|
UserPermission{
|
||||||
User: User{
|
User: User{
|
||||||
Name: "jcitizen",
|
Name: "jcitizen",
|
||||||
// Email: "jane@example.com",
|
EmailAddress: "jane@example.com",
|
||||||
ID: 101,
|
ID: 101,
|
||||||
DisplayName: "Jane Citizen",
|
DisplayName: "Jane Citizen",
|
||||||
Active: true,
|
Active: true,
|
||||||
@ -734,6 +731,93 @@ func TestGetUsersPermissionResponse(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetUsersResponse(t *testing.T) {
|
||||||
|
type args struct {
|
||||||
|
r *APIResponse
|
||||||
|
}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
args args
|
||||||
|
want []User
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Empty list",
|
||||||
|
args: args{
|
||||||
|
r: &APIResponse{
|
||||||
|
Values: map[string]interface{}{"values": []interface{}{}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: nil,
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Bad response",
|
||||||
|
args: args{
|
||||||
|
r: &APIResponse{
|
||||||
|
Values: map[string]interface{}{"values": "not an array"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: nil,
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Single group permission",
|
||||||
|
args: args{
|
||||||
|
r: &APIResponse{
|
||||||
|
Values: map[string]interface{}{
|
||||||
|
"values": []interface{}{
|
||||||
|
map[string]interface{}{
|
||||||
|
"name": "jcitizen",
|
||||||
|
"emailAddress": "jane@example.com",
|
||||||
|
"id": 101,
|
||||||
|
"displayName": "Jane Citizen",
|
||||||
|
"active": true,
|
||||||
|
"slug": "jcitizen",
|
||||||
|
"type": "NORMAL",
|
||||||
|
"directoryName": "Bitbucket Internal Directory",
|
||||||
|
"deletable": true,
|
||||||
|
"lastAuthenticationTimestamp": 1368145580548,
|
||||||
|
"mutableDetails": true,
|
||||||
|
"mutableGroups": true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
want: []User{
|
||||||
|
User{
|
||||||
|
Name: "jcitizen",
|
||||||
|
EmailAddress: "jane@example.com",
|
||||||
|
ID: 101,
|
||||||
|
DisplayName: "Jane Citizen",
|
||||||
|
Active: true,
|
||||||
|
Slug: "jcitizen",
|
||||||
|
Type: "NORMAL",
|
||||||
|
DirectoryName: "Bitbucket Internal Directory",
|
||||||
|
Deletable: true,
|
||||||
|
LastAuthenticationTimestamp: 1368145580548,
|
||||||
|
MutableDetails: true,
|
||||||
|
MutableGroups: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
got, err := GetUsersResponse(tt.args.r)
|
||||||
|
if err != nil && !tt.wantErr {
|
||||||
|
t.Errorf("GetGroupsPermissionResponse() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Errorf("GetGroupsPermissionResponse() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetGroupsPermissionResponse(t *testing.T) {
|
func TestGetGroupsPermissionResponse(t *testing.T) {
|
||||||
type args struct {
|
type args struct {
|
||||||
r *APIResponse
|
r *APIResponse
|
||||||
|
Loading…
x
Reference in New Issue
Block a user