1
0
mirror of https://github.com/pocketbase/pocketbase.git synced 2025-04-16 21:49:51 +02:00

removed DrySubmit form errors wrapping and added more api tests

This commit is contained in:
Gani Georgiev 2022-11-01 00:28:33 +02:00
parent 5298543ce4
commit 9cef6ebd82
4 changed files with 32 additions and 8 deletions

View File

@ -227,14 +227,14 @@ func (api *recordApi) create(c echo.Context) error {
testErr := testForm.DrySubmit(func(txDao *daos.Dao) error { testErr := testForm.DrySubmit(func(txDao *daos.Dao) error {
foundRecord, err := txDao.FindRecordById(collection.Id, testRecord.Id, createRuleFunc) foundRecord, err := txDao.FindRecordById(collection.Id, testRecord.Id, createRuleFunc)
if err != nil { if err != nil {
return err return fmt.Errorf("DrySubmit create rule failure: %v", err)
} }
hasFullManageAccess = hasAuthManageAccess(txDao, foundRecord, requestData) hasFullManageAccess = hasAuthManageAccess(txDao, foundRecord, requestData)
return nil return nil
}) })
if testErr != nil { if testErr != nil {
return NewBadRequestError("Failed to create record.", fmt.Errorf("DrySubmit error: %v", testErr)) return NewBadRequestError("Failed to create record.", testErr)
} }
} }

View File

@ -818,6 +818,14 @@ func TestRecordCrudCreate(t *testing.T) {
ExpectedStatus: 403, ExpectedStatus: 403,
ExpectedContent: []string{`"data":{}`}, ExpectedContent: []string{`"data":{}`},
}, },
{
Name: "submit nil body",
Method: http.MethodPost,
Url: "/api/collections/demo2/records",
Body: nil,
ExpectedStatus: 400,
ExpectedContent: []string{`"data":{}`},
},
{ {
Name: "submit invalid format", Name: "submit invalid format",
Method: http.MethodPost, Method: http.MethodPost,
@ -827,12 +835,17 @@ func TestRecordCrudCreate(t *testing.T) {
ExpectedContent: []string{`"data":{}`}, ExpectedContent: []string{`"data":{}`},
}, },
{ {
Name: "submit nil body", Name: "submit empty json body",
Method: http.MethodPost, Method: http.MethodPost,
Url: "/api/collections/demo2/records", Url: "/api/collections/nologin/records",
Body: nil, Body: strings.NewReader(`{}`),
ExpectedStatus: 400, ExpectedStatus: 400,
ExpectedContent: []string{`"data":{}`}, ExpectedContent: []string{
`"data":{`,
`"email":{"code":"validation_required"`,
`"password":{"code":"validation_required"`,
`"passwordConfirm":{"code":"validation_required"`,
},
}, },
{ {
Name: "guest submit in public collection", Name: "guest submit in public collection",
@ -1316,6 +1329,17 @@ func TestRecordCrudUpdate(t *testing.T) {
"OnRecordBeforeUpdateRequest": 1, "OnRecordBeforeUpdateRequest": 1,
}, },
}, },
{
Name: "trigger field validation",
Method: http.MethodPatch,
Url: "/api/collections/demo2/records/0yxhwia2amd8gec",
Body: strings.NewReader(`{"title":"a"}`),
ExpectedStatus: 400,
ExpectedContent: []string{
`data":{`,
`"title":{"code":"validation_min_text_constraint"`,
},
},
{ {
Name: "guest submit in public collection", Name: "guest submit in public collection",
Method: http.MethodPatch, Method: http.MethodPatch,

Binary file not shown.

Binary file not shown.