@@ -5,56 +5,42 @@ import (
55 "log/slog"
66 "testing"
77
8+ gateway "github.com/meridianhub/meridian/services/api-gateway"
89 "github.com/meridianhub/meridian/services/identity/domain"
910 tenantpersistence "github.com/meridianhub/meridian/services/tenant/adapters/persistence"
1011 "github.com/meridianhub/meridian/shared/platform/tenant"
1112 "github.com/stretchr/testify/assert"
12- "github.com/stretchr/testify/require"
1313)
1414
15- func TestNewSelfRegisteredAdminHook_Validation (t * testing.T ) {
16- logger := slog .Default ()
17-
18- _ , err := NewSelfRegisteredAdminHook (nil , & tenantpersistence.Repository {}, logger )
15+ func TestNewSelfRegisteredAdminHook_NilIdentityRepo (t * testing.T ) {
16+ _ , err := NewSelfRegisteredAdminHook (nil , & tenantpersistence.Repository {}, slog .Default ())
1917 assert .ErrorIs (t , err , ErrNilRepository )
18+ }
2019
21- // Can't easily test with a real identity repo since it requires a DB,
22- // but we verify that nil tenant repo is rejected.
23- // Note: We can't construct a non-nil domain.Repository without a DB connection,
24- // so we test the nil-identity-repo case only.
20+ // mockIdentityRepo satisfies domain.Repository for testing nil tenant repo validation.
21+ type mockIdentityRepo struct {
22+ domain.Repository
2523}
2624
27- func TestSelfRegisteredAdminHook_NoMetadata_IsNoop (t * testing.T ) {
28- // This tests the core logic: when tenant has no registration metadata,
29- // the hook should be a no-op.
30- //
31- // Full integration test would require a DB. Unit test verifies the
32- // metadata extraction logic by checking that Provision returns nil
33- // for tenants without registration metadata.
34- //
35- // This is tested indirectly through the provisioning worker integration tests.
36- t .Log ("self-registered admin hook with no metadata is a no-op - tested via integration" )
25+ func TestNewSelfRegisteredAdminHook_NilTenantRepo (t * testing.T ) {
26+ _ , err := NewSelfRegisteredAdminHook (& mockIdentityRepo {}, nil , slog .Default ())
27+ assert .ErrorIs (t , err , ErrNilTenantRepo )
3728}
3829
39- func TestMetadataKeyConstants (t * testing.T ) {
40- // Verify the metadata keys match between the registration handler and hook.
41- // These must stay in sync.
42- assert .Equal (t , "_registration_email" , metaKeyRegistrationEmail )
43- assert .Equal (t , "_registration_password_hash" , metaKeyRegistrationPasswordHash )
30+ func TestMetadataKeyConstants_InSyncWithGateway (t * testing.T ) {
31+ // These constants are duplicated across packages (identity/bootstrap and api-gateway)
32+ // because a circular import prevents direct sharing. This test ensures they stay in sync.
33+ assert .Equal (t , gateway .MetaKeyRegistrationEmail , MetaKeyRegistrationEmail ,
34+ "bootstrap.MetaKeyRegistrationEmail must match gateway.MetaKeyRegistrationEmail" )
35+ assert .Equal (t , gateway .MetaKeyRegistrationPasswordHash , MetaKeyRegistrationPasswordHash ,
36+ "bootstrap.MetaKeyRegistrationPasswordHash must match gateway.MetaKeyRegistrationPasswordHash" )
4437}
4538
4639func TestSelfRegisteredAdminHook_AsPostProvisioningHook (t * testing.T ) {
4740 // Verify the hook function signature is compatible with the provisioning worker.
48- // We can't create a real hook without DB connections, but we verify the
49- // function type matches what the worker expects.
5041 var hookFn func (ctx context.Context , tenantID tenant.TenantID ) error
5142 _ = hookFn // proves the type signature
5243
53- // Also verify the Identity creation logic with known constants.
54- tid , err := tenant .NewTenantID ("test_tenant" )
55- require .NoError (t , err )
56- assert .Equal (t , "test_tenant" , tid .String ())
57-
5844 // Verify RoleTenantOwner is the correct role for self-registered admins.
5945 assert .Equal (t , domain .Role ("TENANT_OWNER" ), domain .RoleTenantOwner )
6046}
0 commit comments