Skip to content

Commit

Permalink
test(api): fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steveoh committed May 8, 2024
1 parent 5f21e4c commit 166acd1
Show file tree
Hide file tree
Showing 15 changed files with 63 additions and 46 deletions.
2 changes: 1 addition & 1 deletion src/api/Features/Geocoding/UspsDeliveryPointLocation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class Handler(IStaticCache staticCache, ILogger log) : IComputationHandle

_staticCache.UspsDeliveryPoints.TryGetValue(request._address.Zip5.Value.ToString(), out var items);

if (items?.Count != 0) {
if ((items?.Count ?? 0) == 0) {
_log?.ForContext("zip", request._address.Zip5.Value)
.Debug("Delivery Point: cache miss");

Expand Down
4 changes: 3 additions & 1 deletion src/api/Middleware/AuthorizeApiKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public class AuthorizeApiKeyFilter(ILogger log, IBrowserKeyProvider browserProvi
}

var apiKey = await _repo.GetKey(key);
await _db.StringIncrementAsync(key, flags: CommandFlags.FireAndForget);
try {
await _db.StringIncrementAsync(key, flags: CommandFlags.FireAndForget);
} catch { }

// key hasn't been created
if (apiKey == null) {
Expand Down
2 changes: 1 addition & 1 deletion src/data-migration/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
Console.WriteLine("Migrating RavenDB to firestore...");

var store = new DocumentStore() {
Urls = new[] { "http://localhost:3000" },
Urls = ["http://localhost:3000"],
Database = "export"
}.Initialize();

Expand Down
4 changes: 1 addition & 3 deletions test/api.unit.tests/Features/Geocoding/DeliveryPointTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ public async Task Should_return_candidate_from_cache() {
const int pobox = -1;
const int zip = 84114;

var address = Address.BuildPoBoxAddress("inputAddress", pobox, zip,
new[] { new ZipGridLink(84114, "grid", 0) }
);
var address = Address.BuildPoBoxAddress("inputAddress", pobox, zip, [new ZipGridLink(84114, "grid", 0)]);

var geocodeOptions = new SingleGeocodeRequestOptionsContract {
PoBox = true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public DoubleAveExceptionTests() {
mediator.Setup(x => x.Handle(It.IsAny<AddressSystemFromPlace.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((AddressSystemFromPlace.Computation g, CancellationToken _) => {
if (g?._cityKey == "slc") {
return new[] { new PlaceGridLink("slc", "salt lake city", 1) };
return [new PlaceGridLink("slc", "salt lake city", 1)];
}
return Array.Empty<GridLinkable>();
return [];
});
mediator.Setup(x => x.Handle(It.IsAny<AddressSystemFromZipCode.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Array.Empty<GridLinkable>());
.ReturnsAsync([]);

var regexCache = new RegexCache(new Abbreviations());
_computationHandler = new ZoneParsing.Handler(regexCache, mediator.Object, mockLogger.Object);
Expand Down
30 changes: 15 additions & 15 deletions test/api.unit.tests/Features/Geocoding/GeocodeQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ public async Task Should_run_through_main_process() {
var computeMediator = new Mock<IComputeMediator>();
computeMediator.Setup(x => x.Handle(It.IsAny<AddressParsing.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((AddressParsing.Computation __, CancellationToken _) =>
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false)
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false)
);
computeMediator.Setup(x => x.Handle(It.IsAny<ZoneParsing.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((ZoneParsing.Computation __, CancellationToken _) =>
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false)
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false)
);
computeMediator.Setup(x => x.Handle(It.IsAny<UspsDeliveryPointLocation.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((UspsDeliveryPointLocation.Computation __, CancellationToken _) => null);
computeMediator.Setup(x => x.Handle(It.IsAny<GeocodePlan.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((GeocodePlan.Computation __, CancellationToken _) =>
new[] { new LocatorProperties("http://geocoding.plan", "test", 0) }
[new LocatorProperties("http://geocoding.plan", "test", 0)]
);
computeMediator.Setup(x => x.Handle(It.IsAny<Geocode.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((Geocode.Computation __, CancellationToken _) =>
new[] { new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0) }
[new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0)]
);
computeMediator.Setup(x => x.Handle(It.IsAny<FilterCandidates.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((FilterCandidates.Computation __, CancellationToken _) =>
Expand Down Expand Up @@ -63,11 +63,11 @@ public async Task Should_return_404_when_there_is_no_geocode_plan() {
var computeMediator = new Mock<IComputeMediator>();
computeMediator.Setup(x => x.Handle(It.IsAny<AddressParsing.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((AddressParsing.Computation __, CancellationToken _) =>
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false)
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false)
);
computeMediator.Setup(x => x.Handle(It.IsAny<ZoneParsing.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((ZoneParsing.Computation __, CancellationToken _) =>
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false)
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false)
);
computeMediator.Setup(x => x.Handle(It.IsAny<UspsDeliveryPointLocation.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((UspsDeliveryPointLocation.Computation __, CancellationToken _) => null);
Expand All @@ -77,7 +77,7 @@ public async Task Should_return_404_when_there_is_no_geocode_plan() {
);
computeMediator.Setup(x => x.Handle(It.IsAny<Geocode.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((Geocode.Computation __, CancellationToken _) =>
Array.Empty<Candidate>()
[]
);
computeMediator.Setup(x => x.Handle(It.IsAny<FilterCandidates.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((FilterCandidates.Computation __, CancellationToken _) =>
Expand Down Expand Up @@ -107,21 +107,21 @@ public async Task Should_return_404_when_there_is_no_candidate_above_match_score
var computeMediator = new Mock<IComputeMediator>();
computeMediator.Setup(x => x.Handle(It.IsAny<AddressParsing.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((AddressParsing.Computation __, CancellationToken _) =>
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false)
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false)
);
computeMediator.Setup(x => x.Handle(It.IsAny<ZoneParsing.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((ZoneParsing.Computation __, CancellationToken _) =>
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false)
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false)
);
computeMediator.Setup(x => x.Handle(It.IsAny<UspsDeliveryPointLocation.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((UspsDeliveryPointLocation.Computation __, CancellationToken _) => null);
computeMediator.Setup(x => x.Handle(It.IsAny<GeocodePlan.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((GeocodePlan.Computation __, CancellationToken _) =>
new[] { new LocatorProperties("http://geocoding.plan", "test", 0) }
[new LocatorProperties("http://geocoding.plan", "test", 0)]
);
computeMediator.Setup(x => x.Handle(It.IsAny<Geocode.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((Geocode.Computation __, CancellationToken _) =>
new[] { new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0) }
[new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0)]
);
computeMediator.Setup(x => x.Handle(It.IsAny<FilterCandidates.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((FilterCandidates.Computation __, CancellationToken _) => null);
Expand All @@ -142,23 +142,23 @@ public async Task Should_return_early_with_delivery_point() {
var computeMediator = new Mock<IComputeMediator>();
computeMediator.Setup(x => x.Handle(It.IsAny<AddressParsing.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((AddressParsing.Computation __, CancellationToken _) =>
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false)
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false)
);
computeMediator.Setup(x => x.Handle(It.IsAny<ZoneParsing.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((ZoneParsing.Computation __, CancellationToken _) =>
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, new[] { new PlaceGridLink("slc", "SALT LAKE", 0) }, 0, false, false)
new Address("326 east south temple st", 326, Direction.East, "south temple", StreetType.Street, Direction.None, null, 0, [new PlaceGridLink("slc", "SALT LAKE", 0)], 0, false, false)
);
computeMediator.Setup(x => x.Handle(It.IsAny<UspsDeliveryPointLocation.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((UspsDeliveryPointLocation.Computation __, CancellationToken _) =>
new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0)
);
computeMediator.Setup(x => x.Handle(It.IsAny<GeocodePlan.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((GeocodePlan.Computation __, CancellationToken _) =>
new[] { new LocatorProperties("http://geocoding.plan", "test", 0) }
[new LocatorProperties("http://geocoding.plan", "test", 0)]
);
computeMediator.Setup(x => x.Handle(It.IsAny<Geocode.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((Geocode.Computation __, CancellationToken _) =>
new[] { new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0) }
[new Candidate("326 east south temple st", "SALT LAKE", new Point(1, 2), 100, "test", 0)]
);
computeMediator.Setup(x => x.Handle(It.IsAny<FilterCandidates.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((FilterCandidates.Computation __, CancellationToken _) =>
Expand Down
6 changes: 3 additions & 3 deletions test/api.unit.tests/Features/Geocoding/PoBoxTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class PoBoxTests {
public PoBoxTests() {
_poBoxes.Add(84114, new PoBoxAddress(84114, 1, 1));
_exclusions.Add(841140001, new PoBoxAddressCorrection(84114, 841140001, 2, 2));
IReadOnlyCollection<int> zipExclusions = new[] { 84114 };
IReadOnlyCollection<int> zipExclusions = [84114];

var mockCache = new Mock<IStaticCache>();
mockCache.Setup(x => x.PoBoxes).Returns(_poBoxes);
Expand All @@ -32,7 +32,7 @@ public async Task Should_return_candidate_from_exclusions() {
const int zip = 84114;

var address = Address.BuildPoBoxAddress("inputAddress", pobox, zip,
new[] { new ZipGridLink(84114, "grid", 0) }
[new ZipGridLink(84114, "grid", 0)]
);

var geocodeOptions = new SingleGeocodeRequestOptionsContract {
Expand All @@ -56,7 +56,7 @@ public async Task Should_return_candidate_from_poboxes() {
const int zip = 84114;

var address = Address.BuildPoBoxAddress("inputAddress", pobox, zip,
new[] { new ZipGridLink(84114, "grid", 0) }
[new ZipGridLink(84114, "grid", 0)]
);

var geocodeOptions = new SingleGeocodeRequestOptionsContract {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task Should_return_404_when_no_plan_is_created() {
var mediator = new Mock<IComputeMediator>();
mediator.Setup(x => x.Handle(It.IsAny<ReverseGeocodePlan.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync((ReverseGeocodePlan.Computation __, CancellationToken _) =>
Array.Empty<LocatorProperties>()
[]
);

var handler = new ReverseGeocodeQuery.Handler(mediator.Object, _logger);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void Should_return_graphic_for_esri_json() {
point.Y.ShouldBe(2);
}

feature.Attributes.Keys.ShouldBe(new[] { "Location", "Score", "Locator", "MatchAddress", "InputAddress", "StandardizedAddress", "AddressGrid", "ScoreDifference", "Wkid", "Candidates" });
feature.Attributes.Keys.ToList().ShouldBe(["Location", "Score", "Locator", "MatchAddress", "InputAddress", "StandardizedAddress", "AddressGrid", "ScoreDifference", "Wkid", "Candidates"]);
feature.Attributes["Location"].ShouldNotBeNull();
feature.Attributes["Score"].ShouldBe(score);
feature.Attributes["Locator"].ShouldBe(locatorType.ToString());
Expand Down
4 changes: 2 additions & 2 deletions test/api.unit.tests/Features/Geocoding/ZoneParsingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ public ZoneParsingTests() {
It.IsAny<CancellationToken>()))
.ReturnsAsync((AddressSystemFromPlace.Computation g, CancellationToken _) => {
if (g._cityKey == "alta") {
return new[] { new PlaceGridLink("alta", "grid", 1) };
return [new PlaceGridLink("alta", "grid", 1)];
}
return Array.Empty<GridLinkable>();
return [];
});

var mock = new Mock<ILogger>() { DefaultValue = DefaultValue.Mock };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public async Task Should_build_route_map_for_every_location() {
new Concurrencies.ResponseLocations([
new Concurrencies.ConcurrencyLocations(true,"1", -1, 1)
], "1", -1, 1),
new Concurrencies.ResponseLocations(Array.Empty<Concurrencies.ConcurrencyLocations>(), "2", -1, 1),
new Concurrencies.ResponseLocations(Array.Empty<Concurrencies.ConcurrencyLocations>(), "3", -1, 1)
new Concurrencies.ResponseLocations([], "2", -1, 1),
new Concurrencies.ResponseLocations([], "3", -1, 1)
], null);

var computation = new DominantRouteResolver.Computation(locations, null, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public AttributeTableKeyFormattingTests() {

var mediator = new Mock<IComputeMediator>();
mediator.Setup(x => x.Handle(It.IsAny<SqlQuery.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(Array.Empty<SearchResponseContract>());
.ReturnsAsync([]);

var dbOptions = Options.Create(new SearchProviderConfiguration());

Expand Down
4 changes: 2 additions & 2 deletions test/api.unit.tests/Features/Searching/SearchQueryTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public async Task Should_return_results() {

var mediator = new Mock<IComputeMediator>();
mediator.Setup(x => x.Handle(It.IsAny<SqlQuery.Computation>(), It.IsAny<CancellationToken>()))
.ReturnsAsync(new[] {
.ReturnsAsync([
new SearchResponseContract {
Geometry = new SerializableGraphic(
new Graphic(
Expand All @@ -27,7 +27,7 @@ public async Task Should_return_results() {
{ "key", "value"}
}
}
});
]);

var handler = new SearchQuery.Handler(mediator.Object, _logger);
var result = await handler.Handle(query, CancellationToken.None) as IApiResponse<IReadOnlyCollection<SearchResponseContract>>;
Expand Down
Loading

0 comments on commit 166acd1

Please sign in to comment.