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

Function TestJoinDuplicateEmail

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

Source from the content-addressed store, hash-verified

198}
199
200func TestJoinDuplicateEmail(t *testing.T) {
201 db := testutils.InitMemoryDB(t)
202
203 // Setup
204 a := app.NewTest()
205 a.Clock = clock.NewMock()
206 a.DB = db
207 server := MustNewServer(t, &a)
208 defer server.Close()
209
210 u := testutils.SetupUserData(db, "alice@example.com", "somepassword")
211
212 dat := url.Values{}
213 dat.Set("email", "alice@example.com")
214 dat.Set("password", "foobarbaz")
215 dat.Set("password_confirmation", "foobarbaz")
216 req := testutils.MakeFormReq(server.URL, "POST", "/join", dat)
217
218 // Execute
219 res := testutils.HTTPDo(t, req)
220
221 // Test
222 assert.StatusCodeEquals(t, res, http.StatusBadRequest, "status code mismatch")
223
224 var userCount, verificationTokenCount int64
225 testutils.MustExec(t, db.Model(&database.User{}).Count(&userCount), "counting user")
226 testutils.MustExec(t, db.Model(&database.Token{}).Count(&verificationTokenCount), "counting verification token")
227
228 var user database.User
229 testutils.MustExec(t, db.Where("id = ?", u.ID).First(&user), "finding user")
230
231 assert.Equal(t, userCount, int64(1), "user count mismatch")
232 assert.Equal(t, verificationTokenCount, int64(0), "verification_token should not have been created")
233 assert.Equal(t, user.LastLoginAt, (*time.Time)(nil), "LastLoginAt mismatch")
234}
235
236func TestJoinDisabled(t *testing.T) {
237 db := testutils.InitMemoryDB(t)

Callers

nothing calls this directly

Calls 11

InitMemoryDBFunction · 0.92
NewTestFunction · 0.92
NewMockFunction · 0.92
SetupUserDataFunction · 0.92
MakeFormReqFunction · 0.92
HTTPDoFunction · 0.92
StatusCodeEqualsFunction · 0.92
MustExecFunction · 0.92
EqualFunction · 0.92
MustNewServerFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected