mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-22 16:41:14 +00:00
[AZ-370] Refactor C17: status / point-type enums + AC RT2 update
Replaces bare strings with two enums in Common/Enums/:
RegionStatus { Queued, Processing, Completed, Failed }
RoutePointType { Start, End, Action, Intermediate }
Adds a Dapper EnumStringTypeHandler<T> (DataAccess/TypeHandlers/)
that round-trips enums to/from lowercase strings, registered once
at startup via DapperEnumTypeHandlers.RegisterAll(). DataAccess now
references Common (project ref) so entities can carry the enum types.
Sites converted: RegionService (5), RouteProcessingService (3),
RoutePointGraphBuilder (4), entity Status/PointType columns. Log
message and summary file format preserved via .ToLowerInvariant().
API JSON contract preserved by adding JsonStringEnumConverter with
JsonNamingPolicy.CamelCase to the http JSON options — single-word
enum members serialize to the same lowercase strings as before.
DTO renamed: Common.DTO.RegionStatus -> RegionStatusResponse to
free the RegionStatus name for the new enum (forced by the task's
explicit enum name); the renamed DTO has no public-API impact at
the JSON wire level. Stale doc references updated.
AC RT2 in _docs/00_problem/acceptance_criteria.md now lists all 4
point types (start/end/action/intermediate).
Tests: 171 / 171 unit + 5 / 5 smoke green (was 141 + 5; +30 new tests
covering type handler round-trip, set/parse, unknown-value rejection,
idempotent registration, and the AC RT2 doc check).
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -4,6 +4,7 @@ using Microsoft.Extensions.Options;
|
||||
using Moq;
|
||||
using SatelliteProvider.Common.Configs;
|
||||
using SatelliteProvider.Common.DTO;
|
||||
using SatelliteProvider.Common.Enums;
|
||||
using SatelliteProvider.Common.Exceptions;
|
||||
using SatelliteProvider.Common.Interfaces;
|
||||
using SatelliteProvider.DataAccess.Models;
|
||||
@@ -57,10 +58,10 @@ public class RegionServiceTests : IDisposable
|
||||
|
||||
// Assert
|
||||
status.Id.Should().Be(id);
|
||||
status.Status.Should().Be("queued");
|
||||
status.Status.Should().Be(RegionStatus.Queued);
|
||||
regionRepo.Verify(r => r.InsertAsync(It.Is<RegionEntity>(re =>
|
||||
re.Id == id &&
|
||||
re.Status == "queued" &&
|
||||
re.Status == RegionStatus.Queued &&
|
||||
re.SizeMeters == 200 &&
|
||||
re.ZoomLevel == 18)), Times.Once);
|
||||
queue.Verify(q => q.EnqueueAsync(It.Is<RegionRequest>(rr =>
|
||||
@@ -83,7 +84,7 @@ public class RegionServiceTests : IDisposable
|
||||
SizeMeters = 200,
|
||||
ZoomLevel = 18,
|
||||
StitchTiles = false,
|
||||
Status = "processing",
|
||||
Status = RegionStatus.Processing,
|
||||
TilesDownloaded = 5,
|
||||
TilesReused = 3,
|
||||
CreatedAt = DateTime.UtcNow.AddMinutes(-5),
|
||||
@@ -100,7 +101,7 @@ public class RegionServiceTests : IDisposable
|
||||
|
||||
// Assert
|
||||
status.Id.Should().Be(id);
|
||||
status.Status.Should().Be("processing", "AZ-362: returns the existing region's current status, not 'queued'");
|
||||
status.Status.Should().Be(RegionStatus.Processing, "AZ-362: returns the existing region's current status, not 'queued'");
|
||||
regionRepo.Verify(r => r.InsertAsync(It.IsAny<RegionEntity>()), Times.Never,
|
||||
"AZ-362: duplicate Id must not re-insert");
|
||||
queue.VerifyNoOtherCalls();
|
||||
@@ -122,7 +123,7 @@ public class RegionServiceTests : IDisposable
|
||||
Longitude = 37.647063,
|
||||
SizeMeters = 200,
|
||||
ZoomLevel = 18,
|
||||
Status = "queued",
|
||||
Status = RegionStatus.Queued,
|
||||
StitchTiles = false,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
@@ -130,7 +131,7 @@ public class RegionServiceTests : IDisposable
|
||||
|
||||
regionRepo.Setup(r => r.GetByIdAsync(id)).ReturnsAsync(entity);
|
||||
|
||||
var capturedStatuses = new List<string>();
|
||||
var capturedStatuses = new List<RegionStatus>();
|
||||
regionRepo
|
||||
.Setup(r => r.UpdateAsync(It.IsAny<RegionEntity>()))
|
||||
.Callback<RegionEntity>(e => capturedStatuses.Add(e.Status))
|
||||
@@ -163,8 +164,8 @@ public class RegionServiceTests : IDisposable
|
||||
await service.ProcessRegionAsync(id);
|
||||
|
||||
// Assert
|
||||
capturedStatuses.Should().ContainInOrder("processing", "completed");
|
||||
entity.Status.Should().Be("completed");
|
||||
capturedStatuses.Should().ContainInOrder(RegionStatus.Processing, RegionStatus.Completed);
|
||||
entity.Status.Should().Be(RegionStatus.Completed);
|
||||
entity.CsvFilePath.Should().NotBeNullOrEmpty();
|
||||
entity.SummaryFilePath.Should().NotBeNullOrEmpty();
|
||||
entity.TilesDownloaded.Should().Be(1);
|
||||
@@ -204,7 +205,7 @@ public class RegionServiceTests : IDisposable
|
||||
Longitude = 37.647063,
|
||||
SizeMeters = 200,
|
||||
ZoomLevel = 18,
|
||||
Status = "queued",
|
||||
Status = RegionStatus.Queued,
|
||||
StitchTiles = false,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
@@ -212,7 +213,7 @@ public class RegionServiceTests : IDisposable
|
||||
|
||||
regionRepo.Setup(r => r.GetByIdAsync(id)).ReturnsAsync(entity);
|
||||
|
||||
var capturedStatuses = new List<string>();
|
||||
var capturedStatuses = new List<RegionStatus>();
|
||||
regionRepo
|
||||
.Setup(r => r.UpdateAsync(It.IsAny<RegionEntity>()))
|
||||
.Callback<RegionEntity>(e => capturedStatuses.Add(e.Status))
|
||||
@@ -233,8 +234,8 @@ public class RegionServiceTests : IDisposable
|
||||
await service.ProcessRegionAsync(id);
|
||||
|
||||
// Assert
|
||||
capturedStatuses.Should().ContainInOrder("processing", "failed");
|
||||
entity.Status.Should().Be("failed");
|
||||
capturedStatuses.Should().ContainInOrder(RegionStatus.Processing, RegionStatus.Failed);
|
||||
entity.Status.Should().Be(RegionStatus.Failed);
|
||||
entity.SummaryFilePath.Should().NotBeNullOrEmpty();
|
||||
File.Exists(entity.SummaryFilePath!).Should().BeTrue();
|
||||
File.ReadAllText(entity.SummaryFilePath!).Should().Contain("Rate limit exceeded");
|
||||
@@ -256,7 +257,7 @@ public class RegionServiceTests : IDisposable
|
||||
Longitude = 37.647063,
|
||||
SizeMeters = 500,
|
||||
ZoomLevel = 18,
|
||||
Status = "queued",
|
||||
Status = RegionStatus.Queued,
|
||||
StitchTiles = true,
|
||||
CreatedAt = DateTime.UtcNow,
|
||||
UpdatedAt = DateTime.UtcNow,
|
||||
@@ -293,7 +294,7 @@ public class RegionServiceTests : IDisposable
|
||||
await service.ProcessRegionAsync(id);
|
||||
|
||||
// Assert
|
||||
entity.Status.Should().Be("completed");
|
||||
entity.Status.Should().Be(RegionStatus.Completed);
|
||||
var stitchedPath = Path.Combine(_readyDir, $"region_{id}_stitched.jpg");
|
||||
File.Exists(stitchedPath).Should().BeTrue("stitched image must exist when stitchTiles=true");
|
||||
}
|
||||
@@ -305,7 +306,7 @@ public class RegionServiceTests : IDisposable
|
||||
var regionRepo = new Mock<IRegionRepository>();
|
||||
var id = Guid.NewGuid();
|
||||
regionRepo.Setup(r => r.GetByIdAsync(id))
|
||||
.ReturnsAsync(new RegionEntity { Id = id, Status = "completed", TilesDownloaded = 5, TilesReused = 2 });
|
||||
.ReturnsAsync(new RegionEntity { Id = id, Status = RegionStatus.Completed, TilesDownloaded = 5, TilesReused = 2 });
|
||||
var service = BuildService(regionRepo, new Mock<IRegionRequestQueue>(), new Mock<ITileService>());
|
||||
|
||||
// Act
|
||||
@@ -313,7 +314,7 @@ public class RegionServiceTests : IDisposable
|
||||
|
||||
// Assert
|
||||
result.Should().NotBeNull();
|
||||
result!.Status.Should().Be("completed");
|
||||
result!.Status.Should().Be(RegionStatus.Completed);
|
||||
result.TilesDownloaded.Should().Be(5);
|
||||
result.TilesReused.Should().Be(2);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user