Skip to content

Commit

Permalink
Added details link to alert details page
Browse files Browse the repository at this point in the history
  • Loading branch information
hortha committed Oct 6, 2023
1 parent d9f46bc commit 01cbcc8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@

@if (!string.IsNullOrEmpty(Model.Alert.DetailsLink))
{
<a href="@Model.Alert.DetailsLink" class="govuk-link" rel="noreferrer noopener" target="_blank" date-testid="see-full-case-details">See full case details (opens in new tab)</a>
<a href="@Model.Alert.DetailsLink" class="govuk-link" rel="noreferrer noopener" target="_blank" date-testid="full-case-details-link">See full case details (opens in new tab)</a>
}

@if (Model.IsActive)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ public async Task Get_WithAlertIdForNonExistentAlert_ReturnsNotFound()
}

[Theory]
[InlineData("2021-01-01", "2022-03-05", true, true, AlertStatus.Closed)]
[InlineData("2021-01-01", null, false, true, AlertStatus.Active)]
[InlineData("2021-01-01", null, false, false, AlertStatus.Inactive)]
[InlineData("2021-01-01", "2022-03-05", true, false, AlertStatus.Inactive)]
public async Task Get_ValidRequest_RendersExpectedContent(string startDateString, string? endDateString, bool isSpent, bool isActive, AlertStatus expectedAlertStatus)
[InlineData("2021-01-01", "2022-03-05", "http://www.gov.uk", true, true, AlertStatus.Closed)]
[InlineData("2021-01-01", null, null, false, true, AlertStatus.Active)]
[InlineData("2021-01-01", null, "http://www.gov.uk", false, false, AlertStatus.Inactive)]
[InlineData("2021-01-01", "2022-03-05", null, true, false, AlertStatus.Inactive)]
public async Task Get_ValidRequest_RendersExpectedContent(string startDateString, string? endDateString, string? detailsLink, bool isSpent, bool isActive, AlertStatus expectedAlertStatus)
{
// Arrange
var sanctionCode = "G1";
var sanctionCodeName = (await TestData.ReferenceDataCache.GetSanctionCodeByValue(sanctionCode)).dfeta_name;
var startDate = DateOnly.Parse(startDateString);
DateOnly? endDate = endDateString is not null ? DateOnly.Parse(endDateString) : null;
var person = await TestData.CreatePerson(x => x.WithSanction(sanctionCode, startDate: startDate, endDate: endDate, spent: isSpent, isActive: isActive));
var person = await TestData.CreatePerson(x => x.WithSanction(sanctionCode, startDate: startDate, endDate: endDate, spent: isSpent, detailsLink: detailsLink, isActive: isActive));

var request = new HttpRequestMessage(HttpMethod.Get, $"/alerts/{person.Sanctions.Single().SanctionId}");

Expand All @@ -56,6 +56,14 @@ public async Task Get_ValidRequest_RendersExpectedContent(string startDateString
Assert.Equal(endDate is not null ? endDate.Value.ToString("dd/MM/yyyy") : "-", alertHeader.GetElementByTestId("end-date")!.TextContent);
Assert.Equal(expectedAlertStatus.ToString(), alertHeader.GetElementByTestId("status")!.TextContent);
Assert.NotNull(doc.GetElementByTestId("alert-details"));
if (detailsLink is not null)
{
Assert.Equal(detailsLink, doc.GetElementByTestId("full-case-details-link")!.GetAttribute("href"));
}
else
{
Assert.Null(doc.GetElementByTestId("full-case-details-link"));
}
if (isActive)
{
Assert.NotNull(doc.GetElementByTestId("deactivate-button"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,10 @@ public CreatePersonBuilder WithSanction(
DateOnly? reviewDate = null,
bool spent = false,
string details = "lorem ipsum",
string? detailsLink = null,
bool isActive = true)
{
_sanctions.Add(new(Guid.NewGuid(), sanctionCode, startDate, endDate, reviewDate, spent, details, isActive));
_sanctions.Add(new(Guid.NewGuid(), sanctionCode, startDate, endDate, reviewDate, spent, details, detailsLink, isActive));
return this;
}

Expand Down Expand Up @@ -184,20 +185,26 @@ public async Task<CreatePersonResult> Execute(CrmTestData testData)
foreach (var sanction in _sanctions)
{
var sanctionCode = await testData.ReferenceDataCache.GetSanctionCodeByValue(sanction.SanctionCode);
var crmSanction = new dfeta_sanction()
{
Id = sanction.SanctionId,
dfeta_PersonId = personId.ToEntityReference(Contact.EntityLogicalName),
dfeta_SanctionCodeId = sanctionCode.Id.ToEntityReference(dfeta_sanctioncode.EntityLogicalName),
dfeta_StartDate = sanction.StartDate?.FromDateOnlyWithDqtBstFix(isLocalTime: true),
dfeta_EndDate = sanction.EndDate?.FromDateOnlyWithDqtBstFix(isLocalTime: true),
dfeta_NoReAppuntildate = sanction.ReviewDate?.FromDateOnlyWithDqtBstFix(isLocalTime: true),
dfeta_Spent = sanction.Spent,
dfeta_SanctionDetails = sanction.Details
};

if (!string.IsNullOrWhiteSpace(sanction.DetailsLink))
{
crmSanction.dfeta_DetailsLink = sanction.DetailsLink;
}

txnRequestBuilder.AddRequest(new CreateRequest()
{
Target = new dfeta_sanction()
{
Id = sanction.SanctionId,
dfeta_PersonId = personId.ToEntityReference(Contact.EntityLogicalName),
dfeta_SanctionCodeId = sanctionCode.Id.ToEntityReference(dfeta_sanctioncode.EntityLogicalName),
dfeta_StartDate = sanction.StartDate?.FromDateOnlyWithDqtBstFix(isLocalTime: true),
dfeta_EndDate = sanction.EndDate?.FromDateOnlyWithDqtBstFix(isLocalTime: true),
dfeta_NoReAppuntildate = sanction.ReviewDate?.FromDateOnlyWithDqtBstFix(isLocalTime: true),
dfeta_Spent = sanction.Spent,
dfeta_SanctionDetails = sanction.Details
}
Target = crmSanction
});

if (!sanction.IsActive)
Expand Down Expand Up @@ -265,5 +272,5 @@ public record CreatePersonResult
};
}

public record Sanction(Guid SanctionId, string SanctionCode, DateOnly? StartDate, DateOnly? EndDate, DateOnly? ReviewDate, bool Spent, string Details, bool IsActive);
public record Sanction(Guid SanctionId, string SanctionCode, DateOnly? StartDate, DateOnly? EndDate, DateOnly? ReviewDate, bool Spent, string Details, string? DetailsLink, bool IsActive);
}

0 comments on commit 01cbcc8

Please sign in to comment.