Skip to content

Commit

Permalink
EYQB-687: Added the temporary privacy poicy advice page (#386)
Browse files Browse the repository at this point in the history
* EYQB-687: Added the temporary privacy poicy advice page

* Added unit test for the mock
  • Loading branch information
sam-c-dfe authored Sep 30, 2024
1 parent 904f5a1 commit d423054
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public static class AdvicePages
/// Entry ID for the "Level 6 qualification post-2014" advice page.
/// </summary>
public const string Level6QualificationPost2014 = "5aoy3C3jIEKdMo8fauvyvk";

/// <summary>
/// Entry ID for the TEMPORARY Privacy Policy page.
/// </summary>
public const string TemporaryPrivacyPolicy = "6VCAUoA8ERp0hkeT5JcM72";
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ await Task.FromResult(CreateAdvicePage("Level 6 qualification pre 2014",
AdvicePages.Level6QualificationPost2014 =>
await Task.FromResult(CreateAdvicePage("Level 6 qualification post 2014",
body, WhatLevelIsTheQualificationPath)),

AdvicePages.TemporaryPrivacyPolicy =>
await Task.FromResult(CreateAdvicePage("Temporary privacy policy",
body, WhatLevelIsTheQualificationPath)),
_ => null
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,12 @@ public async Task<IActionResult> QualificationLevel7()
return await GetView(AdvicePages.QualificationLevel7);
}

[HttpGet("privacy-policy")]
public async Task<IActionResult> PrivacyPolicy()
{
return await GetView(AdvicePages.TemporaryPrivacyPolicy);
}

private async Task<IActionResult> GetView(string advicePageId)
{
var advicePage = await contentService.GetAdvicePage(advicePageId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,15 @@ describe("A spec that tests advice pages", () => {
cy.get("#feedback-banner-heading").should("contain.text", "Feedback heading");
cy.get("#feedback-banner-body").should("contain.text", "This is the body text");
})

it("Checks the Temporary privacy policy details are on the page", () => {
cy.setCookie('user_journey', '%7B%22WhenWasQualificationStarted%22%3A%227%2F2015%22%7D');
cy.visit("/advice/privacy-policy");

cy.get("#advice-page-heading").should("contain.text", "Temporary privacy policy");
cy.get("#advice-page-body").should("contain.text", "Test Advice Page Body");

cy.get("#feedback-banner-heading").should("contain.text", "Feedback heading");
cy.get("#feedback-banner-body").should("contain.text", "This is the body text");
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -561,4 +561,66 @@ public async Task Level6QualificationPost2014_ContentServiceReturnsAdvicePage_Re

mockContentParser.Verify(x => x.ToHtml(It.IsAny<Document>()), Times.Once);
}

[TestMethod]
public async Task PrivacyPolicy_ContentServiceReturnsNoAdvicePage_RedirectsToErrorPage()
{
var mockLogger = new Mock<ILogger<AdviceController>>();
var mockContentService = new Mock<IContentService>();
var mockContentParser = new Mock<IGovUkContentParser>();

var controller = new AdviceController(mockLogger.Object, mockContentService.Object, mockContentParser.Object,
UserJourneyMockNoOp.Object);

mockContentService.Setup(x => x.GetAdvicePage(AdvicePages.TemporaryPrivacyPolicy))
.ReturnsAsync((AdvicePage?)default).Verifiable();

var result = await controller.PrivacyPolicy();

result.Should().NotBeNull();

var resultType = result as RedirectToActionResult;

resultType.Should().NotBeNull();

resultType!.ActionName.Should().Be("Index");
resultType.ControllerName.Should().Be("Error");

mockLogger.VerifyError("No content for the advice page");
}

[TestMethod]
public async Task PrivacyPolicy_ContentServiceReturnsAdvicePage_ReturnsAdvicePageModel()
{
var mockLogger = new Mock<ILogger<AdviceController>>();
var mockContentService = new Mock<IContentService>();
var mockContentParser = new Mock<IGovUkContentParser>();

var controller = new AdviceController(mockLogger.Object, mockContentService.Object, mockContentParser.Object,
UserJourneyMockNoOp.Object);

const string renderedHtmlBody = "Test html body (Privacy Policy)";

var advicePage = new AdvicePage
{ Heading = "Heading (Privacy Policy)", Body = ContentfulContentHelper.Text("Anything") };
mockContentService.Setup(x => x.GetAdvicePage(AdvicePages.TemporaryPrivacyPolicy))
.ReturnsAsync(advicePage);

mockContentParser.Setup(x => x.ToHtml(It.IsAny<Document>())).ReturnsAsync(renderedHtmlBody);

var result = await controller.PrivacyPolicy();

result.Should().NotBeNull();

var resultType = result as ViewResult;
resultType.Should().NotBeNull();

var model = resultType!.Model as AdvicePageModel;
model.Should().NotBeNull();

model!.Heading.Should().Be(advicePage.Heading);
model.BodyContent.Should().Be(renderedHtmlBody);

mockContentParser.Verify(x => x.ToHtml(It.IsAny<Document>()), Times.Once);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,19 @@ public async Task GetAdvicePage_Level6QualificationPost2014_ReturnsExpectedDetai
result.Body!.Content[0].Should().BeAssignableTo<Paragraph>()
.Which.Content.Should().ContainSingle(x => ((Text)x).Value == "Test Advice Page Body");
}

[TestMethod]
public async Task GetAdvicePage_privacyPolicy_ReturnsExpectedDetails()
{
var contentfulService = new MockContentfulService();

var result = await contentfulService.GetAdvicePage(AdvicePages.TemporaryPrivacyPolicy);
result.Should().NotBeNull();
result.Should().BeAssignableTo<AdvicePage>();
result!.Heading.Should().NotBeNullOrEmpty();
result.Body!.Content[0].Should().BeAssignableTo<Paragraph>()
.Which.Content.Should().ContainSingle(x => ((Text)x).Value == "Test Advice Page Body");
}

[TestMethod]
public async Task GetAdvicePage_UnknownEntryId_ReturnsException()
Expand Down

0 comments on commit d423054

Please sign in to comment.