fix(tenants): set NOT-NULL kind in create_tenant; add regression test #221
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/pms-287-create-tenant-kind"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Fixes
TenantService::create_tenant, which omitted the NOT-NULLtenants.kindcolumn. Closes PMS-287.Migration
019_tenant_kindaddskind NOT NULLand then drops the column default ("the column is otherwise required and callers always set it explicitly").create_tenant's INSERT did not, so it failed with SQLSTATE23502andPOST /api/v1/tenants500'd. Latent because no test exercised that insert path -tests/tenants.rsprovisions viaensure_personal_tenantand seed helpers, both of which setkind. Surfaced while writing the PMS-236 isolation suite.Change
src/modules/tenants/service.rs: addkindto the INSERT with the value'org'(the admin/multi-user org-create path; self-signup useskind='personal').tests/tenants.rs: newcreate_tenant_sets_org_kind- callscreate_tenant, asserts it succeeds and the row reads backkind = 'org'. Fails on the pre-fix code (the.expectpanics on the 23502).Verification
cargo test -p mokosh-server --test tenants create_tenant_sets_org_kind: 1 passed.cargo fmt --all --checkclean;cargo clippy --test tenantsclean.create_tenant's INSERT omitted the tenants.kind column. Migration 019_tenant_kind adds kind NOT NULL and then drops its default ("callers always set it explicitly"), so the insert failed with SQLSTATE 23502 and POST /api/v1/tenants 500'd. The defect was latent because no test exercised the create_tenant insert: tests/tenants.rs provisioned tenants via ensure_personal_tenant and seed helpers, both of which set kind. It surfaced while writing the PMS-236 isolation suite. Set kind = 'org' explicitly in the INSERT (this is the admin/multi-user org-create path; self-signup uses kind='personal'). Add an integration test that calls create_tenant and asserts it succeeds and the row is kind='org', so a future missing-column regression fails CI. #PMS-287