Skip to content

Commit

Permalink
Merge pull request #2251 from josephweinkam/release/R3.2.0
Browse files Browse the repository at this point in the history
EMBCESSMOD-5495: fix bug loading pets during file query
  • Loading branch information
ytqsl authored May 30, 2024
2 parents a5114b5 + a430acd commit 94f6297
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using EMBC.ESS.Utilities.Dynamics.Microsoft.Dynamics.CRM;
using EMBC.Utilities;
using EMBC.Utilities.Extensions;
using Microsoft.IdentityModel.Tokens;

namespace EMBC.ESS.Resources.Evacuations;

Expand Down Expand Up @@ -292,11 +293,11 @@ private static async Task ParallelLoadEvacuationFileAsync(EssContext ctx, era_ev

var loadTasks = new List<Task>();

if (file.era_era_evacuationfile_era_animal_ESSFileid == null) loadTasks.Add(ctx.LoadPropertyAsync(file, nameof(era_evacuationfile.era_era_evacuationfile_era_animal_ESSFileid), ct));
if (file.era_era_evacuationfile_era_essfilenote_ESSFileID == null) loadTasks.Add(ctx.LoadPropertyAsync(file, nameof(era_evacuationfile.era_era_evacuationfile_era_essfilenote_ESSFileID), ct));
if (file.era_era_evacuationfile_era_animal_ESSFileid.IsNullOrEmpty()) loadTasks.Add(ctx.LoadPropertyAsync(file, nameof(era_evacuationfile.era_era_evacuationfile_era_animal_ESSFileid), ct));
if (file.era_era_evacuationfile_era_essfilenote_ESSFileID.IsNullOrEmpty()) loadTasks.Add(ctx.LoadPropertyAsync(file, nameof(era_evacuationfile.era_era_evacuationfile_era_essfilenote_ESSFileID), ct));
if (file.era_TaskId == null) loadTasks.Add(ctx.LoadPropertyAsync(file, nameof(era_evacuationfile.era_TaskId), ct));
if (file.era_Registrant == null) loadTasks.Add(ctx.LoadPropertyAsync(file, nameof(era_evacuationfile.era_Registrant), ct));
if (file.era_era_evacuationfile_era_evacueesupport_ESSFileId == null) loadTasks.Add(ctx.LoadPropertyAsync(file, nameof(era_evacuationfile.era_era_evacuationfile_era_evacueesupport_ESSFileId), ct));
if (file.era_era_evacuationfile_era_evacueesupport_ESSFileId.IsNullOrEmpty()) loadTasks.Add(ctx.LoadPropertyAsync(file, nameof(era_evacuationfile.era_era_evacuationfile_era_evacueesupport_ESSFileId), ct));
loadTasks.Add(LoadNeedsAssessment(ctx, file, ct));

await Task.WhenAll(loadTasks);
Expand Down
14 changes: 14 additions & 0 deletions ess/src/API/EMBC.Tests.Integration.ESS/DynamicsTestData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class DynamicsTestData

private static int[] selfServeSupportTypes = [174360000, 174360001, 174360005, 174360006, 174360009];
private static int[] selfServeOneTimeSupportTypes = [174360005, 174360006];
private static string[] petTypes = ["Dog", "Cat", "Fish", "Bird", "Hamster", "Rabbit"];

public string[] Commmunities => jurisdictions.Select(j => j.era_jurisdictionid.GetValueOrDefault().ToString()).ToArray();

Expand Down Expand Up @@ -391,6 +392,19 @@ private era_evacuationfile CreateEvacuationFile(EssContext essContext, contact p
}
}

var pets = Enumerable.Range(1, Random.Shared.Next(1, petTypes.Length)).Select(i => new era_animal
{
era_animalid = Guid.NewGuid(),
era_numberofpets = Random.Shared.Next(1, 5),
era_name = $"{testPrefix}-{petTypes[i - 1]}"
}).ToArray();

foreach (var pet in pets)
{
essContext.AddToera_animals(pet);
essContext.SetLink(pet, nameof(era_animal.era_ESSFileid), file);
}

file.era_era_evacuationfile_era_householdmember_EvacuationFileid = new Collection<era_householdmember>(householdMembers);
file.era_CurrentNeedsAssessmentid = needsAssessment;
return file;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,18 @@ public async Task Query_FileByNeedsAssessmentId_ReturnsHouseholdMembersForThatAs
twiceUpdatedFile.NeedsAssessment.HouseholdMembers.ShouldHaveSingleItem();
}

[Fact]
public async Task Query_FileByRegistrantId_ResponseIncludesPets()
{
var caseQuery = new EvacuationFilesQuery
{
LinkedRegistrantId = TestContactId
};
var files = (await evacuationRepository.Query(caseQuery)).Items.ToArray();
files.ShouldNotBeEmpty();
files.ShouldAllBe(f => f.NeedsAssessment.Pets.Count() > 0);
}

[Fact]
public async Task CanGetNoEvacuationFilesByRelatedNeedsAssessmentIdOnly()
{
Expand Down

0 comments on commit 94f6297

Please sign in to comment.