Skip to main content

๐Ÿงช 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โ€‹

  1. CineMax Entertainment

    • Company ID: 11111111-1111-1111-1111-111111111111
    • Plan: Basic (50 employees, 10 rooms)
    • Employees: ADM001, MGR001, CSH001
  2. MovieTime Cinemas

    • Company ID: 22222222-2222-2222-2222-222222222222
    • Plan: Basic (50 employees, 10 rooms)
    • Employees: ADM002, MGR002, CSH002
  3. Premium Screens

    • Company ID: 33333333-3333-3333-3333-333333333333
    • Plan: Premium (100 employees, 20 rooms)
    • Employees: ADM003, MGR003, CSH003

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โ€‹

  1. In Swagger, click ๐Ÿ”’ Authorize button
  2. Paste CineMax token (without "Bearer ")
  3. Click Authorize, then Close

Step 2: Test CineMax Data Accessโ€‹

Execute these endpoints and verify results:

EndpointExpected Result
GET /api/movies3 movies: Action Hero 4, Space Adventure, Comedy Night
GET /api/employees3 employees: ADM001, MGR001, CSH001
GET /api/sessions21 sessions (CineMax rooms only)

Step 3: Switch to MovieTimeโ€‹

  1. Click ๐Ÿ”’ Authorize again
  2. Clear previous token and paste MovieTime token
  3. Click Authorize, then Close

Step 4: Verify Data Isolationโ€‹

EndpointExpected Result
GET /api/movies3 different movies: Drama of Hearts, Horror Mansion, Family Fun
GET /api/employees3 different employees: ADM002, MGR002, CSH002
GET /api/sessions21 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โ€‹

  1. Click ๐Ÿ”’ Authorize
  2. Clear previous token and paste System Admin token
  3. 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 employees
  • GET /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โ€‹

  1. As System Admin: Note total counts from GET /api/system-admin/stats
  2. As CineMax: Count items from GET /api/movies, GET /api/employees
  3. As MovieTime: Count items from GET /api/movies, GET /api/employees
  4. As Premium: Count items from GET /api/movies, GET /api/employees
  5. 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 TypeMovies VisibleEmployees VisibleCompanies VisibleAdmin Endpoints
CineMax Token3 (CineMax only)3 (CineMax only)1 (own company)โŒ No access
MovieTime Token3 (MovieTime only)3 (MovieTime only)1 (own company)โŒ No access
Premium Token3 (Premium only)3 (Premium only)1 (own company)โŒ No access
System Admin TokenโŒ No accessโŒ No access3 (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:

  1. โœ… Tenant Isolation: Each tenant sees only their own data (3 movies, 3 employees, 2 customers)
  2. โœ… System Admin Access: Admin can view all companies via system admin endpoints
  3. โœ… Security Boundaries: System admin cannot access tenant endpoints
  4. โœ… Data Consistency: Individual tenant counts sum to platform totals
  5. โœ… Authentication Control: Tokens properly control access to appropriate endpoints

๐ŸŽฌ Congratulations! Your Multi-Tenant Cinema Management SaaS Platform is fully operational!