(t *testing.T)
| 30 | } |
| 31 | |
| 32 | func TestPingUser(t *testing.T) { |
| 33 | testCases := []struct { |
| 34 | name string |
| 35 | authMiddleware func(http.Handler) http.Handler |
| 36 | body io.Reader |
| 37 | getCurrentUserCfg *mockGetCurrentUserConfig |
| 38 | listEmailsCfg *mockListEmailsConfig |
| 39 | syncUserProfileInfoCfg *MockSyncUserProfileInfoConfig |
| 40 | expectedResponse *http.Response |
| 41 | }{ |
| 42 | { |
| 43 | name: "success no github access token in body", |
| 44 | body: testEmptyJSONObjectBody(), |
| 45 | authMiddleware: mockAuthMiddleware(createTestID1User()), |
| 46 | getCurrentUserCfg: nil, |
| 47 | listEmailsCfg: nil, |
| 48 | syncUserProfileInfoCfg: nil, |
| 49 | expectedResponse: createEmptyBodyResponse(http.StatusNoContent), |
| 50 | }, |
| 51 | { |
| 52 | name: "no user", |
| 53 | authMiddleware: mockAuthMiddleware(nil), |
| 54 | body: testEmptyJSONObjectBody(), |
| 55 | getCurrentUserCfg: nil, |
| 56 | listEmailsCfg: nil, |
| 57 | syncUserProfileInfoCfg: nil, |
| 58 | expectedResponse: testJSONResponse(http.StatusInternalServerError, `{ |
| 59 | "code": 500, |
| 60 | "message": "internal server error" |
| 61 | }`), |
| 62 | }, |
| 63 | { |
| 64 | name: "github user id missing from token", |
| 65 | body: strings.NewReader(`{"github_token": "foo"}`), |
| 66 | authMiddleware: mockAuthMiddleware(&auth.User{ |
| 67 | ID: "hi", |
| 68 | GitHubUserID: nil, |
| 69 | }), |
| 70 | getCurrentUserCfg: nil, |
| 71 | listEmailsCfg: nil, |
| 72 | syncUserProfileInfoCfg: nil, |
| 73 | expectedResponse: testJSONResponse(http.StatusInternalServerError, `{ |
| 74 | "code": 500, |
| 75 | "message": "token is missing github user id" |
| 76 | }`), |
| 77 | }, |
| 78 | { |
| 79 | name: "failed to get github user", |
| 80 | body: strings.NewReader(`{"github_token": "foo"}`), |
| 81 | authMiddleware: mockAuthMiddleware(&auth.User{ |
| 82 | ID: "hi", |
| 83 | GitHubUserID: new("123456"), |
| 84 | }), |
| 85 | getCurrentUserCfg: &mockGetCurrentUserConfig{ |
| 86 | err: errTest, |
| 87 | user: nil, |
| 88 | }, |
| 89 | listEmailsCfg: nil, |
nothing calls this directly
no test coverage detected