Skip to content

Commit

Permalink
Merge pull request #324 from DFE-Digital/feature/125531-trust-search-…
Browse files Browse the repository at this point in the history
…address-not-returned

Fixed logic for returning trusts and associated address information
  • Loading branch information
blakebyron-nimble authored Apr 19, 2023
2 parents 47476d6 + fc48966 commit 71cd9c8
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 5 deletions.
55 changes: 51 additions & 4 deletions TramsDataApi.Test/UseCases/SearchTrustsTests.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -32,12 +33,10 @@ public void SearchTrusts_ReturnsEmptyList_WhenNoTrustsFound()
result.Should().BeEquivalentTo(new List<TrustSummaryResponse>());
}

[Fact]
public void SearchTrusts_ReturnsListOfTrustSummaryResponses_WhenTrustsFound()
private IList<Group> Test(string groupName)
{
var groupName = "groupName";

var expectedTrusts = Builder<Group>.CreateListOfSize(10)
return Builder<Group>.CreateListOfSize(10)
.TheFirst(5)
.With(g => g.GroupType = "Trust")
.TheNext(3)
Expand All @@ -47,6 +46,14 @@ public void SearchTrusts_ReturnsListOfTrustSummaryResponses_WhenTrustsFound()
.All()
.With(g => g.GroupName = groupName)
.Build();
}

[Fact]
public void SearchTrusts_ReturnsListOfTrustSummaryResponses_WhenTrustsFound()
{
var groupName = "groupName";

var expectedTrusts = Test(groupName);

var trustsGateway = new Mock<ITrustGateway>();
var establishmentsGateway = new Mock<IEstablishmentGateway>();
Expand All @@ -69,6 +76,45 @@ public void SearchTrusts_ReturnsListOfTrustSummaryResponses_WhenTrustsFound()

result.Should().BeEquivalentTo(expected);
}
[Fact]
public void SearchTrusts_ReturnsListOfTrustSummaryResponsesWithAddresses_WhenTrustsFound()
{
var groupName = "groupName";

var expectedGroups = Test(groupName);

IDictionary<String, Trust> trusts = new Dictionary<String, Trust>();

foreach (var expectedGroup in expectedGroups)
{
var expectedTrust = Builder<Trust>
.CreateNew()
.With(g => g.TrustRef = expectedGroup.GroupId)
.Build();
trusts.Add(expectedGroup.GroupId, expectedTrust);
}

var trustsGateway = new Mock<ITrustGateway>();
var establishmentsGateway = new Mock<IEstablishmentGateway>();

trustsGateway.Setup(g => g.SearchGroups(1, 10, groupName, string.Empty, string.Empty))
.Returns((expectedGroups, expectedGroups.Count));

trustsGateway.Setup(m => m.GetIfdTrustsByTrustRef(It.IsAny<string[]>()))
.Returns(trusts.Values.ToList());

establishmentsGateway.Setup(g => g.GetByTrustUids(It.IsAny<string[]>()))
.Returns(new List<Establishment>());

var expected = expectedGroups.
Select(e => TrustSummaryResponseFactory.Create(e, new List<Establishment>(), trusts[e.GroupId]))
.ToList();

var searchTrusts = new SearchTrusts(trustsGateway.Object, establishmentsGateway.Object);
var (result, _) = searchTrusts.Execute(1, 10, groupName);

result.Should().BeEquivalentTo(expected);
}

[Fact]
public void SearchTrusts_ShouldGetTrustsWithEstablishments_WhenTrustsAndEstablishmentsAreFound()
Expand Down Expand Up @@ -132,5 +178,6 @@ public void SearchTrusts_WithoutEstablishments()
var (result, _) = searchTrusts.Execute(1, 10, ukPrn: ukprn, includeEstablishments: false);
result.Should().BeEquivalentTo(expected);
}

}
}
2 changes: 1 addition & 1 deletion TramsDataApi/UseCases/SearchTrusts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ public SearchTrusts(ITrustGateway trustGateway, IEstablishmentGateway establishm
return (
groups.Select(group =>
{
var trust = trustsForGroup.FirstOrDefault(e => e.TrustRef == group.GroupId);
var establishments = establishmentsForGroup.Where(e => e.TrustsCode == group.GroupUid);
var trust = trustsForGroup.FirstOrDefault(e => e.TrustRef == group.GroupUid);
return TrustSummaryResponseFactory.Create(group, establishments, trust);
}).ToArray(),
recordCount
Expand Down

0 comments on commit 71cd9c8

Please sign in to comment.