MCPcopy
hub / github.com/pocketbase/pocketbase / TestRecordSaveWithAutoTokenKeyRefresh

Function TestRecordSaveWithAutoTokenKeyRefresh

core/record_model_test.go:2147–2200  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

2145}
2146
2147func TestRecordSaveWithAutoTokenKeyRefresh(t *testing.T) {
2148 t.Parallel()
2149
2150 app, _ := tests.NewTestApp()
2151 defer app.Cleanup()
2152
2153 scenarios := []struct {
2154 name string
2155 payload map[string]any
2156 expectedChange bool
2157 }{
2158 {
2159 "no email or password change",
2160 map[string]any{"name": "example"},
2161 false,
2162 },
2163 {
2164 "password change",
2165 map[string]any{"password": "1234567890"},
2166 true,
2167 },
2168 {
2169 "email change",
2170 map[string]any{"email": "test_update@example.com"},
2171 true,
2172 },
2173 }
2174
2175 for _, s := range scenarios {
2176 t.Run(s.name, func(t *testing.T) {
2177 record, err := app.FindFirstRecordByFilter("nologin", "1=1")
2178 if err != nil {
2179 t.Fatal(err)
2180 }
2181
2182 originalTokenKey := record.TokenKey()
2183
2184 record.Load(s.payload)
2185
2186 err = app.Save(record)
2187 if err != nil {
2188 t.Fatal(err)
2189 }
2190
2191 newTokenKey := record.TokenKey()
2192
2193 hasChange := originalTokenKey != newTokenKey
2194
2195 if hasChange != s.expectedChange {
2196 t.Fatalf("Expected hasChange %v, got %v", s.expectedChange, hasChange)
2197 }
2198 })
2199 }
2200}
2201
2202func TestRecordDelete(t *testing.T) {
2203 t.Parallel()

Callers

nothing calls this directly

Calls 7

CleanupMethod · 0.95
NewTestAppFunction · 0.92
TokenKeyMethod · 0.80
SaveMethod · 0.65
RunMethod · 0.45
LoadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…