refactor(hub): harden/enforce pb api rules and add tests

- separate collection related code from hub.go
- ensure hub is bootstrapped and collections updated automatically when
calling NewHub
This commit is contained in:
henrygd
2026-03-20 14:39:05 -04:00
parent adbfe7cfb7
commit 565162ef5f
9 changed files with 756 additions and 169 deletions

View File

@@ -52,7 +52,10 @@ func NewTestHubWithConfig(config core.BaseAppConfig) (*TestHub, error) {
return nil, err
}
hub := hub.NewHub(testApp)
hub, err := hub.NewHub(testApp)
if err != nil {
return nil, err
}
t := &TestHub{
App: testApp,
@@ -77,6 +80,16 @@ func CreateUser(app core.App, email string, password string) (*core.Record, erro
return user, app.Save(user)
}
func CreateUserWithRole(app core.App, email string, password string, roleName string) (*core.Record, error) {
user, err := CreateUser(app, email, password)
if err != nil {
return nil, err
}
user.Set("role", roleName)
return user, app.Save(user)
}
// Helper function to create a test record
func CreateRecord(app core.App, collectionName string, fields map[string]any) (*core.Record, error) {
collection, err := app.FindCachedCollectionByNameOrId(collectionName)