Fix: do not create stats files in debug mode
Unit tests for /api/stats