Improve highlighting and add QoL changes
This commit is contained in:
@@ -9,17 +9,28 @@ import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestListPullRequestsFiltersToViewer(t *testing.T) {
|
||||
func TestListPullRequestsSearchesAssignedPRsInRepository(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if got := r.Header.Get("Authorization"); got != "Bearer secret" {
|
||||
t.Fatalf("authorization = %q", got)
|
||||
}
|
||||
var request graphQLRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got := request.Variables["query"]; got != "is:pr is:open sort:updated-desc repo:o/r assignee:@me" {
|
||||
t.Fatalf("search query = %q", got)
|
||||
}
|
||||
_ = json.NewEncoder(w).Encode(map[string]any{"data": map[string]any{
|
||||
"viewer": map[string]any{"login": "zam"},
|
||||
"repository": map[string]any{"pullRequests": map[string]any{"nodes": []any{
|
||||
map[string]any{"id": "1", "number": 1, "title": "mine", "url": "u", "isDraft": false, "updatedAt": "2026-01-01T00:00:00Z", "author": map[string]any{"login": "zam"}, "reviewThreads": map[string]any{"totalCount": 2}},
|
||||
map[string]any{"id": "2", "number": 2, "title": "theirs", "url": "u", "isDraft": false, "updatedAt": "2026-01-01T00:00:00Z", "author": map[string]any{"login": "other"}, "reviewThreads": map[string]any{"totalCount": 1}},
|
||||
}}},
|
||||
"search": map[string]any{"nodes": []any{
|
||||
map[string]any{
|
||||
"id": "1", "number": 1, "title": "assigned", "url": "u", "isDraft": false,
|
||||
"updatedAt": "2026-01-01T00:00:00Z", "author": map[string]any{"login": "other"},
|
||||
"repository": map[string]any{"name": "r", "nameWithOwner": "o/r", "owner": map[string]any{"login": "o"}},
|
||||
"reviewThreads": map[string]any{"totalCount": 2},
|
||||
},
|
||||
}},
|
||||
}})
|
||||
}))
|
||||
defer server.Close()
|
||||
@@ -29,11 +40,39 @@ func TestListPullRequestsFiltersToViewer(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if len(prs) != 1 || prs[0].Number != 1 || prs[0].ReviewCount != 2 {
|
||||
if len(prs) != 1 || prs[0].Number != 1 || prs[0].ReviewCount != 2 ||
|
||||
prs[0].Owner != "o" || prs[0].Repository != "r" || prs[0].RepoWithOwner != "o/r" {
|
||||
t.Fatalf("unexpected PRs: %#v", prs)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListPullRequestsSearchesAllRepositoriesByDefault(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var request graphQLRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
query, _ := request.Variables["query"].(string)
|
||||
if !strings.Contains(query, "assignee:@me") || strings.Contains(query, "repo:") {
|
||||
t.Fatalf("global search query = %q", query)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"data":{"viewer":{"login":"zam"},"search":{"nodes":[]}}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := NewGitHubClient(server.URL, "secret")
|
||||
if _, err := client.ListPullRequests(context.Background(), "", "", 50, false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestListPullRequestsRejectsGlobalShowAll(t *testing.T) {
|
||||
client := NewGitHubClient("unused", "secret")
|
||||
if _, err := client.ListPullRequests(context.Background(), "", "", 50, true); err == nil {
|
||||
t.Fatal("global --all search was accepted")
|
||||
}
|
||||
}
|
||||
|
||||
func TestGraphQLErrorsAreReturned(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
_, _ = w.Write([]byte(`{"errors":[{"message":"no access"}]}`))
|
||||
|
||||
Reference in New Issue
Block a user