MCPcopy
hub / github.com/pocketbase/pocketbase / TestFindOTPById

Function TestFindOTPById

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

Source from the content-addressed store, hash-verified

138}
139
140func TestFindOTPById(t *testing.T) {
141 t.Parallel()
142
143 app, _ := tests.NewTestApp()
144 defer app.Cleanup()
145
146 if err := tests.StubOTPRecords(app); err != nil {
147 t.Fatal(err)
148 }
149
150 scenarios := []struct {
151 id string
152 expectError bool
153 }{
154 {"", true},
155 {"84nmscqy84lsi1t", true}, // non-otp id
156 {"superuser2_0", false},
157 {"superuser2_4", false}, // expired
158 {"user1_0", false},
159 }
160
161 for _, s := range scenarios {
162 t.Run(s.id, func(t *testing.T) {
163 result, err := app.FindOTPById(s.id)
164
165 hasErr := err != nil
166 if hasErr != s.expectError {
167 t.Fatalf("Expected hasErr %v, got %v (%v)", s.expectError, hasErr, err)
168 }
169
170 if hasErr {
171 return
172 }
173
174 if result.Id != s.id {
175 t.Fatalf("Expected record with id %q, got %q", s.id, result.Id)
176 }
177 })
178 }
179}
180
181func TestDeleteAllOTPsByRecord(t *testing.T) {
182 t.Parallel()

Callers

nothing calls this directly

Calls 5

CleanupMethod · 0.95
NewTestAppFunction · 0.92
StubOTPRecordsFunction · 0.92
FindOTPByIdMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…