MCPcopy Create free account
hub / github.com/GoogleChrome/webstatus.dev / TestPingUser

Function TestPingUser

backend/pkg/httpserver/ping_user_test.go:32–274  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

30}
31
32func 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,

Callers

nothing calls this directly

Calls 12

testEmptyJSONObjectBodyFunction · 0.85
mockAuthMiddlewareFunction · 0.85
createTestID1UserFunction · 0.85
createEmptyBodyResponseFunction · 0.85
testJSONResponseFunction · 0.85
withAuthMiddlewareFunction · 0.85
setupTestServerFunction · 0.85
withCustomStorerFunction · 0.85
assertTestServerRequestFunction · 0.85
RunMethod · 0.65

Tested by

no test coverage detected