13c9c8aa68
Backend Integration Tests: - Create IntegrationTestBase class with WebApplicationFactory - AuthIntegrationTests: Registration, login, validation tests (5 tests) - EventsIntegrationTests: CRUD operations, authorization tests (8 tests) Frontend-Backend Integration (E2E): - Install Playwright with Chromium - Create playwright.config.ts with configuration - Auth E2E tests: login/register page visibility, navigation - Event List E2E tests: page display - Navigation E2E tests: main page navigation flow Total Integration Tests: - Backend: 13 tests covering Auth and Events - E2E: 6 tests covering UI flows
130 lines
3.7 KiB
C#
130 lines
3.7 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using FluentAssertions;
|
|
using RacePlannerApi.DTOs;
|
|
using Xunit;
|
|
|
|
namespace backend.Tests.Integration;
|
|
|
|
public class AuthIntegrationTests : IntegrationTestBase
|
|
{
|
|
public AuthIntegrationTests(WebApplicationFactory<Program> factory) : base(factory) { }
|
|
|
|
[Fact]
|
|
public async Task Register_WithValidData_ReturnsSuccess()
|
|
{
|
|
// Arrange
|
|
var request = new RegisterRequest
|
|
{
|
|
Email = "test@example.com",
|
|
Password = "SecurePass123!",
|
|
Name = "Test User",
|
|
Role = UserRole.Participant
|
|
};
|
|
|
|
// Act
|
|
var response = await _client.PostAsJsonAsync("/api/auth/register", request);
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
var result = await response.Content.ReadFromJsonAsync<AuthResponse>();
|
|
result.Should().NotBeNull();
|
|
result!.Token.Should().NotBeNullOrEmpty();
|
|
result.User.Email.Should().Be(request.Email);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Register_WithDuplicateEmail_ReturnsConflict()
|
|
{
|
|
// Arrange
|
|
var request = new RegisterRequest
|
|
{
|
|
Email = "duplicate@example.com",
|
|
Password = "SecurePass123!",
|
|
Name = "Test User",
|
|
Role = UserRole.Participant
|
|
};
|
|
|
|
// Register first user
|
|
await _client.PostAsJsonAsync("/api/auth/register", request);
|
|
|
|
// Act - Try to register again with same email
|
|
var response = await _client.PostAsJsonAsync("/api/auth/register", request);
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.Conflict);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Login_WithValidCredentials_ReturnsToken()
|
|
{
|
|
// Arrange
|
|
var registerRequest = new RegisterRequest
|
|
{
|
|
Email = "login@example.com",
|
|
Password = "SecurePass123!",
|
|
Name = "Test User",
|
|
Role = UserRole.Participant
|
|
};
|
|
await _client.PostAsJsonAsync("/api/auth/register", registerRequest);
|
|
|
|
var loginRequest = new LoginRequest
|
|
{
|
|
Email = "login@example.com",
|
|
Password = "SecurePass123!"
|
|
};
|
|
|
|
// Act
|
|
var response = await _client.PostAsJsonAsync("/api/auth/login", loginRequest);
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
var result = await response.Content.ReadFromJsonAsync<AuthResponse>();
|
|
result.Should().NotBeNull();
|
|
result!.Token.Should().NotBeNullOrEmpty();
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Login_WithInvalidCredentials_ReturnsUnauthorized()
|
|
{
|
|
// Arrange
|
|
var loginRequest = new LoginRequest
|
|
{
|
|
Email = "nonexistent@example.com",
|
|
Password = "WrongPassword123!"
|
|
};
|
|
|
|
// Act
|
|
var response = await _client.PostAsJsonAsync("/api/auth/login", loginRequest);
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
|
|
}
|
|
|
|
[Fact]
|
|
public async Task Login_WithIncorrectPassword_ReturnsUnauthorized()
|
|
{
|
|
// Arrange
|
|
var registerRequest = new RegisterRequest
|
|
{
|
|
Email = "wrongpass@example.com",
|
|
Password = "CorrectPass123!",
|
|
Name = "Test User",
|
|
Role = UserRole.Participant
|
|
};
|
|
await _client.PostAsJsonAsync("/api/auth/register", registerRequest);
|
|
|
|
var loginRequest = new LoginRequest
|
|
{
|
|
Email = "wrongpass@example.com",
|
|
Password = "WrongPass123!"
|
|
};
|
|
|
|
// Act
|
|
var response = await _client.PostAsJsonAsync("/api/auth/login", loginRequest);
|
|
|
|
// Assert
|
|
response.StatusCode.Should().Be(HttpStatusCode.Unauthorized);
|
|
}
|
|
}
|