Make dashboard updateable
This commit is contained in:
@@ -8,8 +8,62 @@ import (
|
||||
"reflect"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestListBranchesPaginatesAndMarksTheDefaultBranch(t *testing.T) {
|
||||
requests := 0
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
requests++
|
||||
var request graphQLRequest
|
||||
if err := json.NewDecoder(r.Body).Decode(&request); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if !strings.Contains(request.Query, "query RepositoryBranches") {
|
||||
t.Fatalf("unexpected query: %s", request.Query)
|
||||
}
|
||||
if requests == 1 {
|
||||
if request.Variables["after"] != nil {
|
||||
t.Fatalf("first cursor = %#v", request.Variables["after"])
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"data":{"repository":{
|
||||
"defaultBranchRef":{"name":"main"},
|
||||
"refs":{"pageInfo":{"hasNextPage":true,"endCursor":"next"},"nodes":[
|
||||
{"name":"feature/old","target":{"committedDate":"2024-01-01T00:00:00Z"}},
|
||||
{"name":"main","target":{"committedDate":"2025-01-01T00:00:00Z"}}
|
||||
]}
|
||||
}}}`))
|
||||
return
|
||||
}
|
||||
if request.Variables["after"] != "next" {
|
||||
t.Fatalf("second cursor = %#v", request.Variables["after"])
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"data":{"repository":{
|
||||
"defaultBranchRef":{"name":"main"},
|
||||
"refs":{"pageInfo":{"hasNextPage":false},"nodes":[
|
||||
{"name":"release/2.0","target":{"committedDate":"2026-07-28T00:00:00Z"}}
|
||||
]}
|
||||
}}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := NewGitHubClient(server.URL, "secret")
|
||||
branches, err := client.ListBranches(context.Background(), "o", "r")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if requests != 2 || len(branches) != 3 {
|
||||
t.Fatalf("requests=%d branches=%#v", requests, branches)
|
||||
}
|
||||
if branches[0].Name != "main" || !branches[0].IsDefault {
|
||||
t.Fatalf("default branch was not first and marked: %#v", branches)
|
||||
}
|
||||
wantUpdated := time.Date(2026, 7, 28, 0, 0, 0, 0, time.UTC)
|
||||
if branches[1].Name != "release/2.0" || !branches[1].UpdatedAt.Equal(wantUpdated) {
|
||||
t.Fatalf("fresh branch was not decoded and sorted: %#v", branches)
|
||||
}
|
||||
}
|
||||
|
||||
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" {
|
||||
@@ -176,6 +230,40 @@ func TestThreadWriteMutationsUseThreadIDs(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUpdatePullRequestMutatesTitleBodyAndBaseBranch(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)
|
||||
}
|
||||
if !strings.Contains(request.Query, "mutation UpdatePullRequest") {
|
||||
t.Fatalf("unexpected mutation:\n%s", request.Query)
|
||||
}
|
||||
input := request.Variables["input"].(map[string]any)
|
||||
if input["pullRequestId"] != "pr-id" || input["title"] != "New title" ||
|
||||
input["body"] != "- [x] done" || input["baseRefName"] != "release" {
|
||||
t.Fatalf("update input = %#v", input)
|
||||
}
|
||||
_, _ = w.Write([]byte(`{"data":{"updatePullRequest":{"pullRequest":{
|
||||
"id":"pr-id","title":"New title","body":"- [x] done","baseRefName":"release",
|
||||
"updatedAt":"2026-07-28T12:00:00Z","mergeable":"UNKNOWN","mergeStateStatus":"UNKNOWN"
|
||||
}}}}`))
|
||||
}))
|
||||
defer server.Close()
|
||||
|
||||
client := NewGitHubClient(server.URL, "secret")
|
||||
got, err := client.UpdatePullRequest(context.Background(), "pr-id", PullRequestMetadata{
|
||||
Title: "New title", Body: "- [x] done", BaseRef: "release",
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.Title != "New title" || got.Body != "- [x] done" || got.BaseRef != "release" ||
|
||||
got.Mergeable != "UNKNOWN" || got.UpdatedAt.IsZero() {
|
||||
t.Fatalf("updated pull request = %#v", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCheckContextsAndAnnotationsArePaginated(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
var request graphQLRequest
|
||||
|
||||
Reference in New Issue
Block a user