🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
242 lines
8.4 KiB
C#
242 lines
8.4 KiB
C#
using System.Net;
|
|
using System.Net.Http.Json;
|
|
using FluentAssertions;
|
|
using Xunit;
|
|
|
|
namespace ColaFlow.IntegrationTests.API;
|
|
|
|
/// <summary>
|
|
/// Example API Integration Test for Projects Controller
|
|
/// Based on M1-Architecture-Design.md Section 8.3
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// To use this test, you need to:
|
|
/// 1. Implement ColaFlowWebApplicationFactory with your Program and DbContext types
|
|
/// 2. Implement actual API endpoints
|
|
/// 3. Implement DTOs
|
|
/// </remarks>
|
|
public class ProjectsApiTests // : IClassFixture<ColaFlowWebApplicationFactory<Program, ColaFlowDbContext>>
|
|
{
|
|
// private readonly HttpClient _client;
|
|
// private readonly ColaFlowWebApplicationFactory<Program, ColaFlowDbContext> _factory;
|
|
|
|
// public ProjectsApiTests(ColaFlowWebApplicationFactory<Program, ColaFlowDbContext> factory)
|
|
// {
|
|
// _factory = factory;
|
|
// _client = factory.CreateClient();
|
|
// }
|
|
|
|
[Fact]
|
|
public async Task GetProjects_ReturnsSuccessStatusCode()
|
|
{
|
|
// Arrange
|
|
// No setup needed
|
|
|
|
// Act
|
|
// var response = await _client.GetAsync("/api/v1/projects");
|
|
|
|
// Assert
|
|
// TODO: Uncomment after API is implemented
|
|
// response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
|
|
// Placeholder assertion for template
|
|
await Task.CompletedTask;
|
|
true.Should().BeTrue("This is a placeholder test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateProject_ValidData_ReturnsCreated()
|
|
{
|
|
// Arrange
|
|
// var createRequest = new CreateProjectDto
|
|
// {
|
|
// Name = "Test Project",
|
|
// Description = "Test Description",
|
|
// Key = "TEST"
|
|
// };
|
|
|
|
// Act
|
|
// var response = await _client.PostAsJsonAsync("/api/v1/projects", createRequest);
|
|
|
|
// Assert
|
|
// TODO: Uncomment after API is implemented
|
|
// response.StatusCode.Should().Be(HttpStatusCode.Created);
|
|
// var project = await response.Content.ReadFromJsonAsync<ProjectDto>();
|
|
// project.Should().NotBeNull();
|
|
// project!.Name.Should().Be("Test Project");
|
|
// project.Key.Should().Be("TEST");
|
|
|
|
// Placeholder assertion for template
|
|
await Task.CompletedTask;
|
|
true.Should().BeTrue("This is a placeholder test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task CreateProject_DuplicateKey_ReturnsBadRequest()
|
|
{
|
|
// Arrange
|
|
// using var scope = _factory.CreateScope();
|
|
// var dbContext = _factory.GetDbContext(scope);
|
|
|
|
// Seed existing project with key "TEST"
|
|
// var existingProject = Project.Create("Existing", "Description", "TEST", UserId.Create(Guid.NewGuid()));
|
|
// await dbContext.Projects.AddAsync(existingProject);
|
|
// await dbContext.SaveChangesAsync();
|
|
|
|
// var createRequest = new CreateProjectDto
|
|
// {
|
|
// Name = "New Project",
|
|
// Description = "Description",
|
|
// Key = "TEST" // Duplicate key
|
|
// };
|
|
|
|
// Act
|
|
// var response = await _client.PostAsJsonAsync("/api/v1/projects", createRequest);
|
|
|
|
// Assert
|
|
// TODO: Uncomment after API is implemented
|
|
// response.StatusCode.Should().Be(HttpStatusCode.BadRequest);
|
|
|
|
// Placeholder assertion for template
|
|
await Task.CompletedTask;
|
|
true.Should().BeTrue("This is a placeholder test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetProject_ExistingId_ReturnsProject()
|
|
{
|
|
// Arrange
|
|
// using var scope = _factory.CreateScope();
|
|
// var dbContext = _factory.GetDbContext(scope);
|
|
|
|
// Seed test project
|
|
// var project = Project.Create("Test Project", "Description", "TEST", UserId.Create(Guid.NewGuid()));
|
|
// await dbContext.Projects.AddAsync(project);
|
|
// await dbContext.SaveChangesAsync();
|
|
|
|
// Act
|
|
// var response = await _client.GetAsync($"/api/v1/projects/{project.Id.Value}");
|
|
|
|
// Assert
|
|
// TODO: Uncomment after API is implemented
|
|
// response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
// var returnedProject = await response.Content.ReadFromJsonAsync<ProjectDto>();
|
|
// returnedProject.Should().NotBeNull();
|
|
// returnedProject!.Name.Should().Be("Test Project");
|
|
|
|
// Placeholder assertion for template
|
|
await Task.CompletedTask;
|
|
true.Should().BeTrue("This is a placeholder test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetProject_NonExistingId_ReturnsNotFound()
|
|
{
|
|
// Arrange
|
|
// var nonExistingId = Guid.NewGuid();
|
|
|
|
// Act
|
|
// var response = await _client.GetAsync($"/api/v1/projects/{nonExistingId}");
|
|
|
|
// Assert
|
|
// TODO: Uncomment after API is implemented
|
|
// response.StatusCode.Should().Be(HttpStatusCode.NotFound);
|
|
|
|
// Placeholder assertion for template
|
|
await Task.CompletedTask;
|
|
true.Should().BeTrue("This is a placeholder test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task UpdateProject_ValidData_ReturnsUpdated()
|
|
{
|
|
// Arrange
|
|
// using var scope = _factory.CreateScope();
|
|
// var dbContext = _factory.GetDbContext(scope);
|
|
|
|
// Seed test project
|
|
// var project = Project.Create("Original", "Description", "TEST", UserId.Create(Guid.NewGuid()));
|
|
// await dbContext.Projects.AddAsync(project);
|
|
// await dbContext.SaveChangesAsync();
|
|
|
|
// var updateRequest = new UpdateProjectDto
|
|
// {
|
|
// Name = "Updated Project",
|
|
// Description = "Updated Description"
|
|
// };
|
|
|
|
// Act
|
|
// var response = await _client.PutAsJsonAsync($"/api/v1/projects/{project.Id.Value}", updateRequest);
|
|
|
|
// Assert
|
|
// TODO: Uncomment after API is implemented
|
|
// response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
// var updatedProject = await response.Content.ReadFromJsonAsync<ProjectDto>();
|
|
// updatedProject.Should().NotBeNull();
|
|
// updatedProject!.Name.Should().Be("Updated Project");
|
|
|
|
// Placeholder assertion for template
|
|
await Task.CompletedTask;
|
|
true.Should().BeTrue("This is a placeholder test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task DeleteProject_ExistingId_ReturnsNoContent()
|
|
{
|
|
// Arrange
|
|
// using var scope = _factory.CreateScope();
|
|
// var dbContext = _factory.GetDbContext(scope);
|
|
|
|
// Seed test project
|
|
// var project = Project.Create("Test", "Description", "TEST", UserId.Create(Guid.NewGuid()));
|
|
// await dbContext.Projects.AddAsync(project);
|
|
// await dbContext.SaveChangesAsync();
|
|
|
|
// Act
|
|
// var response = await _client.DeleteAsync($"/api/v1/projects/{project.Id.Value}");
|
|
|
|
// Assert
|
|
// TODO: Uncomment after API is implemented
|
|
// response.StatusCode.Should().Be(HttpStatusCode.NoContent);
|
|
|
|
// Verify soft delete
|
|
// var deletedProject = await dbContext.Projects.FindAsync(project.Id);
|
|
// deletedProject.Should().BeNull(); // Filtered by global query filter
|
|
|
|
// Placeholder assertion for template
|
|
await Task.CompletedTask;
|
|
true.Should().BeTrue("This is a placeholder test");
|
|
}
|
|
|
|
[Fact]
|
|
public async Task GetKanbanBoard_ExistingProject_ReturnsBoard()
|
|
{
|
|
// Arrange
|
|
// using var scope = _factory.CreateScope();
|
|
// var dbContext = _factory.GetDbContext(scope);
|
|
|
|
// Seed test project with tasks
|
|
// var project = Project.Create("Test", "Description", "TEST", UserId.Create(Guid.NewGuid()));
|
|
// var epic = project.CreateEpic("Epic 1", "Description", UserId.Create(Guid.NewGuid()));
|
|
// var story = epic.CreateStory("Story 1", "Description", TaskPriority.High, UserId.Create(Guid.NewGuid()));
|
|
// story.CreateTask("Task 1", "Description", TaskPriority.Medium, UserId.Create(Guid.NewGuid()));
|
|
|
|
// await dbContext.Projects.AddAsync(project);
|
|
// await dbContext.SaveChangesAsync();
|
|
|
|
// Act
|
|
// var response = await _client.GetAsync($"/api/v1/projects/{project.Id.Value}/kanban");
|
|
|
|
// Assert
|
|
// TODO: Uncomment after API is implemented
|
|
// response.StatusCode.Should().Be(HttpStatusCode.OK);
|
|
// var kanban = await response.Content.ReadFromJsonAsync<KanbanBoardDto>();
|
|
// kanban.Should().NotBeNull();
|
|
// kanban!.Columns.Should().HaveCount(4); // To Do, In Progress, Review, Done
|
|
|
|
// Placeholder assertion for template
|
|
await Task.CompletedTask;
|
|
true.Should().BeTrue("This is a placeholder test");
|
|
}
|
|
}
|