Skip to content

Commit

Permalink
Merge pull request #186 from DFE-Digital/add-delivery-manager-question
Browse files Browse the repository at this point in the history
Add delivery manager question
  • Loading branch information
RogerHowellDfE authored Feb 10, 2024
2 parents 2e8f967 + 80e8b6d commit 474ebc1
Show file tree
Hide file tree
Showing 11 changed files with 1,092 additions and 222 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public ServiceAssessmentService.Domain.Model.AssessmentRequest ToDomainModel()
SeniorResponsibleOfficer = SeniorResponsibleOfficer?.ToDomainModel(),
HasProductOwnerManager = HasProductOwnerManager,
ProductOwnerManager = ProductOwnerManager?.ToDomainModel(),
HasDeliveryManager = HasDeliveryManager,
DeliveryManager = DeliveryManager?.ToDomainModel(),
CreatedAt = CreatedUtc,
UpdatedAt = UpdatedUtc,
};
Expand Down Expand Up @@ -95,6 +97,8 @@ public static Database.Entities.AssessmentRequest FromDomain(Domain.Model.Assess
SeniorResponsibleOfficerId = domainModel.SeniorResponsibleOfficer?.Id,
HasProductOwnerManager = domainModel.HasProductOwnerManager,
ProductOwnerManagerId = domainModel.ProductOwnerManager?.Id,
HasDeliveryManager = domainModel.HasDeliveryManager,
DeliveryManagerId = domainModel.DeliveryManager?.Id,
CreatedUtc = domainModel.CreatedAt.UtcDateTime,
UpdatedUtc = domainModel.UpdatedAt.UtcDateTime,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public AssessmentRequestRepository(DataContext dbContext, ILogger<AssessmentRequ
.Include(e => e.DeputyDirector)
.Include(e => e.SeniorResponsibleOfficer)
.Include(e => e.ProductOwnerManager)
.Include(e => e.DeliveryManager)
.Select(e => e.ToDomainModel())
.ToListAsync();

Expand All @@ -43,6 +44,7 @@ public AssessmentRequestRepository(DataContext dbContext, ILogger<AssessmentRequ
.Include(e => e.DeputyDirector)
.Include(e => e.SeniorResponsibleOfficer)
.Include(e => e.ProductOwnerManager)
.Include(e => e.DeliveryManager)
.Where(e => e.Id == id)
.Select(e => e.ToDomainModel())
.SingleOrDefaultAsync();
Expand Down Expand Up @@ -743,7 +745,7 @@ public async Task<RadioConditionalValidationResult<PersonValidationResult>> Upda
return validateDescriptionResult;
}

public async Task<RadioConditionalValidationResult<PersonValidationResult>> UpdateProductOwnerManagerAsync(Guid id, bool? hasProductManager, string newPersonalName, string newFamilyName, string newEmail)
public async Task<RadioConditionalValidationResult<PersonValidationResult>> UpdateProductOwnerManagerAsync(Guid id, bool? hasProductOwnerManager, string newPersonalName, string newFamilyName, string newEmail)
{
// Validate the assessment request being edited, exists
var assessmentRequest = await _dbContext.AssessmentRequests
Expand All @@ -769,7 +771,7 @@ public async Task<RadioConditionalValidationResult<PersonValidationResult>> Upda
}

// Do specific update
assessmentRequest.HasProductOwnerManager = hasProductManager;
assessmentRequest.HasProductOwnerManager = hasProductOwnerManager;

if (
string.IsNullOrWhiteSpace(newPersonalName)
Expand All @@ -792,7 +794,73 @@ public async Task<RadioConditionalValidationResult<PersonValidationResult>> Upda

// Validate the new value
var domainModel = assessmentRequest.ToDomainModel();
var validateDescriptionResult = domainModel.ValidateProductManager();
var validateDescriptionResult = domainModel.ValidateProductOwnerManager();

// If valid, save it to the database
if (validateDescriptionResult.IsValid)
{
_dbContext.AssessmentRequests.Update(assessmentRequest);
await _dbContext.SaveChangesAsync();
}
else
{
_logger.LogInformation("Attempted to update assessment request with ID {Id}, but it was not valid", id);
}

// Return the result
return validateDescriptionResult;
}

public async Task<RadioConditionalValidationResult<PersonValidationResult>> UpdateDeliveryManagerAsync(Guid id, bool? hasProductOwnerManager, string newPersonalName, string newFamilyName, string newEmail)
{
// Validate the assessment request being edited, exists
var assessmentRequest = await _dbContext.AssessmentRequests
.Include(e => e.DeliveryManager)
.SingleOrDefaultAsync(e => e.Id == id);
if (assessmentRequest is null)
{
var validationResult = new RadioConditionalValidationResult<PersonValidationResult>
{
NestedValidationResult = new()
{
IsValid = true,
},
};
validationResult.RadioQuestionValidationErrors.Add(new()
{
FieldName = nameof(assessmentRequest.Id),
ErrorMessage = $"Assessment request with ID {id} not found",
});
validationResult.IsValid = false;

return validationResult;
}

// Do specific update
assessmentRequest.HasDeliveryManager = hasProductOwnerManager;

if (
string.IsNullOrWhiteSpace(newPersonalName)
&& string.IsNullOrWhiteSpace(newFamilyName)
&& string.IsNullOrWhiteSpace(newEmail)
)
{
// No person details provided, therefore declaring that the SRO is null.
assessmentRequest.DeliveryManager = null;
}
else
{
// At least one detail about the SRO has been provided, therefore...
// Either use the existing SRO (fetched via query above) and overwrite details, or create a new one and supply details for the first time.
assessmentRequest.DeliveryManager ??= new Database.Entities.Person();
assessmentRequest.DeliveryManager.PersonalName = newPersonalName;
assessmentRequest.DeliveryManager.FamilyName = newFamilyName;
assessmentRequest.DeliveryManager.Email = newEmail;
}

// Validate the new value
var domainModel = assessmentRequest.ToDomainModel();
var validateDescriptionResult = domainModel.ValidateProductOwnerManager();

// If valid, save it to the database
if (validateDescriptionResult.IsValid)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using ServiceAssessmentService.Domain.Model;

namespace ServiceAssessmentService.Domain.Test;

public class AssessmentRequestDeliveryManagerCompletenessTests
{
private static Person ArbitraryValidPerson => new Person
{
PersonalName = "Arbitrary Personal Name",
FamilyName = "Arbitrary Family Name",
Email = "[email protected]",
};
private static Person ArbitraryIncompletePerson => new Person
{
PersonalName = null,
FamilyName = null,
Email = null,
};

public static TheoryData<bool?, Person?> CompleteCombinations => new()
{
// Complete scenarios
// - Declares Delivery Manager is known, Delivery Manager details provided
{true, ArbitraryValidPerson},
// - Declares Delivery Manager is not known, no Delivery Manager details provided
{false, null},

};

public static TheoryData<bool?, Person?> IncompleteCombinations => new()
{
// All other combinations are incomplete/invalid
{null, null},
{null, ArbitraryValidPerson},
{null, ArbitraryIncompletePerson},

{true, null},
// {true, ArbitraryValidPerson}, // ignore - valid combination
{true, ArbitraryIncompletePerson},

// {false, null}, // ignore - valid combination
{false, ArbitraryValidPerson},
{false, ArbitraryIncompletePerson},

};


[Theory]
[MemberData(nameof(CompleteCombinations))]
public void IsDeliveryManagerComplete_WHEN_CompleteCombinationOfValues_THEN_IsComplete(
bool? hasDeliveryManager,
Person? deliveryManager
)
{
// Arrange
var assessmentRequest = new AssessmentRequest
{
HasDeliveryManager = hasDeliveryManager,
DeliveryManager = deliveryManager,
};

// Act
var result = assessmentRequest.IsDeliveryManagerComplete();

// Assert
Assert.True(result);
}

[Theory]
[MemberData(nameof(IncompleteCombinations))]
public void IsDeliveryManagerComplete_WHEN_IncompleteCombinationOfValues_THEN_IsComplete(
bool? hasDeliveryManager,
Person? deliveryManager
)
{
// Arrange
var assessmentRequest = new AssessmentRequest
{
HasDeliveryManager = hasDeliveryManager,
DeliveryManager = deliveryManager,
};

// Act
var result = assessmentRequest.IsDeliveryManagerComplete();

// Assert
string deliveryManagerString = deliveryManager?.ToString() ?? "null";

Assert.False(result, $"Expected to be incomplete: " +
$"\n- DeliveryManager: {deliveryManagerString}");
}
}
Loading

0 comments on commit 474ebc1

Please sign in to comment.