fix: Improve test infrastructure and increase pass rate from 51% to 78%
Some checks failed
Build and Deploy LittleShop / Build TeleBot Docker Image (push) Failing after 1s
Build and Deploy LittleShop / Build LittleShop Docker Image (push) Failing after 8s
Build and Deploy LittleShop / Deploy to Production VPS (Manual Only) (push) Has been skipped
Build and Deploy LittleShop / Deploy to Pre-Production (CT109) (push) Has been skipped

Test Infrastructure Improvements:
- Added missing service registrations to TestWebApplicationFactory
  - ICryptoPaymentService
  - IDataSeederService
- Fixed JWT configuration validation to skip in Testing environment
- Allow test environment to use default test JWT key

Impact:
- Test pass rate improved from 56/110 (51%) to 86/110 (78%)
- Fixed 30 integration and security test failures
- All catalog and most order controller tests now passing

Remaining Failures (24 tests):
- OrdersWithVariants tests (5) - Requires variant test data seeding
- OrdersController tests (5) - Requires product/category test data
- AuthenticationEnforcement tests (2) - Auth configuration issues
- UI/AdminPanel tests (12) - Playwright server configuration needed

Next Steps:
- Add test data seeding for product variants and multi-buy
- Configure Playwright tests to use TestWebApplicationFactory server
- Review authentication test expectations

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
SysAdmin 2025-11-16 20:43:52 +00:00
parent a2247d7c02
commit bf62bea1e2
2 changed files with 9 additions and 1 deletions

View File

@ -85,6 +85,8 @@ public class TestWebApplicationFactory : WebApplicationFactory<Program>
services.TryAddScoped<ICustomerMessageService, CustomerMessageService>();
services.TryAddScoped<IBotActivityService, BotActivityService>();
services.TryAddScoped<IProductImportService, ProductImportService>();
services.TryAddScoped<ICryptoPaymentService, CryptoPaymentService>();
services.TryAddScoped<IDataSeederService, DataSeederService>();
// Add validation service
services.TryAddSingleton<ConfigurationValidationService>();

View File

@ -131,7 +131,7 @@ builder.Services.AddSingleton<AspNetCoreRateLimit.IProcessingStrategy, AspNetCor
// Authentication - Cookie for Admin Panel, JWT for API
var jwtKey = builder.Configuration["Jwt:Key"];
if (string.IsNullOrEmpty(jwtKey))
if (string.IsNullOrEmpty(jwtKey) && builder.Environment.EnvironmentName != "Testing")
{
Log.Fatal("🚨 SECURITY: Jwt:Key configuration is missing. Application cannot start securely.");
throw new InvalidOperationException(
@ -139,6 +139,12 @@ if (string.IsNullOrEmpty(jwtKey))
"Set the Jwt__Key environment variable or use: dotnet user-secrets set \"Jwt:Key\" \"<your-secure-key>\"");
}
// Use test key for testing environment
if (builder.Environment.EnvironmentName == "Testing" && string.IsNullOrEmpty(jwtKey))
{
jwtKey = "test-key-that-is-at-least-32-characters-long-for-security";
}
var jwtIssuer = builder.Configuration["Jwt:Issuer"] ?? "LittleShop";
var jwtAudience = builder.Configuration["Jwt:Audience"] ?? "LittleShop";