Skip to content

Commit 31398fe

Browse files
committed
Add test for non-interactive projects v1 unsupported
Introduces a test case to ensure that when editing pull requests non-interactively and projects v1 is unsupported, v1 project metadata is not fetched and only v2 project queries are made.
1 parent ec526bf commit 31398fe

1 file changed

Lines changed: 61 additions & 0 deletions

File tree

pkg/cmd/pr/edit/edit_test.go

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -895,6 +895,67 @@ func Test_editRun(t *testing.T) {
895895
},
896896
stdout: "https://github.com/OWNER/REPO/pull/123\n",
897897
},
898+
{
899+
name: "non-interactive projects v1 unsupported doesn't fetch v1 metadata",
900+
input: &EditOptions{
901+
Detector: &fd.DisabledDetectorMock{},
902+
SelectorArg: "123",
903+
Finder: shared.NewMockFinder("123", &api.PullRequest{
904+
URL: "https://github.com/OWNER/REPO/pull/123",
905+
}, ghrepo.New("OWNER", "REPO")),
906+
Interactive: false,
907+
Editable: shared.Editable{
908+
Projects: shared.EditableProjects{
909+
EditableSlice: shared.EditableSlice{
910+
Add: []string{"CleanupV2"},
911+
Remove: []string{"RoadmapV2"},
912+
Edited: true,
913+
},
914+
},
915+
},
916+
Fetcher: testFetcher{},
917+
},
918+
httpStubs: func(t *testing.T, reg *httpmock.Registry) {
919+
// Ensure v1 project queries are NOT made.
920+
reg.Exclude(t, httpmock.GraphQL(`query RepositoryProjectList\b`))
921+
reg.Exclude(t, httpmock.GraphQL(`query OrganizationProjectList\b`))
922+
// Provide only v2 project metadata queries.
923+
reg.Register(
924+
httpmock.GraphQL(`query RepositoryProjectV2List\b`),
925+
httpmock.StringResponse(`
926+
{ "data": { "repository": { "projectsV2": {
927+
"nodes": [
928+
{ "title": "CleanupV2", "id": "CLEANUPV2ID" },
929+
{ "title": "RoadmapV2", "id": "ROADMAPV2ID" }
930+
],
931+
"pageInfo": { "hasNextPage": false }
932+
} } } }
933+
`))
934+
reg.Register(
935+
httpmock.GraphQL(`query OrganizationProjectV2List\b`),
936+
httpmock.StringResponse(`
937+
{ "data": { "organization": { "projectsV2": {
938+
"nodes": [
939+
{ "title": "TriageV2", "id": "TRIAGEV2ID" }
940+
],
941+
"pageInfo": { "hasNextPage": false }
942+
} } } }
943+
`))
944+
reg.Register(
945+
httpmock.GraphQL(`query UserProjectV2List\b`),
946+
httpmock.StringResponse(`
947+
{ "data": { "viewer": { "projectsV2": {
948+
"nodes": [
949+
{ "title": "MonalisaV2", "id": "MONALISAV2ID" }
950+
],
951+
"pageInfo": { "hasNextPage": false }
952+
} } } }
953+
`))
954+
mockProjectV2ItemUpdate(reg)
955+
mockPullRequestUpdate(reg)
956+
},
957+
stdout: "https://github.com/OWNER/REPO/pull/123\n",
958+
},
898959
}
899960
for _, tt := range tests {
900961
t.Run(tt.name, func(t *testing.T) {

0 commit comments

Comments
 (0)