MCPcopy Index your code
hub / github.com/dnote/dnote / TestJoin

Function TestJoin

pkg/server/controllers/users_test.go:50–116  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

48}
49
50func TestJoin(t *testing.T) {
51 testCases := []struct {
52 email string
53 password string
54 passwordConfirmation string
55 }{
56 {
57 email: "alice@example.com",
58 password: "pass1234",
59 passwordConfirmation: "pass1234",
60 },
61 {
62 email: "bob@example.com",
63 password: "Y9EwmjH@Jq6y5a64MSACUoM4w7SAhzvY",
64 passwordConfirmation: "Y9EwmjH@Jq6y5a64MSACUoM4w7SAhzvY",
65 },
66 {
67 email: "chuck@example.com",
68 password: "e*H@kJi^vXbWEcD9T5^Am!Y@7#Po2@PC",
69 passwordConfirmation: "e*H@kJi^vXbWEcD9T5^Am!Y@7#Po2@PC",
70 },
71 }
72
73 for _, tc := range testCases {
74 t.Run(fmt.Sprintf("register %s %s", tc.email, tc.password), func(t *testing.T) {
75 db := testutils.InitMemoryDB(t)
76
77 // Setup
78 emailBackend := testutils.MockEmailbackendImplementation{}
79 a := app.NewTest()
80 a.Clock = clock.NewMock()
81 a.EmailBackend = &emailBackend
82 a.DB = db
83 server := MustNewServer(t, &a)
84 defer server.Close()
85
86 dat := url.Values{}
87 dat.Set("email", tc.email)
88 dat.Set("password", tc.password)
89 dat.Set("password_confirmation", tc.passwordConfirmation)
90 req := testutils.MakeFormReq(server.URL, "POST", "/join", dat)
91
92 // Execute
93 res := testutils.HTTPDo(t, req)
94
95 // Test
96 assert.StatusCodeEquals(t, res, http.StatusFound, "")
97
98 var user database.User
99 testutils.MustExec(t, db.Where("email = ?", tc.email).First(&user), "finding account")
100 assert.Equal(t, user.Email.String, tc.email, "Email mismatch")
101 assert.NotEqual(t, user.ID, 0, "UserID mismatch")
102 passwordErr := bcrypt.CompareHashAndPassword([]byte(user.Password.String), []byte(tc.password))
103 assert.Equal(t, passwordErr, nil, "Password mismatch")
104
105 testutils.MustExec(t, db.Where("id = ?", user.ID).First(&user), "finding user")
106 assert.Equal(t, user.MaxUSN, 0, "MaxUSN mismatch")
107

Callers

nothing calls this directly

Calls 14

InitMemoryDBFunction · 0.92
NewTestFunction · 0.92
NewMockFunction · 0.92
MakeFormReqFunction · 0.92
HTTPDoFunction · 0.92
StatusCodeEqualsFunction · 0.92
MustExecFunction · 0.92
EqualFunction · 0.92
NotEqualFunction · 0.92
EqualfFunction · 0.92
DeepEqualFunction · 0.92
MustNewServerFunction · 0.85

Tested by

no test coverage detected