Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

262834 regulator packaging data downloading file #177

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ public class Submission : AbstractSubmission
public string? ProducerType { get; set; }
public Guid? ComplianceSchemeId { get; set; }
public string? ActualSubmissionPeriod { get; set; }
public string PomFileName { get; set; }
public string PomBlobName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ public static Submission GetTestSubmission() =>
FirstName = "Test",
LastName = "User",
Telephone = "0123 456 789",
ServiceRole = "Approved person"
ServiceRole = "Approved person",
PomBlobName = "A blob name",
PomFileName = "A Pom File.csv"
};
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using EPR.RegulatorService.Frontend.Core.Models;
using EPR.RegulatorService.Frontend.Core.Models.FileDownload;
using EPR.RegulatorService.Frontend.Core.Models.Registrations;
using EPR.RegulatorService.Frontend.Core.Models.Submissions;
using EPR.RegulatorService.Frontend.Core.Sessions;
using EPR.RegulatorService.Frontend.Web.Constants;
using EPR.RegulatorService.Frontend.Web.Controllers.Submissions;
using EPR.RegulatorService.Frontend.Web.ViewModels.Applications;
using EPR.RegulatorService.Frontend.Web.ViewModels.Registrations;
using EPR.RegulatorService.Frontend.Web.ViewModels.Submissions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -453,5 +456,312 @@ public async Task GivenSetOrResetFilterValuesInSession_WhenNotClearFilters_AndIs
JourneySessionMock.RegulatorSubmissionSession.SearchSubmissionPeriods.Should().BeEquivalentTo(submissionFiltersModel.SearchSubmissionPeriods);
JourneySessionMock.RegulatorSubmissionSession.CurrentPageNumber.Should().Be(DefaultPageNumber);
}

[TestMethod]
public async Task SubmissionsFileDownload_RedirectsToPackagingDataFileDownload()
{
// Act
var result = await _systemUnderTest.SubmissionsFileDownload();

// Assert
result.Should().NotBeNull();
result.Should().BeOfType<RedirectToActionResult>();
var redirectResult = result as RedirectToActionResult;
redirectResult.ActionName.Should().Be("PackagingDataFileDownload");
redirectResult.ControllerName.Should().Be("Submissions");
}

[TestMethod]
public void PackagingDataFileDownload_ReturnsViewWithViewModel()
{
// Act
var result = _systemUnderTest.PackagingDataFileDownload();

// Assert
result.Should().NotBeNull();
result.Should().BeOfType<ViewResult>();
((Microsoft.AspNetCore.Mvc.ViewResult)result).ViewName.Should().Be("PackagingDataFileDownload");
}

[TestMethod]
public void PackagingDataFileDownloadFailed_ReturnsViewWithViewModel()
{
// Act
var result = _systemUnderTest.PackagingDataFileDownloadFailed();

// Assert
result.Should().NotBeNull();
result.Should().BeOfType<ViewResult>();
var viewResult = result as ViewResult;
viewResult.Model.Should().NotBeNull();
viewResult.Model.Should().BeOfType<SubmissionDetailsFileDownloadViewModel>();
var model = (SubmissionDetailsFileDownloadViewModel)viewResult.Model;
model.DownloadFailed.Should().BeTrue();
model.HasIssue.Should().BeFalse();
viewResult.ViewName.Should().Be("PackagingDataFileDownloadFailed");
}


[TestMethod]
public async Task PackagingDataFileDownloadSecurityWarning_ReturnsViewWithViewModel()
{
// Arrange
var submission = _fixture.Create<Submission>();
submission.FirstName = "fstName";
submission.LastName = "lstName";
var session = new JourneySession
{
RegulatorSubmissionSession = new RegulatorSubmissionSession
{
OrganisationSubmission = submission,


}
};

_sessionManagerMock
.Setup(x => x.GetSessionAsync(It.IsAny<ISession>()))
.ReturnsAsync(session);

// Act
var result = await _systemUnderTest.PackagingDataFileDownloadSecurityWarning();

// Assert
result.Should().NotBeNull();
result.Should().BeOfType<ViewResult>();

var viewResult = result as ViewResult;
viewResult.Should().NotBeNull();
viewResult.Model.Should().NotBeNull();
viewResult.Model.Should().BeOfType<SubmissionDetailsFileDownloadViewModel>();

var model = (SubmissionDetailsFileDownloadViewModel)viewResult.Model;
model.DownloadFailed.Should().BeTrue();
model.HasIssue.Should().BeTrue();
model.SubmittedBy.Should().Be("fstName lstName"); // Validate the submittedBy field

viewResult.ViewName.Should().Be("PackagingDataFileDownloadFailed");
}


[TestMethod]
public async Task FileDownloadInProgress_ValidRequest_ReturnsFile()
{
// Arrange
var submission = _fixture.Create<Submission>();
var session = new JourneySession
{
RegulatorSubmissionSession = new RegulatorSubmissionSession
{
OrganisationSubmission = submission
}
};

_sessionManagerMock.Setup(x => x.GetSessionAsync(It.IsAny<ISession>())).ReturnsAsync(session);

using (var response = new HttpResponseMessage(System.Net.HttpStatusCode.OK)
{
Content = new StringContent("file content")
})
{
response.Content.Headers.ContentDisposition = new System.Net.Http.Headers.ContentDispositionHeaderValue("attachment")
{
FileName = "testfile.txt"
};

_facadeServiceMock.Setup(x => x.GetFileDownload(It.IsAny<FileDownloadRequest>())).ReturnsAsync(response);

// Act
var result = await _systemUnderTest.FileDownloadInProgress();

// Assert
result.Should().NotBeNull();
result.Should().BeOfType<FileStreamResult>();
var fileResult = result as FileStreamResult;
fileResult.ContentType.Should().Be("application/octet-stream");
fileResult.FileDownloadName.Should().Be("testfile.txt");
}
}

[TestMethod]
public async Task FileDownloadInProgress_FileInfected_ReturnsRedirectToAction()
{
// Arrange
var submission = _fixture.Create<Submission>();
var session = new JourneySession
{
RegulatorSubmissionSession = new RegulatorSubmissionSession
{
OrganisationSubmission = submission
}
};

_sessionManagerMock.Setup(x => x.GetSessionAsync(It.IsAny<ISession>())).ReturnsAsync(session);

using var response = new HttpResponseMessage(System.Net.HttpStatusCode.Forbidden);

_facadeServiceMock.Setup(x => x.GetFileDownload(It.IsAny<FileDownloadRequest>())).ReturnsAsync(response);

// Act
var result = await _systemUnderTest.FileDownloadInProgress();

// Assert
result.Should().NotBeNull();
result.Should().BeOfType<RedirectToActionResult>();
var redirectResult = result as RedirectToActionResult;
redirectResult.ActionName.Should().Be("PackagingDataFileDownloadSecurityWarning");
redirectResult.ControllerName.Should().BeNull();
}


[TestMethod]
public async Task FileDownloadInProgress_DownloadFailed_ReturnsRedirectToAction()
{
// Arrange
var submission = _fixture.Create<Submission>();
var session = new JourneySession
{
RegulatorSubmissionSession = new RegulatorSubmissionSession
{
OrganisationSubmission = submission
}
};

_sessionManagerMock.Setup(x => x.GetSessionAsync(It.IsAny<ISession>())).ReturnsAsync(session);

using (var response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest))
{
_facadeServiceMock.Setup(x => x.GetFileDownload(It.IsAny<FileDownloadRequest>())).ReturnsAsync(response);

// Act
var result = await _systemUnderTest.FileDownloadInProgress();

// Assert
result.Should().NotBeNull();
result.Should().BeOfType<RedirectToActionResult>();
var redirectResult = result as RedirectToActionResult;
redirectResult.ActionName.Should().Be("PackagingDataFileDownloadFailed");
redirectResult.ControllerName.Should().BeNull();
}
}

[TestMethod]
public async Task FileDownloadInProgress_DownloadFailed_ReturnsRedirectToActionXXXXXX()
{
// Arrange
var submission = _fixture.Create<Submission>();
submission.PomBlobName = null;
var session = new JourneySession
{
RegulatorSubmissionSession = new RegulatorSubmissionSession
{
OrganisationSubmission = submission
}
};

_sessionManagerMock.Setup(x => x.GetSessionAsync(It.IsAny<ISession>())).ReturnsAsync(session);

using (var response = new HttpResponseMessage(System.Net.HttpStatusCode.BadRequest))
{
_facadeServiceMock.Setup(x => x.GetFileDownload(It.IsAny<FileDownloadRequest>())).ReturnsAsync(response);

// Act
var result = await _systemUnderTest.FileDownloadInProgress();

// Assert
result.Should().NotBeNull();
result.Should().BeOfType<RedirectToActionResult>();
var redirectResult = result as RedirectToActionResult;
redirectResult.ActionName.Should().Be("PackagingDataFileDownloadFailed");
redirectResult.ControllerName.Should().BeNull();
}
}

[TestMethod]
public void FormatTimeAndDateForSubmission_ReturnsCorrectFormat_MorningTime()
{
// Arrange

var inputDate = new DateTime(2025, 1, 8, 9, 30, 0); // 9:30 AM, 8th January 2025
var expectedOutput = "9:30am on 08 January 2025";

// Act
var result = _systemUnderTest.FormatTimeAndDateForSubmission(inputDate);

// Assert
result.Should().Be(expectedOutput);
}

[TestMethod]
public void FormatTimeAndDateForSubmission_ReturnsCorrectFormat_AfternoonTime()
{
// Arrange
var inputDate = new DateTime(2025, 1, 8, 14, 15, 0); // 2:15 PM, 8th January 2025
var expectedOutput = "2:15pm on 08 January 2025";

// Act
var result = _systemUnderTest.FormatTimeAndDateForSubmission(inputDate);

// Assert
result.Should().Be(expectedOutput);
}

[TestMethod]
public void FormatTimeAndDateForSubmission_ReturnsCorrectFormat_EdgeCaseMidnight()
{
// Arrange
var inputDate = new DateTime(2025, 1, 8, 0, 0, 0); // Midnight, 8th January 2025
var expectedOutput = "12:00am on 08 January 2025";

// Act
var result = _systemUnderTest.FormatTimeAndDateForSubmission(inputDate);

// Assert
result.Should().Be(expectedOutput);
}

[TestMethod]
public void FormatTimeAndDateForSubmission_ReturnsCorrectFormat_EdgeCaseNoon()
{
// Arrange
var inputDate = new DateTime(2025, 1, 8, 12, 0, 0); // Noon, 8th January 2025
var expectedOutput = "12:00pm on 08 January 2025";

// Act
var result = _systemUnderTest.FormatTimeAndDateForSubmission(inputDate);

// Assert
result.Should().Be(expectedOutput);
}

[TestMethod]
public void FormatTimeAndDateForSubmission_ReturnsCorrectFormat_LeapYear()
{
// Arrange
var inputDate = new DateTime(2024, 2, 29, 8, 45, 0); // 8:45 AM, 29th February 2024 (leap year)
var expectedOutput = "8:45am on 29 February 2024";

// Act
var result = _systemUnderTest.FormatTimeAndDateForSubmission(inputDate);

// Assert
result.Should().Be(expectedOutput);
}

[TestMethod]
public async Task Submissions_GetSessionIsNull_CreatesNewSessionAndReturnsView()
{
// Arrange
_sessionManagerMock.Setup(m => m.GetSessionAsync(It.IsAny<ISession>())).ReturnsAsync((JourneySession)null);

// Act
var result = await _systemUnderTest.Submissions();

// Assert
Assert.IsNotNull(result);
var viewResult = result as ViewResult;
Assert.IsNotNull(viewResult);
Assert.IsInstanceOfType(viewResult.Model, typeof(SubmissionsViewModel));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public async Task GivenOnSubmissionDetailsPage_WhenSubmissionDetailsHttpGetCalle
model!.OrganisationName.Should().Be(submissionFromSession.OrganisationName);
model.SubmissionId.Should().Be(submissionFromSession.SubmissionId);
model.SubmittedBy.Should().Be($"{submissionFromSession.FirstName} {submissionFromSession.LastName}");
model.SubmissionBlobName.Should().Be(submissionFromSession.PomBlobName);
model.SubmissionFileName.Should().Be(submissionFromSession.PomFileName);

AssertBackLink(result, PagePath.Submissions);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public static class FeatureFlags
public const string RegistrationDataPeriodAndTime = "RegistrationDataPeriodAndTime";

public const string ManageRegistrationSubmissions = "ManageRegistrationSubmissions";

public const string EnableCsvDownload = "EnableCsvDownload";
}
4 changes: 4 additions & 0 deletions src/EPR.RegulatorService.Frontend.Web/Constants/PagePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static class PagePath
public const string EmailNominatedApprovedPerson = "email-nominated-approved-person";
public const string AccountPermissionsChanged = "account-permissions-changed";
public const string FileDownload = "file-download";
public const string SubmissionsFileDownload = "submissions-file-download";
public const string OrganisationDetailsFileDownload = "organisation-details-file-download";
public const string OrganisationDetailsFileDownloadFailed = "organisation-details-file-download-failed";
public const string OrganisationDetailsFileDownloadSecurityWarning = "organisation-details-file-download-security-warning";
Expand All @@ -51,6 +52,9 @@ public static class PagePath
public const string RegistrationSubmissionFileDownloadFailed = "registration-submission-download-failed";
public const string RegistrationSubmissionFileDownloadSecurityWarning = "registration-submission-download-security-warning";
public const string RegistrationSubmissionsFileDownload = "submission-file-download";
public const string PackagingDataFileDownload = "packaging-data-file-download";
public const string PackagingDataFileDownloadFailed = "packaging-data-file-download-failed";
public const string PackagingDataFileDownloadSecurityWarning = "packaging-data-file-download-security-warning";

// Non journey paths
public const string Accessibility = "accessibility";
Expand Down
Loading
Loading