From d423054533d7091ed8a6012646cf241c552c3451 Mon Sep 17 00:00:00 2001
From: Sam C <156680559+sam-c-dfe@users.noreply.github.com>
Date: Mon, 30 Sep 2024 12:06:06 +0100
Subject: [PATCH] EYQB-687: Added the temporary privacy poicy advice page
(#386)
* EYQB-687: Added the temporary privacy poicy advice page
* Added unit test for the mock
---
.../Constants/AdvicePages.cs | 5 ++
.../Content/MockContentfulService.cs | 4 ++
.../Controllers/AdviceController.cs | 6 ++
.../cypress/e2e/pages/advice-spec.cy.js | 11 ++++
.../Controllers/AdviceControllerTests.cs | 62 +++++++++++++++++++
.../Mocks/MockContentfulServiceTests.cs | 13 ++++
6 files changed, 101 insertions(+)
diff --git a/src/Dfe.EarlyYearsQualification.Content/Constants/AdvicePages.cs b/src/Dfe.EarlyYearsQualification.Content/Constants/AdvicePages.cs
index b00e7b1cb..c639934b3 100644
--- a/src/Dfe.EarlyYearsQualification.Content/Constants/AdvicePages.cs
+++ b/src/Dfe.EarlyYearsQualification.Content/Constants/AdvicePages.cs
@@ -46,4 +46,9 @@ public static class AdvicePages
/// Entry ID for the "Level 6 qualification post-2014" advice page.
///
public const string Level6QualificationPost2014 = "5aoy3C3jIEKdMo8fauvyvk";
+
+ ///
+ /// Entry ID for the TEMPORARY Privacy Policy page.
+ ///
+ public const string TemporaryPrivacyPolicy = "6VCAUoA8ERp0hkeT5JcM72";
}
\ No newline at end of file
diff --git a/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs b/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs
index 87af5ea9d..816930db1 100644
--- a/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs
+++ b/src/Dfe.EarlyYearsQualification.Mock/Content/MockContentfulService.cs
@@ -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
};
}
diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs
index 8d5233d64..4ecee5de8 100644
--- a/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs
+++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/AdviceController.cs
@@ -87,6 +87,12 @@ public async Task QualificationLevel7()
return await GetView(AdvicePages.QualificationLevel7);
}
+ [HttpGet("privacy-policy")]
+ public async Task PrivacyPolicy()
+ {
+ return await GetView(AdvicePages.TemporaryPrivacyPolicy);
+ }
+
private async Task GetView(string advicePageId)
{
var advicePage = await contentService.GetAdvicePage(advicePageId);
diff --git a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/pages/advice-spec.cy.js b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/pages/advice-spec.cy.js
index c736dde20..6db7a30e4 100644
--- a/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/pages/advice-spec.cy.js
+++ b/tests/Dfe.EarlyYearsQualification.E2ETests/cypress/e2e/pages/advice-spec.cy.js
@@ -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");
+ })
})
\ No newline at end of file
diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/AdviceControllerTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/AdviceControllerTests.cs
index 5540bbe6c..01bc8a79b 100644
--- a/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/AdviceControllerTests.cs
+++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Controllers/AdviceControllerTests.cs
@@ -561,4 +561,66 @@ public async Task Level6QualificationPost2014_ContentServiceReturnsAdvicePage_Re
mockContentParser.Verify(x => x.ToHtml(It.IsAny()), Times.Once);
}
+
+ [TestMethod]
+ public async Task PrivacyPolicy_ContentServiceReturnsNoAdvicePage_RedirectsToErrorPage()
+ {
+ var mockLogger = new Mock>();
+ var mockContentService = new Mock();
+ var mockContentParser = new Mock();
+
+ 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>();
+ var mockContentService = new Mock();
+ var mockContentParser = new Mock();
+
+ 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())).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()), Times.Once);
+ }
}
\ No newline at end of file
diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs
index e8f77a497..54822d204 100644
--- a/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs
+++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Mocks/MockContentfulServiceTests.cs
@@ -136,6 +136,19 @@ public async Task GetAdvicePage_Level6QualificationPost2014_ReturnsExpectedDetai
result.Body!.Content[0].Should().BeAssignableTo()
.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();
+ result!.Heading.Should().NotBeNullOrEmpty();
+ result.Body!.Content[0].Should().BeAssignableTo()
+ .Which.Content.Should().ContainSingle(x => ((Text)x).Value == "Test Advice Page Body");
+ }
[TestMethod]
public async Task GetAdvicePage_UnknownEntryId_ReturnsException()