From 7a83796455561ea039a89dccf1958b0c3260c01f Mon Sep 17 00:00:00 2001 From: Sam Carter Date: Thu, 18 Jul 2024 10:49:47 +0100 Subject: [PATCH] Updated to add in the reset functionality when someone starts the first step of the journey --- .../Controllers/QuestionsController.cs | 1 + .../UserJourneyCookieService/UserJourneyCookieService.cs | 2 +- .../Controllers/QuestionsControllerTests.cs | 4 ++++ .../Services/UserJourneyCookieServiceTests.cs | 8 ++++---- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs b/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs index b225afc4..5543e6fa 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Controllers/QuestionsController.cs @@ -27,6 +27,7 @@ public class QuestionsController( [HttpGet("where-was-the-qualification-awarded")] public async Task WhereWasTheQualificationAwarded() { + userJourneyCookieService.ResetUserJourneyCookie(); return await GetRadioView(QuestionPages.WhereWasTheQualificationAwarded, nameof(this.WhereWasTheQualificationAwarded), Questions); diff --git a/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/UserJourneyCookieService.cs b/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/UserJourneyCookieService.cs index cee77ac0..b298fd55 100644 --- a/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/UserJourneyCookieService.cs +++ b/src/Dfe.EarlyYearsQualification.Web/Services/UserJourneyCookieService/UserJourneyCookieService.cs @@ -12,7 +12,7 @@ public class UserJourneyCookieService(IHttpContextAccessor context, ILogger x.ResetUserJourneyCookie(), Times.Once); mockContentService.VerifyAll(); @@ -77,6 +79,8 @@ public async Task WhereWasTheQualificationAwarded_ContentServiceReturnsQuestionP mockQuestionModelValidator.Object); var result = await controller.WhereWasTheQualificationAwarded(); + + mockUserJourneyCookieService.Verify(x => x.ResetUserJourneyCookie(), Times.Once); result.Should().NotBeNull(); diff --git a/tests/Dfe.EarlyYearsQualification.UnitTests/Services/UserJourneyCookieServiceTests.cs b/tests/Dfe.EarlyYearsQualification.UnitTests/Services/UserJourneyCookieServiceTests.cs index 48f63b97..61507de8 100644 --- a/tests/Dfe.EarlyYearsQualification.UnitTests/Services/UserJourneyCookieServiceTests.cs +++ b/tests/Dfe.EarlyYearsQualification.UnitTests/Services/UserJourneyCookieServiceTests.cs @@ -414,8 +414,8 @@ private static Mock SetHttpContextWithExistingCookie(objec private static void CheckSerializedModelWasSet(Mock mockContext, string serializedModelToCheck) { - var in364Days = new DateTimeOffset(DateTime.Now.AddDays(364)); - var inOneYear = new DateTimeOffset(DateTime.Now.AddYears(1)); + var in29Minutes = new DateTimeOffset(DateTime.Now.AddMinutes(29)); + var in30Minutes = new DateTimeOffset(DateTime.Now.AddMinutes(30)); mockContext .Verify(http => @@ -425,8 +425,8 @@ private static void CheckSerializedModelWasSet(Mock mockCo options => options.Secure && options.HttpOnly - && options.Expires > in364Days - && options.Expires < inOneYear) + && options.Expires > in29Minutes + && options.Expires < in30Minutes) ), Times.Once); }