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

Function TestJoinError

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

Source from the content-addressed store, hash-verified

116}
117
118func TestJoinError(t *testing.T) {
119 t.Run("missing email", func(t *testing.T) {
120 db := testutils.InitMemoryDB(t)
121
122 // Setup
123 a := app.NewTest()
124 a.Clock = clock.NewMock()
125 a.DB = db
126 server := MustNewServer(t, &a)
127 defer server.Close()
128
129 dat := url.Values{}
130 dat.Set("password", "SLMZFM5RmSjA5vfXnG5lPOnrpZSbtmV76cnAcrlr2yU")
131 req := testutils.MakeFormReq(server.URL, "POST", "/join", dat)
132
133 // Execute
134 res := testutils.HTTPDo(t, req)
135
136 // Test
137 assert.StatusCodeEquals(t, res, http.StatusBadRequest, "Status mismatch")
138
139 var userCount int64
140 testutils.MustExec(t, db.Model(&database.User{}).Count(&userCount), "counting user")
141
142 assert.Equal(t, userCount, int64(0), "userCount mismatch")
143 })
144
145 t.Run("missing password", func(t *testing.T) {
146 db := testutils.InitMemoryDB(t)
147
148 // Setup
149 a := app.NewTest()
150 a.Clock = clock.NewMock()
151 a.DB = db
152 server := MustNewServer(t, &a)
153 defer server.Close()
154
155 dat := url.Values{}
156 dat.Set("email", "alice@example.com")
157 req := testutils.MakeFormReq(server.URL, "POST", "/join", dat)
158
159 // Execute
160 res := testutils.HTTPDo(t, req)
161
162 // Test
163 assert.StatusCodeEquals(t, res, http.StatusBadRequest, "Status mismatch")
164
165 var userCount int64
166 testutils.MustExec(t, db.Model(&database.User{}).Count(&userCount), "counting user")
167
168 assert.Equal(t, userCount, int64(0), "userCount mismatch")
169 })
170
171 t.Run("password confirmation mismatch", func(t *testing.T) {
172 db := testutils.InitMemoryDB(t)
173
174 // Setup
175 a := app.NewTest()

Callers

nothing calls this directly

Calls 10

InitMemoryDBFunction · 0.92
NewTestFunction · 0.92
NewMockFunction · 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