Fix middleware loading in tests