mirror of
https://github.com/pocketbase/pocketbase.git
synced 2025-03-18 21:57:50 +02:00
updated tests
This commit is contained in:
parent
5dbf975424
commit
dbc074ee9a
@ -115,6 +115,18 @@ func TestSyncRecordTableSchema(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func getTotalViews(app core.App) (int, error) {
|
||||
var total int
|
||||
|
||||
err := app.DB().Select("count(*)").
|
||||
From("sqlite_master").
|
||||
AndWhere(dbx.NewExp("sql is not null")).
|
||||
AndWhere(dbx.HashExp{"type": "view"}).
|
||||
Row(&total)
|
||||
|
||||
return total, err
|
||||
}
|
||||
|
||||
func TestSingleVsMultipleValuesNormalization(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@ -126,6 +138,11 @@ func TestSingleVsMultipleValuesNormalization(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
beforeTotalViews, err := getTotalViews(app)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// mock field changes
|
||||
collection.Fields.GetByName("select_one").(*core.SelectField).MaxSelect = 2
|
||||
collection.Fields.GetByName("select_many").(*core.SelectField).MaxSelect = 1
|
||||
@ -146,11 +163,13 @@ func TestSingleVsMultipleValuesNormalization(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
// ensures that the writable schema was reverted to its expected default
|
||||
var writableSchema bool
|
||||
app.DB().NewQuery("PRAGMA writable_schema").Row(&writableSchema)
|
||||
if writableSchema == true {
|
||||
t.Fatalf("Expected writable_schema to be OFF, got %v", writableSchema)
|
||||
// ensure that the views were reinserted
|
||||
afterTotalViews, err := getTotalViews(app)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if afterTotalViews != beforeTotalViews {
|
||||
t.Fatalf("Expected total views %d, got %d", beforeTotalViews, afterTotalViews)
|
||||
}
|
||||
|
||||
// check whether the columns DEFAULT definition was updated
|
||||
|
@ -141,7 +141,7 @@ func (app *BaseApp) delete(ctx context.Context, model Model, isForAuxDB bool) er
|
||||
})
|
||||
if deleteErr != nil {
|
||||
errEvent := &ModelErrorEvent{ModelEvent: *event, Error: deleteErr}
|
||||
errEvent.App = app
|
||||
errEvent.App = app // replace with the initial app in case it was changed by the hook
|
||||
hookErr := app.OnModelAfterDeleteError().Trigger(errEvent)
|
||||
if hookErr != nil {
|
||||
return errors.Join(deleteErr, hookErr)
|
||||
@ -332,7 +332,7 @@ func (app *BaseApp) create(ctx context.Context, model Model, withValidations boo
|
||||
event.Model.MarkAsNew() // reset "new" state
|
||||
|
||||
errEvent := &ModelErrorEvent{ModelEvent: *event, Error: saveErr}
|
||||
errEvent.App = app
|
||||
errEvent.App = app // replace with the initial app in case it was changed by the hook
|
||||
hookErr := app.OnModelAfterCreateError().Trigger(errEvent)
|
||||
if hookErr != nil {
|
||||
return errors.Join(saveErr, hookErr)
|
||||
@ -416,7 +416,7 @@ func (app *BaseApp) update(ctx context.Context, model Model, withValidations boo
|
||||
})
|
||||
if saveErr != nil {
|
||||
errEvent := &ModelErrorEvent{ModelEvent: *event, Error: saveErr}
|
||||
errEvent.App = app
|
||||
errEvent.App = app // replace with the initial app in case it was changed by the hook
|
||||
hookErr := app.OnModelAfterUpdateError().Trigger(errEvent)
|
||||
if hookErr != nil {
|
||||
return errors.Join(saveErr, hookErr)
|
||||
|
Loading…
x
Reference in New Issue
Block a user