Skip to content

Commit

Permalink
Merge pull request #917 from dlcs/feature/spaces_count_off
Browse files Browse the repository at this point in the history
Fix approximateImageCount on spaces
  • Loading branch information
donaldgray authored Nov 14, 2024
2 parents 94640df + 11224f1 commit 90908ce
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/protagonist/API.Tests/Integration/SpaceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public async Task Post_SimpleSpace_Creates_Space()
var apiSpace = await response.ReadAsHydraResponseAsync<Space>();

// assert
apiSpace.ApproximateNumberOfImages.Should().Be(0);
response.StatusCode.Should().Be(HttpStatusCode.Created);
response.Headers.Location.PathAndQuery.Should().Be($"{postUrl}/{expectedSpace}");
apiSpace.Should().NotBeNull();
Expand All @@ -62,7 +63,7 @@ public async Task Post_SimpleSpace_Creates_Space()
public async Task Post_ComplexSpace_Creates_Space()
{
// arrange
int? customerId = 99; // await EnsureCustomerForSpaceTests("Post_ComplexSpace_Creates_Space");
int? customerId = 99;

const string newSpaceJson = @"{
""@type"": ""Space"",
Expand Down Expand Up @@ -152,12 +153,12 @@ public async Task GetSpaces_Returns_HydraCollection()

// assert
response.StatusCode.Should().Be(HttpStatusCode.OK);
var coll = await response.ReadAsHydraResponseAsync<HydraCollection<JObject>>();
var coll = await response.ReadAsHydraResponseAsync<HydraCollection<Space>>();
coll.Should().NotBeNull();
coll.Type.Should().Be("Collection");
coll.Members.Should().HaveCount(10);
coll.Members.Should().Contain(jo => jo["@id"].Value<string>().EndsWith($"{spacesUrl}/1"));
coll.Members.Should().Contain(jo => jo["@id"].Value<string>().EndsWith($"{spacesUrl}/10"));
coll.Members.Should().Contain(jo => jo.Id.EndsWith($"{spacesUrl}/1"));
coll.Members.Should().Contain(jo => jo.Id.EndsWith($"{spacesUrl}/10"));
}

[Fact]
Expand Down
6 changes: 4 additions & 2 deletions src/protagonist/DLCS.Repository/Spaces/SpaceRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ private async Task<int> GetIdForNewSpace(int requestCustomer)
ec.Scope == spaceId.ToString(), cancellationToken: cancellationToken);
if (counter != null)
{
space.ApproximateNumberOfImages = counter.Next;
space.ApproximateNumberOfImages = GetApproximateImages(counter.Next);
}
return space;
Expand Down Expand Up @@ -175,7 +175,7 @@ public async Task<PageOfSpaces> GetPageOfSpaces(
.ToDictionaryAsync(ec => ec.Scope, ec => ec.Next, cancellationToken: cancellationToken);
foreach (var space in result.Spaces)
{
space.ApproximateNumberOfImages = counters[space.Id.ToString()];
space.ApproximateNumberOfImages = GetApproximateImages(counters[space.Id.ToString()]);
}

return result;
Expand Down Expand Up @@ -314,4 +314,6 @@ await entityCounterRepository.Remove(customerId, KnownEntityCounters.SpaceImages

return resultMessage;
}

private static long GetApproximateImages(long entityCounterNext) => Math.Max(entityCounterNext - 1, 0);
}

0 comments on commit 90908ce

Please sign in to comment.