(t *testing.T)
| 73 | } |
| 74 | |
| 75 | func 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 | } |
nothing calls this directly
no test coverage detected