mirror of
https://github.com/interviewstreet/go-jira.git
synced 2025-06-23 00:07:40 +02:00
use pagination from design
This commit is contained in:
@ -29,29 +29,48 @@ func TestGroupService_GetPage(t *testing.T) {
|
||||
testRequestURL(t, r, "/rest/api/2/group/member?groupname=default")
|
||||
startAt := r.URL.Query().Get("startAt")
|
||||
if startAt == "0" {
|
||||
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/group/member?includeInactiveUsers=false&maxResults=2&groupname=default&startAt=0","nextPage":"`+testServer.URL+`/rest/api/2/group/member?groupname=default&includeInactiveUsers=false&maxResults=2&startAt=2","maxResults":2,"startAt":0,"total":2,"isLast":false,"values":[{"self":"http://www.example.com/jira/rest/api/2/user?username=michael","name":"michael","key":"michael","emailAddress":"michael@example.com","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"alex@example.com","displayName":"AlexanderMahone","active":true,"timeZone":"Australia/Sydney"}]}`)
|
||||
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/group/member?includeInactiveUsers=false&maxResults=2&groupname=default&startAt=0","nextPage":"`+testServer.URL+`/rest/api/2/group/member?groupname=default&includeInactiveUsers=false&maxResults=2&startAt=2","maxResults":2,"startAt":0,"total":4,"isLast":false,"values":[{"self":"http://www.example.com/jira/rest/api/2/user?username=michael","name":"michael","key":"michael","emailAddress":"michael@example.com","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"alex@example.com","displayName":"AlexanderMahone","active":true,"timeZone":"Australia/Sydney"}]}`)
|
||||
} else if startAt == "2" {
|
||||
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/group/member?includeInactiveUsers=false&maxResults=2&groupname=default&startAt=2","maxResults":2,"startAt":0,"total":2,"isLast":true,"values":[{"self":"http://www.example.com/jira/rest/api/2/user?username=michael","name":"michael","key":"michael","emailAddress":"michael@example.com","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"alex@example.com","displayName":"AlexanderMahone","active":true,"timeZone":"Australia/Sydney"}]}`)
|
||||
fmt.Fprint(w, `{"self":"http://www.example.com/jira/rest/api/2/group/member?includeInactiveUsers=false&maxResults=2&groupname=default&startAt=2","maxResults":2,"startAt":2,"total":4,"isLast":true,"values":[{"self":"http://www.example.com/jira/rest/api/2/user?username=michael","name":"michael","key":"michael","emailAddress":"michael@example.com","displayName":"MichaelScofield","active":true,"timeZone":"Australia/Sydney"},{"self":"http://www.example.com/jira/rest/api/2/user?username=alex","name":"alex","key":"alex","emailAddress":"alex@example.com","displayName":"AlexanderMahone","active":true,"timeZone":"Australia/Sydney"}]}`)
|
||||
} else {
|
||||
t.Errorf("startAt %s", startAt)
|
||||
}
|
||||
})
|
||||
if page, _, err := testClient.Group.GetByPage("default", 0, 2, false); err != nil {
|
||||
if page, resp, err := testClient.Group.GetByOption("default", &GroupSearchOptions{
|
||||
StartAt: 0,
|
||||
MaxResults: 2,
|
||||
IncludeInactiveUsers: false,
|
||||
}); err != nil {
|
||||
t.Errorf("Error given: %s %s", err, testServer.URL)
|
||||
} else if page == nil {
|
||||
t.Error("Expected members. Group.Members is nil")
|
||||
} else if page == nil || len(page) != 2 {
|
||||
t.Error("Expected members. Group.Members is not 2 or is nil")
|
||||
} else {
|
||||
if len(page.Members) != 2 {
|
||||
t.Errorf("Expect 2 members in list. Get %d members", len(page.Members))
|
||||
if resp.StartAt != 0 {
|
||||
t.Errorf("Expect Result StartAt to be 0, but is %d", resp.StartAt)
|
||||
}
|
||||
url := page.NextPage
|
||||
if page, _, err = page.GetNextPage(); err != nil {
|
||||
t.Errorf("Error given: %s %s", err, url)
|
||||
} else if page == nil {
|
||||
t.Error("Expected members. Group.Members is nil")
|
||||
if resp.MaxResults != 2 {
|
||||
t.Errorf("Expect Result MaxResults to be 2, but is %d", resp.MaxResults)
|
||||
}
|
||||
if resp.Total != 4 {
|
||||
t.Errorf("Expect Result Total to be 4, but is %d", resp.Total)
|
||||
}
|
||||
if page, resp, err := testClient.Group.GetByOption("default", &GroupSearchOptions{
|
||||
StartAt: 2,
|
||||
MaxResults: 2,
|
||||
IncludeInactiveUsers: false,
|
||||
}); err != nil {
|
||||
t.Errorf("Error give: %s %s", err, testServer.URL)
|
||||
} else if page == nil || len(page) != 2 {
|
||||
t.Error("Expected members. Group.Members is not 2 or is nil")
|
||||
} else {
|
||||
if len(page.Members) != 2 {
|
||||
t.Errorf("Expect 2 members in list. Get %d members", len(page.Members))
|
||||
if resp.StartAt != 2 {
|
||||
t.Errorf("Expect Result StartAt to be 2, but is %d", resp.StartAt)
|
||||
}
|
||||
if resp.MaxResults != 2 {
|
||||
t.Errorf("Expect Result MaxResults to be 2, but is %d", resp.MaxResults)
|
||||
}
|
||||
if resp.Total != 4 {
|
||||
t.Errorf("Expect Result Total to be 4, but is %d", resp.Total)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user