MCPcopy Index your code
hub / github.com/cli/cli / TestUpdateProjectV2Items

Function TestUpdateProjectV2Items

api/queries_projects_v2_test.go:17–96  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

15)
16
17func TestUpdateProjectV2Items(t *testing.T) {
18 var tests = []struct {
19 name string
20 httpStubs func(*httpmock.Registry)
21 expectError bool
22 }{
23 {
24 name: "updates project items",
25 httpStubs: func(reg *httpmock.Registry) {
26 reg.Register(
27 httpmock.GraphQL(`mutation UpdateProjectV2Items\b`),
28 httpmock.GraphQLQuery(`{"data":{"add_000":{"item":{"id":"1"}},"delete_001":{"item":{"id":"2"}}}}`,
29 func(mutations string, inputs map[string]interface{}) {
30 expectedMutations := `
31 mutation UpdateProjectV2Items(
32 $input_000: AddProjectV2ItemByIdInput!
33 $input_001: AddProjectV2ItemByIdInput!
34 $input_002: DeleteProjectV2ItemInput!
35 $input_003: DeleteProjectV2ItemInput!
36 ) {
37 add_000: addProjectV2ItemById(input: $input_000) { item { id } }
38 add_001: addProjectV2ItemById(input: $input_001) { item { id } }
39 delete_002: deleteProjectV2Item(input: $input_002) { deletedItemId }
40 delete_003: deleteProjectV2Item(input: $input_003) { deletedItemId }
41 }`
42 assert.Equal(t, stripSpace(expectedMutations), stripSpace(mutations))
43 if len(inputs) != 4 {
44 t.Fatalf("expected 4 inputs, got %d", len(inputs))
45 }
46 i0 := inputs["input_000"].(map[string]interface{})
47 i1 := inputs["input_001"].(map[string]interface{})
48 i2 := inputs["input_002"].(map[string]interface{})
49 i3 := inputs["input_003"].(map[string]interface{})
50 adds := []string{
51 fmt.Sprintf("%v -> %v", i0["contentId"], i0["projectId"]),
52 fmt.Sprintf("%v -> %v", i1["contentId"], i1["projectId"]),
53 }
54 removes := []string{
55 fmt.Sprintf("%v x %v", i2["itemId"], i2["projectId"]),
56 fmt.Sprintf("%v x %v", i3["itemId"], i3["projectId"]),
57 }
58 sort.Strings(adds)
59 sort.Strings(removes)
60 assert.Equal(t, []string{"item1 -> project1", "item2 -> project2"}, adds)
61 assert.Equal(t, []string{"item3 x project3", "item4 x project4"}, removes)
62 }))
63 },
64 },
65 {
66 name: "fails to update project items",
67 httpStubs: func(reg *httpmock.Registry) {
68 reg.Register(
69 httpmock.GraphQL(`mutation UpdateProjectV2Items\b`),
70 httpmock.GraphQLMutation(`{"data":{}, "errors": [{"message": "some gql error"}]}`, func(inputs map[string]interface{}) {}),
71 )
72 },
73 expectError: true,
74 },

Callers

nothing calls this directly

Calls 12

RegisterMethod · 0.95
VerifyMethod · 0.95
GraphQLFunction · 0.92
GraphQLQueryFunction · 0.92
GraphQLMutationFunction · 0.92
FromFullNameFunction · 0.92
stripSpaceFunction · 0.85
newTestClientFunction · 0.85
UpdateProjectV2ItemsFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected