[#3025] updated tests.ApiScenario fields
This commit is contained in:
parent
4f3d1682de
commit
311bc74b7e
22
CHANGELOG.md
22
CHANGELOG.md
|
@ -66,6 +66,27 @@
|
||||||
$security.sha512(text)
|
$security.sha512(text)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- ⚠️ Changes to `tests.ApiScenario` struct:
|
||||||
|
|
||||||
|
- The `ApiScenario.AfterTestFunc` now receive as 3rd argument `*http.Response` pointer instead of `*echo.Echo` as the latter is not really useful in this context.
|
||||||
|
```go
|
||||||
|
// old
|
||||||
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo)
|
||||||
|
|
||||||
|
// new
|
||||||
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response)
|
||||||
|
```
|
||||||
|
|
||||||
|
- The `ApiScenario.TestAppFactory` now accept the test instance as argument and no longer expect an error as return result ([#3025](https://github.com/pocketbase/pocketbase/discussions/3025#discussioncomment-6592272)).
|
||||||
|
```go
|
||||||
|
// old
|
||||||
|
TestAppFactory: func() (*tests.TestApp, error)
|
||||||
|
|
||||||
|
// new
|
||||||
|
TestAppFactory: func(t *testing.T) *tests.TestApp
|
||||||
|
```
|
||||||
|
_Returning a `nil` app instance from the factory results in test failure._
|
||||||
|
|
||||||
- Fill the `LastVerificationSentAt` and `LastResetSentAt` fields only after a successfull email send ([#3121](https://github.com/pocketbase/pocketbase/issues/3121)).
|
- Fill the `LastVerificationSentAt` and `LastResetSentAt` fields only after a successfull email send ([#3121](https://github.com/pocketbase/pocketbase/issues/3121)).
|
||||||
|
|
||||||
- Skip API `fields` json transformations for non 20x responses ([#3176](https://github.com/pocketbase/pocketbase/issues/3176)).
|
- Skip API `fields` json transformations for non 20x responses ([#3176](https://github.com/pocketbase/pocketbase/issues/3176)).
|
||||||
|
@ -79,6 +100,7 @@
|
||||||
- Reflected the latest JS SDK changes in the Admin UI.
|
- Reflected the latest JS SDK changes in the Admin UI.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
## v0.17.7
|
## v0.17.7
|
||||||
|
|
||||||
- Fixed the autogenerated `down` migrations to properly revert the old collection rules in case a change was made in `up` ([#3192](https://github.com/pocketbase/pocketbase/pull/3192); thanks @impact-merlinmarek).
|
- Fixed the autogenerated `down` migrations to properly revert the old collection rules in case a change was made in `up` ([#3192](https://github.com/pocketbase/pocketbase/pull/3192); thanks @impact-merlinmarek).
|
||||||
|
|
|
@ -85,7 +85,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||||
Name: "unauthorized",
|
Name: "unauthorized",
|
||||||
Method: http.MethodPost,
|
Method: http.MethodPost,
|
||||||
Url: "/api/backups",
|
Url: "/api/backups",
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
ensureNoBackups(t, app)
|
ensureNoBackups(t, app)
|
||||||
},
|
},
|
||||||
ExpectedStatus: 401,
|
ExpectedStatus: 401,
|
||||||
|
@ -98,7 +98,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||||
RequestHeaders: map[string]string{
|
RequestHeaders: map[string]string{
|
||||||
"Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyMjA4OTg1MjYxfQ.UwD8JvkbQtXpymT09d7J6fdA0aP9g4FJ1GPh_ggEkzc",
|
"Authorization": "eyJhbGciOiJIUzI1NiJ9.eyJpZCI6IjRxMXhsY2xtZmxva3UzMyIsInR5cGUiOiJhdXRoUmVjb3JkIiwiY29sbGVjdGlvbklkIjoiX3BiX3VzZXJzX2F1dGhfIiwiZXhwIjoyMjA4OTg1MjYxfQ.UwD8JvkbQtXpymT09d7J6fdA0aP9g4FJ1GPh_ggEkzc",
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
ensureNoBackups(t, app)
|
ensureNoBackups(t, app)
|
||||||
},
|
},
|
||||||
ExpectedStatus: 401,
|
ExpectedStatus: 401,
|
||||||
|
@ -114,7 +114,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||||
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||||
app.Cache().Set(core.CacheKeyActiveBackup, "")
|
app.Cache().Set(core.CacheKeyActiveBackup, "")
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
ensureNoBackups(t, app)
|
ensureNoBackups(t, app)
|
||||||
},
|
},
|
||||||
ExpectedStatus: 400,
|
ExpectedStatus: 400,
|
||||||
|
@ -127,7 +127,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||||
RequestHeaders: map[string]string{
|
RequestHeaders: map[string]string{
|
||||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
files, err := getBackupFiles(app)
|
files, err := getBackupFiles(app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -152,7 +152,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||||
RequestHeaders: map[string]string{
|
RequestHeaders: map[string]string{
|
||||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
ensureNoBackups(t, app)
|
ensureNoBackups(t, app)
|
||||||
},
|
},
|
||||||
ExpectedStatus: 400,
|
ExpectedStatus: 400,
|
||||||
|
@ -169,7 +169,7 @@ func TestBackupsCreate(t *testing.T) {
|
||||||
RequestHeaders: map[string]string{
|
RequestHeaders: map[string]string{
|
||||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
files, err := getBackupFiles(app)
|
files, err := getBackupFiles(app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -371,7 +371,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
noTestBackupFilesChanges(t, app)
|
noTestBackupFilesChanges(t, app)
|
||||||
},
|
},
|
||||||
ExpectedStatus: 401,
|
ExpectedStatus: 401,
|
||||||
|
@ -389,7 +389,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
noTestBackupFilesChanges(t, app)
|
noTestBackupFilesChanges(t, app)
|
||||||
},
|
},
|
||||||
ExpectedStatus: 401,
|
ExpectedStatus: 401,
|
||||||
|
@ -407,7 +407,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
noTestBackupFilesChanges(t, app)
|
noTestBackupFilesChanges(t, app)
|
||||||
},
|
},
|
||||||
ExpectedStatus: 400,
|
ExpectedStatus: 400,
|
||||||
|
@ -428,7 +428,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||||
// mock active backup with the same name to delete
|
// mock active backup with the same name to delete
|
||||||
app.Cache().Set(core.CacheKeyActiveBackup, "test1.zip")
|
app.Cache().Set(core.CacheKeyActiveBackup, "test1.zip")
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
noTestBackupFilesChanges(t, app)
|
noTestBackupFilesChanges(t, app)
|
||||||
},
|
},
|
||||||
ExpectedStatus: 400,
|
ExpectedStatus: 400,
|
||||||
|
@ -449,7 +449,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||||
// mock active backup with different name
|
// mock active backup with different name
|
||||||
app.Cache().Set(core.CacheKeyActiveBackup, "new.zip")
|
app.Cache().Set(core.CacheKeyActiveBackup, "new.zip")
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
files, err := getBackupFiles(app)
|
files, err := getBackupFiles(app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -481,7 +481,7 @@ func TestBackupsDelete(t *testing.T) {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
files, err := getBackupFiles(app)
|
files, err := getBackupFiles(app)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -245,7 +245,7 @@ func TestCollectionDelete(t *testing.T) {
|
||||||
"OnCollectionBeforeDeleteRequest": 1,
|
"OnCollectionBeforeDeleteRequest": 1,
|
||||||
"OnCollectionAfterDeleteRequest": 1,
|
"OnCollectionAfterDeleteRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
ensureDeletedFiles(app, "9n89pl5vkct6330")
|
ensureDeletedFiles(app, "9n89pl5vkct6330")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -264,7 +264,7 @@ func TestCollectionDelete(t *testing.T) {
|
||||||
"OnCollectionBeforeDeleteRequest": 1,
|
"OnCollectionBeforeDeleteRequest": 1,
|
||||||
"OnCollectionAfterDeleteRequest": 1,
|
"OnCollectionAfterDeleteRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
ensureDeletedFiles(app, "9n89pl5vkct6330")
|
ensureDeletedFiles(app, "9n89pl5vkct6330")
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -693,7 +693,7 @@ func TestCollectionCreate(t *testing.T) {
|
||||||
"OnCollectionBeforeCreateRequest": 1,
|
"OnCollectionBeforeCreateRequest": 1,
|
||||||
"OnCollectionAfterCreateRequest": 1,
|
"OnCollectionAfterCreateRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
indexes, err := app.Dao().TableIndexes("new")
|
indexes, err := app.Dao().TableIndexes("new")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -823,7 +823,7 @@ func TestCollectionUpdate(t *testing.T) {
|
||||||
"OnCollectionBeforeUpdateRequest": 1,
|
"OnCollectionBeforeUpdateRequest": 1,
|
||||||
"OnCollectionAfterUpdateRequest": 1,
|
"OnCollectionAfterUpdateRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
// check if the record table was renamed
|
// check if the record table was renamed
|
||||||
if !app.Dao().HasTable("new") {
|
if !app.Dao().HasTable("new") {
|
||||||
t.Fatal("Couldn't find record table 'new'.")
|
t.Fatal("Couldn't find record table 'new'.")
|
||||||
|
@ -1060,7 +1060,7 @@ func TestCollectionUpdate(t *testing.T) {
|
||||||
"OnCollectionBeforeUpdateRequest": 1,
|
"OnCollectionBeforeUpdateRequest": 1,
|
||||||
"OnCollectionAfterUpdateRequest": 1,
|
"OnCollectionAfterUpdateRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
indexes, err := app.Dao().TableIndexes("new")
|
indexes, err := app.Dao().TableIndexes("new")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1115,7 +1115,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||||
`"data":{`,
|
`"data":{`,
|
||||||
`"collections":{"code":"validation_required"`,
|
`"collections":{"code":"validation_required"`,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
collections := []*models.Collection{}
|
collections := []*models.Collection{}
|
||||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1143,7 +1143,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||||
"OnCollectionsBeforeImportRequest": 1,
|
"OnCollectionsBeforeImportRequest": 1,
|
||||||
"OnModelBeforeDelete": 4,
|
"OnModelBeforeDelete": 4,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
collections := []*models.Collection{}
|
collections := []*models.Collection{}
|
||||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1185,7 +1185,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||||
"OnCollectionsBeforeImportRequest": 1,
|
"OnCollectionsBeforeImportRequest": 1,
|
||||||
"OnModelBeforeCreate": 2,
|
"OnModelBeforeCreate": 2,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
collections := []*models.Collection{}
|
collections := []*models.Collection{}
|
||||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1241,7 +1241,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||||
"OnModelBeforeCreate": 3,
|
"OnModelBeforeCreate": 3,
|
||||||
"OnModelAfterCreate": 3,
|
"OnModelAfterCreate": 3,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
collections := []*models.Collection{}
|
collections := []*models.Collection{}
|
||||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1346,7 +1346,7 @@ func TestCollectionsImport(t *testing.T) {
|
||||||
"OnModelBeforeCreate": 1,
|
"OnModelBeforeCreate": 1,
|
||||||
"OnModelAfterCreate": 1,
|
"OnModelAfterCreate": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
collections := []*models.Collection{}
|
collections := []*models.Collection{}
|
||||||
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
if err := app.Dao().CollectionQuery().All(&collections); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -34,7 +34,7 @@ func TestRealtimeConnect(t *testing.T) {
|
||||||
"OnRealtimeAfterMessageSend": 1,
|
"OnRealtimeAfterMessageSend": 1,
|
||||||
"OnRealtimeDisconnectRequest": 1,
|
"OnRealtimeDisconnectRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
if len(app.SubscriptionsBroker().Clients()) != 0 {
|
if len(app.SubscriptionsBroker().Clients()) != 0 {
|
||||||
t.Errorf("Expected the subscribers to be removed after connection close, found %d", len(app.SubscriptionsBroker().Clients()))
|
t.Errorf("Expected the subscribers to be removed after connection close, found %d", len(app.SubscriptionsBroker().Clients()))
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ func TestRealtimeConnect(t *testing.T) {
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
if len(app.SubscriptionsBroker().Clients()) != 0 {
|
if len(app.SubscriptionsBroker().Clients()) != 0 {
|
||||||
t.Errorf("Expected the subscribers to be removed after connection close, found %d", len(app.SubscriptionsBroker().Clients()))
|
t.Errorf("Expected the subscribers to be removed after connection close, found %d", len(app.SubscriptionsBroker().Clients()))
|
||||||
}
|
}
|
||||||
|
@ -79,7 +79,7 @@ func TestRealtimeConnect(t *testing.T) {
|
||||||
return hook.StopPropagation
|
return hook.StopPropagation
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
if len(app.SubscriptionsBroker().Clients()) != 0 {
|
if len(app.SubscriptionsBroker().Clients()) != 0 {
|
||||||
t.Errorf("Expected the subscribers to be removed after connection close, found %d", len(app.SubscriptionsBroker().Clients()))
|
t.Errorf("Expected the subscribers to be removed after connection close, found %d", len(app.SubscriptionsBroker().Clients()))
|
||||||
}
|
}
|
||||||
|
@ -124,7 +124,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||||
client.Subscribe("test0")
|
client.Subscribe("test0")
|
||||||
app.SubscriptionsBroker().Register(client)
|
app.SubscriptionsBroker().Register(client)
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
if len(client.Subscriptions()) != 0 {
|
if len(client.Subscriptions()) != 0 {
|
||||||
t.Errorf("Expected no subscriptions, got %v", client.Subscriptions())
|
t.Errorf("Expected no subscriptions, got %v", client.Subscriptions())
|
||||||
}
|
}
|
||||||
|
@ -145,7 +145,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||||
client.Subscribe("test0")
|
client.Subscribe("test0")
|
||||||
app.SubscriptionsBroker().Register(client)
|
app.SubscriptionsBroker().Register(client)
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
expectedSubs := []string{"test1", "test2"}
|
expectedSubs := []string{"test1", "test2"}
|
||||||
if len(expectedSubs) != len(client.Subscriptions()) {
|
if len(expectedSubs) != len(client.Subscriptions()) {
|
||||||
t.Errorf("Expected subscriptions %v, got %v", expectedSubs, client.Subscriptions())
|
t.Errorf("Expected subscriptions %v, got %v", expectedSubs, client.Subscriptions())
|
||||||
|
@ -175,7 +175,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||||
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||||
app.SubscriptionsBroker().Register(client)
|
app.SubscriptionsBroker().Register(client)
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
admin, _ := client.Get(apis.ContextAdminKey).(*models.Admin)
|
admin, _ := client.Get(apis.ContextAdminKey).(*models.Admin)
|
||||||
if admin == nil {
|
if admin == nil {
|
||||||
t.Errorf("Expected admin auth model, got nil")
|
t.Errorf("Expected admin auth model, got nil")
|
||||||
|
@ -199,7 +199,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||||
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
BeforeTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
||||||
app.SubscriptionsBroker().Register(client)
|
app.SubscriptionsBroker().Register(client)
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
authRecord, _ := client.Get(apis.ContextAuthRecordKey).(*models.Record)
|
authRecord, _ := client.Get(apis.ContextAuthRecordKey).(*models.Record)
|
||||||
if authRecord == nil {
|
if authRecord == nil {
|
||||||
t.Errorf("Expected auth record model, got nil")
|
t.Errorf("Expected auth record model, got nil")
|
||||||
|
@ -224,7 +224,7 @@ func TestRealtimeSubscribe(t *testing.T) {
|
||||||
|
|
||||||
app.SubscriptionsBroker().Register(client)
|
app.SubscriptionsBroker().Register(client)
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
authRecord, _ := client.Get(apis.ContextAuthRecordKey).(*models.Record)
|
authRecord, _ := client.Get(apis.ContextAuthRecordKey).(*models.Record)
|
||||||
if authRecord == nil {
|
if authRecord == nil {
|
||||||
t.Errorf("Expected auth record model, got nil")
|
t.Errorf("Expected auth record model, got nil")
|
||||||
|
|
|
@ -1188,7 +1188,7 @@ func TestRecordAuthUnlinkExternalsAuth(t *testing.T) {
|
||||||
"OnRecordAfterUnlinkExternalAuthRequest": 1,
|
"OnRecordAfterUnlinkExternalAuthRequest": 1,
|
||||||
"OnRecordBeforeUnlinkExternalAuthRequest": 1,
|
"OnRecordBeforeUnlinkExternalAuthRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
record, err := app.Dao().FindRecordById("users", "4q1xlclmfloku33")
|
record, err := app.Dao().FindRecordById("users", "4q1xlclmfloku33")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
@ -1234,7 +1234,7 @@ func TestRecordAuthUnlinkExternalsAuth(t *testing.T) {
|
||||||
"OnRecordAfterUnlinkExternalAuthRequest": 1,
|
"OnRecordAfterUnlinkExternalAuthRequest": 1,
|
||||||
"OnRecordBeforeUnlinkExternalAuthRequest": 1,
|
"OnRecordBeforeUnlinkExternalAuthRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
record, err := app.Dao().FindRecordById("users", "4q1xlclmfloku33")
|
record, err := app.Dao().FindRecordById("users", "4q1xlclmfloku33")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
|
|
|
@ -903,7 +903,7 @@ func TestRecordCrudDelete(t *testing.T) {
|
||||||
"OnRecordAfterDeleteRequest": 1,
|
"OnRecordAfterDeleteRequest": 1,
|
||||||
"OnRecordBeforeDeleteRequest": 1,
|
"OnRecordBeforeDeleteRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
ensureDeletedFiles(app, "_pb_users_auth_", "4q1xlclmfloku33")
|
ensureDeletedFiles(app, "_pb_users_auth_", "4q1xlclmfloku33")
|
||||||
|
|
||||||
// check if all the external auths records were deleted
|
// check if all the external auths records were deleted
|
||||||
|
@ -990,7 +990,7 @@ func TestRecordCrudDelete(t *testing.T) {
|
||||||
"OnRecordBeforeDeleteRequest": 1,
|
"OnRecordBeforeDeleteRequest": 1,
|
||||||
"OnRecordAfterDeleteRequest": 1,
|
"OnRecordAfterDeleteRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
recId := "84nmscqy84lsi1t"
|
recId := "84nmscqy84lsi1t"
|
||||||
rec, _ := app.Dao().FindRecordById("demo1", recId, nil)
|
rec, _ := app.Dao().FindRecordById("demo1", recId, nil)
|
||||||
if rec != nil {
|
if rec != nil {
|
||||||
|
@ -2032,7 +2032,7 @@ func TestRecordCrudUpdate(t *testing.T) {
|
||||||
"OnRecordAfterUpdateRequest": 1,
|
"OnRecordAfterUpdateRequest": 1,
|
||||||
"OnRecordBeforeUpdateRequest": 1,
|
"OnRecordBeforeUpdateRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
record, _ := app.Dao().FindRecordById("nologin", "phhq3wr65cap535")
|
record, _ := app.Dao().FindRecordById("nologin", "phhq3wr65cap535")
|
||||||
if !record.ValidatePassword("12345678") {
|
if !record.ValidatePassword("12345678") {
|
||||||
t.Fatal("Password update failed.")
|
t.Fatal("Password update failed.")
|
||||||
|
@ -2075,7 +2075,7 @@ func TestRecordCrudUpdate(t *testing.T) {
|
||||||
"OnRecordAfterUpdateRequest": 1,
|
"OnRecordAfterUpdateRequest": 1,
|
||||||
"OnRecordBeforeUpdateRequest": 1,
|
"OnRecordBeforeUpdateRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
record, _ := app.Dao().FindRecordById("users", "oap640cot4yru2s")
|
record, _ := app.Dao().FindRecordById("users", "oap640cot4yru2s")
|
||||||
if !record.ValidatePassword("12345678") {
|
if !record.ValidatePassword("12345678") {
|
||||||
t.Fatal("Password update failed.")
|
t.Fatal("Password update failed.")
|
||||||
|
@ -2137,7 +2137,7 @@ func TestRecordCrudUpdate(t *testing.T) {
|
||||||
"OnRecordAfterUpdateRequest": 1,
|
"OnRecordAfterUpdateRequest": 1,
|
||||||
"OnRecordBeforeUpdateRequest": 1,
|
"OnRecordBeforeUpdateRequest": 1,
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
record, _ := app.Dao().FindRecordById("nologin", "dc49k6jgejn40h3")
|
record, _ := app.Dao().FindRecordById("nologin", "dc49k6jgejn40h3")
|
||||||
if !record.ValidatePassword("123456789") {
|
if !record.ValidatePassword("123456789") {
|
||||||
t.Fatal("Password update failed.")
|
t.Fatal("Password update failed.")
|
||||||
|
|
|
@ -400,7 +400,7 @@ func TestSettingsTestEmail(t *testing.T) {
|
||||||
RequestHeaders: map[string]string{
|
RequestHeaders: map[string]string{
|
||||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
if app.TestMailer.TotalSend != 1 {
|
if app.TestMailer.TotalSend != 1 {
|
||||||
t.Fatalf("[verification] Expected 1 sent email, got %d", app.TestMailer.TotalSend)
|
t.Fatalf("[verification] Expected 1 sent email, got %d", app.TestMailer.TotalSend)
|
||||||
}
|
}
|
||||||
|
@ -435,7 +435,7 @@ func TestSettingsTestEmail(t *testing.T) {
|
||||||
RequestHeaders: map[string]string{
|
RequestHeaders: map[string]string{
|
||||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
if app.TestMailer.TotalSend != 1 {
|
if app.TestMailer.TotalSend != 1 {
|
||||||
t.Fatalf("[password-reset] Expected 1 sent email, got %d", app.TestMailer.TotalSend)
|
t.Fatalf("[password-reset] Expected 1 sent email, got %d", app.TestMailer.TotalSend)
|
||||||
}
|
}
|
||||||
|
@ -470,7 +470,7 @@ func TestSettingsTestEmail(t *testing.T) {
|
||||||
RequestHeaders: map[string]string{
|
RequestHeaders: map[string]string{
|
||||||
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
"Authorization": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6InN5d2JoZWNuaDQ2cmhtMCIsInR5cGUiOiJhZG1pbiIsImV4cCI6MjIwODk4NTI2MX0.M1m--VOqGyv0d23eeUc0r9xE8ZzHaYVmVFw1VZW6gT8",
|
||||||
},
|
},
|
||||||
AfterTestFunc: func(t *testing.T, app *tests.TestApp, e *echo.Echo) {
|
AfterTestFunc: func(t *testing.T, app *tests.TestApp, res *http.Response) {
|
||||||
if app.TestMailer.TotalSend != 1 {
|
if app.TestMailer.TotalSend != 1 {
|
||||||
t.Fatalf("[email-change] Expected 1 sent email, got %d", app.TestMailer.TotalSend)
|
t.Fatalf("[email-change] Expected 1 sent email, got %d", app.TestMailer.TotalSend)
|
||||||
}
|
}
|
||||||
|
|
21
tests/api.go
21
tests/api.go
|
@ -6,6 +6,7 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
"net/http"
|
||||||
"net/http/httptest"
|
"net/http/httptest"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
@ -37,9 +38,9 @@ type ApiScenario struct {
|
||||||
|
|
||||||
// test hooks
|
// test hooks
|
||||||
// ---
|
// ---
|
||||||
TestAppFactory func() (*TestApp, error)
|
TestAppFactory func(t *testing.T) *TestApp
|
||||||
BeforeTestFunc func(t *testing.T, app *TestApp, e *echo.Echo)
|
BeforeTestFunc func(t *testing.T, app *TestApp, e *echo.Echo)
|
||||||
AfterTestFunc func(t *testing.T, app *TestApp, e *echo.Echo)
|
AfterTestFunc func(t *testing.T, app *TestApp, res *http.Response)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test executes the test scenario.
|
// Test executes the test scenario.
|
||||||
|
@ -54,17 +55,18 @@ func (scenario *ApiScenario) Test(t *testing.T) {
|
||||||
|
|
||||||
func (scenario *ApiScenario) test(t *testing.T) {
|
func (scenario *ApiScenario) test(t *testing.T) {
|
||||||
var testApp *TestApp
|
var testApp *TestApp
|
||||||
var testAppErr error
|
|
||||||
if scenario.TestAppFactory != nil {
|
if scenario.TestAppFactory != nil {
|
||||||
// @todo consider passing the testing instance to the factory and maybe remove the error from the declaration
|
testApp = scenario.TestAppFactory(t)
|
||||||
// (see https://github.com/pocketbase/pocketbase/discussions/3025)
|
if testApp == nil {
|
||||||
testApp, testAppErr = scenario.TestAppFactory()
|
t.Fatal("TestAppFactory must return a non-nill app instance")
|
||||||
} else {
|
|
||||||
testApp, testAppErr = NewTestApp()
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
var testAppErr error
|
||||||
|
testApp, testAppErr = NewTestApp()
|
||||||
if testAppErr != nil {
|
if testAppErr != nil {
|
||||||
t.Fatalf("Failed to initialize the test app instance: %v", testAppErr)
|
t.Fatalf("Failed to initialize the test app instance: %v", testAppErr)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
defer testApp.Cleanup()
|
defer testApp.Cleanup()
|
||||||
|
|
||||||
e, err := apis.InitApi(testApp)
|
e, err := apis.InitApi(testApp)
|
||||||
|
@ -172,8 +174,7 @@ func (scenario *ApiScenario) test(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @todo consider adding the response body to the AfterTestFunc args
|
|
||||||
if scenario.AfterTestFunc != nil {
|
if scenario.AfterTestFunc != nil {
|
||||||
scenario.AfterTestFunc(t, testApp, e)
|
scenario.AfterTestFunc(t, testApp, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue