๐งช Multi-Tenant Cinema Management System - Testing Guide
๐ Overviewโ
This guide walks you through testing the multi-tenant architecture of the Cinema Management System. The system supports multiple cinema companies with complete data isolation and cross-tenant administration capabilities.
๐ข Multi-Tenant Architectureโ
Available Tenantsโ
-
CineMax Entertainment
- Company ID:
11111111-1111-1111-1111-111111111111
- Plan: Basic (50 employees, 10 rooms)
- Employees: ADM001, MGR001, CSH001
- Company ID:
-
MovieTime Cinemas
- Company ID:
22222222-2222-2222-2222-222222222222
- Plan: Basic (50 employees, 10 rooms)
- Employees: ADM002, MGR002, CSH002
- Company ID:
-
Premium Screens
- Company ID:
33333333-3333-3333-3333-333333333333
- Plan: Premium (100 employees, 20 rooms)
- Employees: ADM003, MGR003, CSH003
- Company ID:
System Administratorโ
- Username:
sysadmin
- Cross-tenant access to all companies
- Platform management capabilities
๐ Authentication Setupโ
1. Access Swagger Documentationโ
Navigate to: http://localhost:3000/api/docs/
2. Generate Authentication Tokensโ
For Tenant Testing:โ
# CineMax Entertainment Token
docker-compose exec api npm run token:multitenant 11111111-1111-1111-1111-111111111111 ADM001
# MovieTime Cinemas Token
docker-compose exec api npm run token:multitenant 22222222-2222-2222-2222-222222222222 ADM002
# Premium Screens Token
docker-compose exec api npm run token:multitenant 33333333-3333-3333-3333-333333333333 ADM003
For System Admin Testing:โ
# System Administrator Token
docker-compose exec api npm run token:sysadmin sysadmin
โ ๏ธ Important: Copy tokens WITHOUT the "Bearer " prefix for Swagger authentication.
๐ฏ Test Scenariosโ
Scenario 1: Tenant Data Isolationโ
Step 1: Authenticate as CineMaxโ
- In Swagger, click ๐ Authorize button
- Paste CineMax token (without "Bearer ")
- Click Authorize, then Close
Step 2: Test CineMax Data Accessโ
Execute these endpoints and verify results:
Endpoint | Expected Result |
---|---|
GET /api/movies | 3 movies: Action Hero 4, Space Adventure, Comedy Night |
GET /api/employees | 3 employees: ADM001, MGR001, CSH001 |
GET /api/sessions | 21 sessions (CineMax rooms only) |
Step 3: Switch to MovieTimeโ
- Click ๐ Authorize again
- Clear previous token and paste MovieTime token
- Click Authorize, then Close
Step 4: Verify Data Isolationโ
Endpoint | Expected Result |
---|---|
GET /api/movies | 3 different movies: Drama of Hearts, Horror Mansion, Family Fun |
GET /api/employees | 3 different employees: ADM002, MGR002, CSH002 |
GET /api/sessions | 21 different sessions (MovieTime rooms only) |
โ Success Criteria: You cannot see any CineMax data when authenticated as MovieTime.
Scenario 2: System Admin Cross-Tenant Accessโ
Step 1: Authenticate as System Adminโ
- Click ๐ Authorize
- Clear previous token and paste System Admin token
- Click Authorize, then Close
Step 2: Test System Admin Capabilitiesโ
A) Cross-Tenant Company Managementโ
GET /api/system-admin/companies
โ Should return 3 companies
B) Platform Statisticsโ
GET /api/system-admin/stats
โ Should show:{
"platform": {
"totalCompanies": 3,
"activeCompanies": 3
},
"users": {
"totalEmployees": 9,
"totalCustomers": 6
}
}
C) Company-Specific Data Accessโ
GET /api/system-admin/companies/11111111-1111-1111-1111-111111111111/employees
โ CineMax employeesGET /api/system-admin/companies/22222222-2222-2222-2222-222222222222/employees
โ MovieTime employees
Step 3: Verify Security Isolationโ
GET /api/movies
โ Should return 401 Unauthorized (System admin cannot access tenant endpoints)
โ Success Criteria: System admin can access all company data via system admin endpoints but is blocked from regular tenant endpoints.
Scenario 3: Data Consistency Verificationโ
Test Cross-Tenant Data Consistencyโ
- As System Admin: Note total counts from
GET /api/system-admin/stats
- As CineMax: Count items from
GET /api/movies
,GET /api/employees
- As MovieTime: Count items from
GET /api/movies
,GET /api/employees
- As Premium: Count items from
GET /api/movies
,GET /api/employees
- Verify: Individual tenant counts should sum to system admin totals
Expected Totals:
- Movies: 9 total (3 per tenant)
- Employees: 9 total (3 per tenant)
- Customers: 6 total (2 per tenant)
- Companies: 3 total
โ Expected Test Results Matrixโ
Authentication Type | Movies Visible | Employees Visible | Companies Visible | Admin Endpoints |
---|---|---|---|---|
CineMax Token | 3 (CineMax only) | 3 (CineMax only) | 1 (own company) | โ No access |
MovieTime Token | 3 (MovieTime only) | 3 (MovieTime only) | 1 (own company) | โ No access |
Premium Token | 3 (Premium only) | 3 (Premium only) | 1 (own company) | โ No access |
System Admin Token | โ No access | โ No access | 3 (all companies) | โ Full access |
๐ Troubleshootingโ
Common Issuesโ
Token Not Workingโ
- Ensure you copied token without "Bearer " prefix
- Tokens expire in 8 hours - generate fresh ones
- Check for extra spaces when pasting
Getting 401 Errorsโ
- Click ๐ Authorize and re-enter your token
- Verify the token format is correct
- Ensure you're using the right token type for the endpoint
No System Admin Endpoints Visibleโ
- Refresh the Swagger page
- Verify the API container is running:
docker-compose ps api
Wrong Data Countโ
- Verify you're testing with fresh seeded data:
docker-compose exec api npm run seed:multitenant
- Check that you're using the correct company ID for token generation
๐ Quick Test Commandsโ
For command-line testing:
# Test tenant isolation (should each return 3)
curl -H "Authorization: Bearer [CINEMAX_TOKEN]" http://localhost:3000/api/movies | jq '.count'
curl -H "Authorization: Bearer [MOVIETIME_TOKEN]" http://localhost:3000/api/movies | jq '.count'
curl -H "Authorization: Bearer [PREMIUM_TOKEN]" http://localhost:3000/api/movies | jq '.count'
# Test system admin (should return 3)
curl -H "Authorization: Bearer [SYSADMIN_TOKEN]" http://localhost:3000/api/system-admin/companies | jq '.data | length'
# Test security isolation (should return 401)
curl -H "Authorization: Bearer [SYSADMIN_TOKEN]" http://localhost:3000/api/movies
๐ Success Confirmationโ
Your multi-tenant system is working correctly when:
- โ Tenant Isolation: Each tenant sees only their own data (3 movies, 3 employees, 2 customers)
- โ System Admin Access: Admin can view all companies via system admin endpoints
- โ Security Boundaries: System admin cannot access tenant endpoints
- โ Data Consistency: Individual tenant counts sum to platform totals
- โ Authentication Control: Tokens properly control access to appropriate endpoints
๐ฌ Congratulations! Your Multi-Tenant Cinema Management SaaS Platform is fully operational!