MCPcopy
hub / github.com/pocketbase/pocketbase / TestDeleteExpiredOTPs

Function TestDeleteExpiredOTPs

core/otp_query_test.go:250–310  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

248}
249
250func TestDeleteExpiredOTPs(t *testing.T) {
251 t.Parallel()
252
253 checkDeletedIds := func(app core.App, t *testing.T, expectedDeletedIds []string) {
254 if err := tests.StubOTPRecords(app); err != nil {
255 t.Fatal(err)
256 }
257
258 deletedIds := []string{}
259 app.OnRecordAfterDeleteSuccess().BindFunc(func(e *core.RecordEvent) error {
260 deletedIds = append(deletedIds, e.Record.Id)
261 return e.Next()
262 })
263
264 if err := app.DeleteExpiredOTPs(); err != nil {
265 t.Fatal(err)
266 }
267
268 if len(deletedIds) != len(expectedDeletedIds) {
269 t.Fatalf("Expected deleted ids\n%v\ngot\n%v", expectedDeletedIds, deletedIds)
270 }
271
272 for _, id := range expectedDeletedIds {
273 if !slices.Contains(deletedIds, id) {
274 t.Errorf("Expected to find deleted id %q in %v", id, deletedIds)
275 }
276 }
277 }
278
279 t.Run("default test collections", func(t *testing.T) {
280 app, _ := tests.NewTestApp()
281 defer app.Cleanup()
282
283 checkDeletedIds(app, t, []string{
284 "user1_0",
285 "superuser2_2",
286 "superuser2_4",
287 })
288 })
289
290 t.Run("otp collection duration mock", func(t *testing.T) {
291 app, _ := tests.NewTestApp()
292 defer app.Cleanup()
293
294 superusers, err := app.FindCollectionByNameOrId(core.CollectionNameSuperusers)
295 if err != nil {
296 t.Fatal(err)
297 }
298 superusers.OTP.Duration = 60
299 if err := app.Save(superusers); err != nil {
300 t.Fatalf("Failed to mock superusers otp duration: %v", err)
301 }
302
303 checkDeletedIds(app, t, []string{
304 "user1_0",
305 "superuser2_2",
306 "superuser2_4",
307 "superuser3_1",

Callers

nothing calls this directly

Calls 10

CleanupMethod · 0.95
StubOTPRecordsFunction · 0.92
NewTestAppFunction · 0.92
NextMethod · 0.65
DeleteExpiredOTPsMethod · 0.65
SaveMethod · 0.65
BindFuncMethod · 0.45
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…