Skip to content

Commit

Permalink
add test for API
Browse files Browse the repository at this point in the history
  • Loading branch information
abhijit-hota committed Oct 3, 2023
1 parent 2bec3f1 commit 0aea507
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions github/apps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,53 @@ func TestAppsService_Get_specifiedApp(t *testing.T) {
}
}

func TestAppsService_ListInstallationRequests(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/app/installation-requests", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
testFormValues(t, r, values{
"page": "1",
"per_page": "2",
})
fmt.Fprint(w, `[{
"id": 1,
"account": { "id": 2 },
"requester": { "id": 3 },
"created_at": "2018-01-01T00:00:00Z"
}]`,
)
})

opt := &ListOptions{Page: 1, PerPage: 2}
ctx := context.Background()
installationRequests, _, err := client.Apps.ListInstallationRequests(ctx, opt)
if err != nil {
t.Errorf("Apps.ListInstallations returned error: %v", err)
}

date := Timestamp{Time: time.Date(2018, time.January, 1, 0, 0, 0, 0, time.UTC)}
want := []*InstallationRequest{{
ID: Int64(1),
Account: &User{ID: Int64(2)},
Requester: &User{ID: Int64(3)},
CreatedAt: &date,
}}
if !cmp.Equal(installationRequests, want) {
t.Errorf("Apps.ListInstallationRequests returned %+v, want %+v", installationRequests, want)
}

const methodName = "ListInstallationRequests"
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Apps.ListInstallationRequests(ctx, opt)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestAppsService_ListInstallations(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down

0 comments on commit 0aea507

Please sign in to comment.