MCPcopy Create free account
hub / github.com/cli/cli / TestProjectItemIDByURL

Function TestProjectItemIDByURL

pkg/cmd/project/shared/queries/resolve_test.go:75–126  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

73}
74
75func TestProjectItemIDByURL(t *testing.T) {
76 t.Run("returns the item id for the matching project", func(t *testing.T) {
77 defer gock.Off()
78 gock.New("https://api.github.com").
79 Post("/graphql").
80 Reply(200).
81 JSON(map[string]interface{}{
82 "data": map[string]interface{}{
83 "resource": map[string]interface{}{
84 "__typename": "Issue",
85 "projectItems": map[string]interface{}{
86 "nodes": []map[string]interface{}{
87 {"id": "PVTI_other", "project": map[string]interface{}{"id": "PVT_other"}},
88 {"id": "PVTI_match", "project": map[string]interface{}{"id": "PVT_target"}},
89 },
90 },
91 },
92 },
93 })
94
95 client := NewTestClient()
96 id, err := client.ProjectItemIDByURL("https://github.com/monalisa/repo/issues/1", "PVT_target", 5)
97 require.NoError(t, err)
98 assert.Equal(t, "PVTI_match", id)
99 })
100
101 t.Run("errors when the resource is not an item on the project", func(t *testing.T) {
102 defer gock.Off()
103 gock.New("https://api.github.com").
104 Post("/graphql").
105 Reply(200).
106 JSON(map[string]interface{}{
107 "data": map[string]interface{}{
108 "resource": map[string]interface{}{
109 "__typename": "Issue",
110 "projectItems": map[string]interface{}{
111 "nodes": []map[string]interface{}{
112 {"id": "PVTI_other", "project": map[string]interface{}{"id": "PVT_other"}},
113 },
114 },
115 },
116 },
117 })
118
119 client := NewTestClient()
120 _, err := client.ProjectItemIDByURL("https://github.com/monalisa/repo/issues/1", "PVT_target", 5)
121 require.Error(t, err)
122 var nip *ItemNotInProjectError
123 require.True(t, errors.As(err, &nip))
124 assert.Contains(t, err.Error(), "is not an item in project 5")
125 })
126}

Callers

nothing calls this directly

Calls 7

ReplyMethod · 0.80
ProjectItemIDByURLMethod · 0.80
EqualMethod · 0.80
ContainsMethod · 0.80
NewTestClientFunction · 0.70
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected