Skip to content

Commit 9ff9c03

Browse files
committed
test: Add coverage for SeedDemoUsers skipping missing tenant schemas
Add TestSeedDemoUsers_SkipsMissingTenantSchema to cover the new ErrTenantSchemaNotProvisioned skip path. Uses schemaNotProvisioned flag on fakeRepo to simulate the missing-schema condition without requiring a real database.
1 parent 2a9b908 commit 9ff9c03

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

services/identity/bootstrap/demo_users_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88

99
"github.com/google/uuid"
1010
"github.com/meridianhub/meridian/services/identity/domain"
11+
"github.com/meridianhub/meridian/shared/platform/db"
1112
"github.com/meridianhub/meridian/shared/platform/tenant"
1213
"github.com/stretchr/testify/assert"
1314
"github.com/stretchr/testify/require"
@@ -19,6 +20,9 @@ type fakeRepo struct {
1920
roles map[uuid.UUID][]*domain.RoleAssignment // keyed by identity ID
2021

2122
saveWithRolesCalled bool
23+
// schemaNotProvisioned makes FindByEmail return ErrTenantSchemaNotProvisioned
24+
// for any email lookup, simulating a missing tenant schema.
25+
schemaNotProvisioned bool
2226
}
2327

2428
func newFakeRepo() *fakeRepo {
@@ -43,6 +47,9 @@ func (f *fakeRepo) FindByID(_ context.Context, id uuid.UUID) (*domain.Identity,
4347
}
4448

4549
func (f *fakeRepo) FindByEmail(_ context.Context, email string) (*domain.Identity, error) {
50+
if f.schemaNotProvisioned {
51+
return nil, db.ErrTenantSchemaNotProvisioned
52+
}
4653
if ident, ok := f.identities[email]; ok {
4754
return ident, nil
4855
}
@@ -240,3 +247,16 @@ func TestSeedDemoUsers_ReconcilesRole_ExistingUserMissingRole(t *testing.T) {
240247
require.Len(t, roles, 1)
241248
assert.Equal(t, domain.RoleOperator, roles[0].Role())
242249
}
250+
251+
func TestSeedDemoUsers_SkipsMissingTenantSchema(t *testing.T) {
252+
t.Setenv("DEMO_OPERATOR_EMAIL", "operator@volterra.energy")
253+
t.Setenv("DEMO_OPERATOR_PASSWORD", "demo2026")
254+
t.Setenv("DEMO_OPERATOR_TENANT", "missing_tenant")
255+
256+
repo := newFakeRepo()
257+
repo.schemaNotProvisioned = true
258+
259+
err := SeedDemoUsers(context.Background(), repo)
260+
require.NoError(t, err, "should skip tenants with missing schemas instead of failing")
261+
assert.False(t, repo.saveWithRolesCalled, "should not have attempted to save identity")
262+
}

0 commit comments

Comments
 (0)