# Video Cache E2E Test ## Overview This test validates the Redis cache contract for video caches: - Category video lists contain ONLY video IDs (not Tag JSON) - Tag-filtered video lists contain ONLY video IDs - Tag metadata lists contain ONLY Tag JSON objects ## Prerequisites Before running the test, ensure: 1. **MongoDB is running** and accessible with valid credentials 2. **Redis is running** on localhost:6379 (or configure in .env file) 3. **MongoDB has test data** (channels, categories, videos, tags) ## Environment Setup The test uses `.env.mgnt.test` for configuration. Update the following variables if needed: ```bash # MongoDB connection (ensure user exists and has correct permissions) MONGO_URL="mongodb://boxuser:PASSWORD@localhost:27017/box_admin?authSource=admin" MONGO_STATS_URL="mongodb://boxstatuser:PASSWORD@localhost:27017/box_stats?authSource=admin" # Redis connection REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_DB=0 ``` ### MongoDB Authentication Issues If you see `SCRAM failure: Authentication failed`: 1. **Option A**: Create the MongoDB user: ```bash mongosh admin db.createUser({ user: "boxuser", pwd: "YOUR_PASSWORD", roles: [{ role: "readWrite", db: "box_admin" }] }) ``` 2. **Option B**: Update `.env.mgnt.test` to use your existing MongoDB credentials 3. **Option C**: Use connection string without authentication: ```bash MONGO_URL="mongodb://localhost:27017/box_admin" ``` ## Running the Test ```bash # From box-nestjs-monorepo directory pnpm test:e2e:mgnt ``` ## Test Output Successful test output includes: ``` ✅ Redis connection verified 🗑️ Deleted cache keys: { ... } 🔨 Rebuilding video caches... 📋 Found X category video list keys 📋 Found X tag-filtered video list keys 📋 Found X tag metadata list keys ✅ All cache keys validated successfully! ``` ## Validation Logic The test performs these validations: ### Video List Keys - Key type is `list` - Each element is a 24-character hex string (MongoDB ObjectId) - **Fails if** Tag JSON or Category JSON is detected ### Tag Metadata Keys - Key type is `list` - Each element is valid JSON with required fields: `id`, `name`, `seq`, `status`, `channelId`, `categoryId` - **Fails if** plain video IDs are detected ## Troubleshooting ### No Cache Keys Found If test shows `Found 0 category video list keys`: - MongoDB has no data - run seed scripts: ```bash pnpm prisma:seed:mongo:test ``` ### Test Timeout If test exceeds 60 seconds: - Check MongoDB query performance - Ensure indexes exist on frequently queried fields - Reduce test data volume ### Redis Connection Failed If `expect(pong).toBe('PONG')` fails: - Verify Redis is running: `redis-cli ping` - Check REDIS_HOST and REDIS_PORT in `.env.mgnt.test`