MCPcopy
hub / github.com/pocketbase/pocketbase / TestRelationFieldValidateValue

Function TestRelationFieldValidateValue

core/field_relation_test.go:196–346  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

194}
195
196func TestRelationFieldValidateValue(t *testing.T) {
197 app, _ := tests.NewTestApp()
198 defer app.Cleanup()
199
200 demo1, err := app.FindCollectionByNameOrId("demo1")
201 if err != nil {
202 t.Fatal(err)
203 }
204
205 scenarios := []struct {
206 name string
207 field *core.RelationField
208 record func() *core.Record
209 expectError bool
210 }{
211 // single
212 {
213 "[single] zero field value (not required)",
214 &core.RelationField{Name: "test", MaxSelect: 1, CollectionId: demo1.Id},
215 func() *core.Record {
216 record := core.NewRecord(core.NewBaseCollection("test_collection"))
217 record.SetRaw("test", "")
218 return record
219 },
220 false,
221 },
222 {
223 "[single] zero field value (required)",
224 &core.RelationField{Name: "test", MaxSelect: 1, CollectionId: demo1.Id, Required: true},
225 func() *core.Record {
226 record := core.NewRecord(core.NewBaseCollection("test_collection"))
227 record.SetRaw("test", "")
228 return record
229 },
230 true,
231 },
232 {
233 "[single] id from other collection",
234 &core.RelationField{Name: "test", MaxSelect: 1, CollectionId: demo1.Id},
235 func() *core.Record {
236 record := core.NewRecord(core.NewBaseCollection("test_collection"))
237 record.SetRaw("test", "achvryl401bhse3")
238 return record
239 },
240 true,
241 },
242 {
243 "[single] valid id",
244 &core.RelationField{Name: "test", MaxSelect: 1, CollectionId: demo1.Id},
245 func() *core.Record {
246 record := core.NewRecord(core.NewBaseCollection("test_collection"))
247 record.SetRaw("test", "84nmscqy84lsi1t")
248 return record
249 },
250 false,
251 },
252 {
253 "[single] > MaxSelect",

Callers

nothing calls this directly

Calls 8

CleanupMethod · 0.95
SetRawMethod · 0.95
NewTestAppFunction · 0.92
NewRecordFunction · 0.92
NewBaseCollectionFunction · 0.92
ValidateValueMethod · 0.65
RunMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…