|
| 1 | +package sentry |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "fmt" |
| 6 | + "net/http" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/stretchr/testify/assert" |
| 10 | +) |
| 11 | + |
| 12 | +func TestOrganizationCodeMappingsService_List(t *testing.T) { |
| 13 | + client, mux, _, teardown := setup() |
| 14 | + defer teardown() |
| 15 | + |
| 16 | + mux.HandleFunc("/api/0/organizations/the-interstellar-jurisdiction/code-mappings/", func(w http.ResponseWriter, r *http.Request) { |
| 17 | + assertMethod(t, "GET", r) |
| 18 | + assertQuery(t, map[string]string{"cursor": "100:-1:1", "integrationId": "123456"}, r) |
| 19 | + w.Header().Set("Content-Type", "application/json") |
| 20 | + fmt.Fprint(w, `[ |
| 21 | + { |
| 22 | + "id": "54321", |
| 23 | + "projectId": "7654321", |
| 24 | + "projectSlug": "spoon-knife", |
| 25 | + "repoId": "456123", |
| 26 | + "repoName": "octocat/Spoon-Knife", |
| 27 | + "integrationId": "123456", |
| 28 | + "provider": { |
| 29 | + "key": "github", |
| 30 | + "slug": "github", |
| 31 | + "name": "GitHub", |
| 32 | + "canAdd": true, |
| 33 | + "canDisable": false, |
| 34 | + "features": [ |
| 35 | + "codeowners", |
| 36 | + "commits", |
| 37 | + "issue-basic", |
| 38 | + "stacktrace-link" |
| 39 | + ], |
| 40 | + "aspects": {} |
| 41 | + }, |
| 42 | + "stackRoot": "/", |
| 43 | + "sourceRoot": "src/", |
| 44 | + "defaultBranch": "main" |
| 45 | + } |
| 46 | + ]`) |
| 47 | + }) |
| 48 | + |
| 49 | + ctx := context.Background() |
| 50 | + integrations, _, err := client.OrganizationCodeMappings.List(ctx, "the-interstellar-jurisdiction", &ListOrganizationCodeMappingsParams{ |
| 51 | + ListCursorParams: ListCursorParams{ |
| 52 | + Cursor: "100:-1:1", |
| 53 | + }, |
| 54 | + IntegrationId: "123456", |
| 55 | + }) |
| 56 | + assert.NoError(t, err) |
| 57 | + expected := []*OrganizationCodeMapping{ |
| 58 | + { |
| 59 | + ID: "54321", |
| 60 | + ProjectId: "7654321", |
| 61 | + ProjectSlug: "spoon-knife", |
| 62 | + RepoId: "456123", |
| 63 | + RepoName: "octocat/Spoon-Knife", |
| 64 | + IntegrationId: "123456", |
| 65 | + Provider: &OrganizationIntegrationProvider{ |
| 66 | + Key: "github", |
| 67 | + Slug: "github", |
| 68 | + Name: "GitHub", |
| 69 | + CanAdd: true, |
| 70 | + CanDisable: false, |
| 71 | + Features: []string{ |
| 72 | + "codeowners", |
| 73 | + "commits", |
| 74 | + "issue-basic", |
| 75 | + "stacktrace-link", |
| 76 | + }, |
| 77 | + }, |
| 78 | + StackRoot: "/", |
| 79 | + SourceRoot: "src/", |
| 80 | + DefaultBranch: "main", |
| 81 | + }, |
| 82 | + } |
| 83 | + assert.Equal(t, expected, integrations) |
| 84 | +} |
| 85 | + |
| 86 | +func TestOrganizationCodeMappingsService_Create(t *testing.T) { |
| 87 | + client, mux, _, teardown := setup() |
| 88 | + defer teardown() |
| 89 | + |
| 90 | + mux.HandleFunc("/api/0/organizations/the-interstellar-jurisdiction/code-mappings/", func(w http.ResponseWriter, r *http.Request) { |
| 91 | + assertMethod(t, "POST", r) |
| 92 | + w.WriteHeader(http.StatusCreated) |
| 93 | + w.Header().Set("Content-Type", "application/json") |
| 94 | + fmt.Fprint(w, `{ |
| 95 | + "id": "54321", |
| 96 | + "projectId": "7654321", |
| 97 | + "projectSlug": "spoon-knife", |
| 98 | + "repoId": "456123", |
| 99 | + "repoName": "octocat/Spoon-Knife", |
| 100 | + "integrationId": "123456", |
| 101 | + "provider": { |
| 102 | + "key": "github", |
| 103 | + "slug": "github", |
| 104 | + "name": "GitHub", |
| 105 | + "canAdd": true, |
| 106 | + "canDisable": false, |
| 107 | + "features": [ |
| 108 | + "codeowners", |
| 109 | + "commits", |
| 110 | + "issue-basic", |
| 111 | + "stacktrace-link" |
| 112 | + ], |
| 113 | + "aspects": {} |
| 114 | + }, |
| 115 | + "stackRoot": "/", |
| 116 | + "sourceRoot": "src/", |
| 117 | + "defaultBranch": "main" |
| 118 | + }`) |
| 119 | + }) |
| 120 | + |
| 121 | + ctx := context.Background() |
| 122 | + createOrganizationCodeMappingParams := CreateOrganizationCodeMappingParams{ |
| 123 | + DefaultBranch: "main", |
| 124 | + StackRoot: "/", |
| 125 | + SourceRoot: "src/", |
| 126 | + RepositoryId: "456123", |
| 127 | + IntegrationId: "123456", |
| 128 | + ProjectId: "7654321", |
| 129 | + } |
| 130 | + codeMapping, _, err := client.OrganizationCodeMappings.Create(ctx, "the-interstellar-jurisdiction", createOrganizationCodeMappingParams) |
| 131 | + assert.NoError(t, err) |
| 132 | + expected := &OrganizationCodeMapping{ |
| 133 | + ID: "54321", |
| 134 | + ProjectId: "7654321", |
| 135 | + ProjectSlug: "spoon-knife", |
| 136 | + RepoId: "456123", |
| 137 | + RepoName: "octocat/Spoon-Knife", |
| 138 | + IntegrationId: "123456", |
| 139 | + Provider: &OrganizationIntegrationProvider{ |
| 140 | + Key: "github", |
| 141 | + Slug: "github", |
| 142 | + Name: "GitHub", |
| 143 | + CanAdd: true, |
| 144 | + CanDisable: false, |
| 145 | + Features: []string{ |
| 146 | + "codeowners", |
| 147 | + "commits", |
| 148 | + "issue-basic", |
| 149 | + "stacktrace-link", |
| 150 | + }, |
| 151 | + }, |
| 152 | + StackRoot: "/", |
| 153 | + SourceRoot: "src/", |
| 154 | + DefaultBranch: "main", |
| 155 | + } |
| 156 | + assert.Equal(t, expected, codeMapping) |
| 157 | +} |
| 158 | + |
| 159 | +func TestOrganizationCodeMappingsService_Update(t *testing.T) { |
| 160 | + client, mux, _, teardown := setup() |
| 161 | + defer teardown() |
| 162 | + |
| 163 | + codeMappingId := "54321" |
| 164 | + |
| 165 | + mux.HandleFunc(fmt.Sprintf("/api/0/organizations/the-interstellar-jurisdiction/code-mappings/%s/", codeMappingId), func(w http.ResponseWriter, r *http.Request) { |
| 166 | + assertMethod(t, "PUT", r) |
| 167 | + w.WriteHeader(http.StatusOK) |
| 168 | + w.Header().Set("Content-Type", "application/json") |
| 169 | + fmt.Fprintf(w, `{ |
| 170 | + "id": "%s", |
| 171 | + "projectId": "7654321", |
| 172 | + "projectSlug": "spoon-knife", |
| 173 | + "repoId": "456123", |
| 174 | + "repoName": "octocat/Spoon-Knife", |
| 175 | + "integrationId": "123456", |
| 176 | + "provider": { |
| 177 | + "key": "github", |
| 178 | + "slug": "github", |
| 179 | + "name": "GitHub", |
| 180 | + "canAdd": true, |
| 181 | + "canDisable": false, |
| 182 | + "features": [ |
| 183 | + "codeowners", |
| 184 | + "commits", |
| 185 | + "issue-basic", |
| 186 | + "stacktrace-link" |
| 187 | + ], |
| 188 | + "aspects": {} |
| 189 | + }, |
| 190 | + "stackRoot": "/", |
| 191 | + "sourceRoot": "src/", |
| 192 | + "defaultBranch": "main" |
| 193 | + }`, codeMappingId) |
| 194 | + }) |
| 195 | + |
| 196 | + ctx := context.Background() |
| 197 | + updateOrganizationCodeMappingParams := UpdateOrganizationCodeMappingParams{ |
| 198 | + DefaultBranch: "main", |
| 199 | + StackRoot: "/", |
| 200 | + SourceRoot: "src/", |
| 201 | + RepositoryId: "456123", |
| 202 | + IntegrationId: "123456", |
| 203 | + ProjectId: "7654321", |
| 204 | + } |
| 205 | + codeMapping, _, err := client.OrganizationCodeMappings.Update(ctx, "the-interstellar-jurisdiction", codeMappingId, updateOrganizationCodeMappingParams) |
| 206 | + assert.NoError(t, err) |
| 207 | + expected := &OrganizationCodeMapping{ |
| 208 | + ID: codeMappingId, |
| 209 | + ProjectId: "7654321", |
| 210 | + ProjectSlug: "spoon-knife", |
| 211 | + RepoId: "456123", |
| 212 | + RepoName: "octocat/Spoon-Knife", |
| 213 | + IntegrationId: "123456", |
| 214 | + Provider: &OrganizationIntegrationProvider{ |
| 215 | + Key: "github", |
| 216 | + Slug: "github", |
| 217 | + Name: "GitHub", |
| 218 | + CanAdd: true, |
| 219 | + CanDisable: false, |
| 220 | + Features: []string{ |
| 221 | + "codeowners", |
| 222 | + "commits", |
| 223 | + "issue-basic", |
| 224 | + "stacktrace-link", |
| 225 | + }, |
| 226 | + }, |
| 227 | + StackRoot: "/", |
| 228 | + SourceRoot: "src/", |
| 229 | + DefaultBranch: "main", |
| 230 | + } |
| 231 | + assert.Equal(t, expected, codeMapping) |
| 232 | +} |
| 233 | + |
| 234 | +func TestOrganizationCodeMappingsService_Delete(t *testing.T) { |
| 235 | + client, mux, _, teardown := setup() |
| 236 | + defer teardown() |
| 237 | + |
| 238 | + codeMappingId := "54321" |
| 239 | + |
| 240 | + mux.HandleFunc(fmt.Sprintf("/api/0/organizations/the-interstellar-jurisdiction/code-mappings/%s/", codeMappingId), func(w http.ResponseWriter, r *http.Request) { |
| 241 | + assertMethod(t, "DELETE", r) |
| 242 | + w.WriteHeader(http.StatusNoContent) |
| 243 | + w.Header().Set("Content-Type", "application/json") |
| 244 | + }) |
| 245 | + |
| 246 | + ctx := context.Background() |
| 247 | + _, err := client.OrganizationCodeMappings.Delete(ctx, "the-interstellar-jurisdiction", codeMappingId) |
| 248 | + assert.NoError(t, err) |
| 249 | +} |
0 commit comments