Skip to content

Commit

Permalink
removed DrySubmit form errors wrapping and added more api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ganigeorgiev committed Oct 31, 2022
1 parent 5298543 commit 9cef6eb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 6 deletions.
4 changes: 2 additions & 2 deletions apis/record_crud.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,14 +227,14 @@ func (api *recordApi) create(c echo.Context) error {
testErr := testForm.DrySubmit(func(txDao *daos.Dao) error {
foundRecord, err := txDao.FindRecordById(collection.Id, testRecord.Id, createRuleFunc)
if err != nil {
return err
return fmt.Errorf("DrySubmit create rule failure: %v", err)
}
hasFullManageAccess = hasAuthManageAccess(txDao, foundRecord, requestData)
return nil
})

if testErr != nil {
return NewBadRequestError("Failed to create record.", fmt.Errorf("DrySubmit error: %v", testErr))
return NewBadRequestError("Failed to create record.", testErr)
}
}

Expand Down
32 changes: 28 additions & 4 deletions apis/record_crud_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -819,21 +819,34 @@ func TestRecordCrudCreate(t *testing.T) {
ExpectedContent: []string{`"data":{}`},
},
{
Name: "submit invalid format",
Name: "submit nil body",
Method: http.MethodPost,
Url: "/api/collections/demo2/records",
Body: strings.NewReader(`{"`),
Body: nil,
ExpectedStatus: 400,
ExpectedContent: []string{`"data":{}`},
},
{
Name: "submit nil body",
Name: "submit invalid format",
Method: http.MethodPost,
Url: "/api/collections/demo2/records",
Body: nil,
Body: strings.NewReader(`{"`),
ExpectedStatus: 400,
ExpectedContent: []string{`"data":{}`},
},
{
Name: "submit empty json body",
Method: http.MethodPost,
Url: "/api/collections/nologin/records",
Body: strings.NewReader(`{}`),
ExpectedStatus: 400,
ExpectedContent: []string{
`"data":{`,
`"email":{"code":"validation_required"`,
`"password":{"code":"validation_required"`,
`"passwordConfirm":{"code":"validation_required"`,
},
},
{
Name: "guest submit in public collection",
Method: http.MethodPost,
Expand Down Expand Up @@ -1316,6 +1329,17 @@ func TestRecordCrudUpdate(t *testing.T) {
"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",
Method: http.MethodPatch,
Expand Down
Binary file modified tests/data/data.db
Binary file not shown.
Binary file modified tests/data/logs.db
Binary file not shown.

0 comments on commit 9cef6eb

Please sign in to comment.