Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/chore/qualification-details-refa…
Browse files Browse the repository at this point in the history
…ctor' into chore/qualification-details-refactor
  • Loading branch information
ThomasWhittington committed Jan 7, 2025
2 parents 2d20ee3 + 3dd6d96 commit 94cd7e1
Showing 1 changed file with 52 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ public void WasStartedBetweenSeptember2014AndAugust2019_CookieHasValidValueIn201

service.WasStartedBetweenSeptember2014AndAugust2019().Should().BeTrue();
}

[TestMethod]
public void WasStartedBetweenSept2014AndAug2019_CookieValueIsEmpty_Throws()
{
Expand Down Expand Up @@ -562,7 +562,7 @@ public void WasStartedBetweenSept2014AndAug2019_CookieHasInvalidValue_Throws()

action.Should().Throw<InvalidOperationException>();
}

[TestMethod]
[DataRow("8/2014")]
[DataRow("9/2019")]
Expand All @@ -582,7 +582,7 @@ public void WasStartedBetweenSept2014AndAug2019_CookieValueOutsideOfRange_Return

service.WasStartedBetweenSeptember2014AndAugust2019().Should().BeFalse();
}

[TestMethod]
[DataRow("9/2014")]
[DataRow("8/2019")]
Expand All @@ -602,42 +602,6 @@ public void WasStartedBetweenSept2014AndAug2019_CookieValueInsideOfRange_Returns

service.WasStartedBetweenSeptember2014AndAugust2019().Should().BeTrue();
}

[TestMethod]
public void GetQualificationStartedBetween2014And2019_CookieValueIsEmpty_Throws()
{
var existingModel = new UserJourneyCookieService.UserJourneyModel
{
WhenWasQualificationStarted = string.Empty
};

var mockHttpContextAccessor = SetCookieManagerWithExistingCookie(existingModel);
var mockLogger = new Mock<ILogger<UserJourneyCookieService>>();

var service = new UserJourneyCookieService(mockLogger.Object, mockHttpContextAccessor.cookieManager.Object);

var action = () => service.WasStartedBetweenSeptember2014AndAugust2019();

action.Should().Throw<InvalidOperationException>();
}

[TestMethod]
public void GetQualificationStartedBetween2014And2019_CookieHasInvalidValue_Throws()
{
var existingModel = new UserJourneyCookieService.UserJourneyModel
{
WhenWasQualificationStarted = "4"
};

var mockHttpContextAccessor = SetCookieManagerWithExistingCookie(existingModel);
var mockLogger = new Mock<ILogger<UserJourneyCookieService>>();

var service = new UserJourneyCookieService(mockLogger.Object, mockHttpContextAccessor.cookieManager.Object);

var action = () => service.WasStartedBetweenSeptember2014AndAugust2019();

action.Should().Throw<InvalidOperationException>();
}

[TestMethod]
public void GetQualificationStartedBetween2014And2019_CookieHasValidValueIn2013_ReturnsTrue()
Expand Down Expand Up @@ -671,38 +635,6 @@ public void GetQualificationStartedBetween2014And2019_CookieHasValidValueInAugus
service.WasStartedBetweenSeptember2014AndAugust2019().Should().BeFalse();
}

[TestMethod]
public void GetQualificationStartedBetween2014And2019_CookieHasValidValueInSeptember2014_ReturnsTrue()
{
var existingModel = new UserJourneyCookieService.UserJourneyModel
{
WhenWasQualificationStarted = "9/2014"
};

var mockHttpContextAccessor = SetCookieManagerWithExistingCookie(existingModel);
var mockLogger = new Mock<ILogger<UserJourneyCookieService>>();

var service = new UserJourneyCookieService(mockLogger.Object, mockHttpContextAccessor.cookieManager.Object);

service.WasStartedBetweenSeptember2014AndAugust2019().Should().BeTrue();
}

[TestMethod]
public void GetQualificationStartedBetween2014And2019_CookieHasValidValueIn2015_ReturnsTrue()
{
var existingModel = new UserJourneyCookieService.UserJourneyModel
{
WhenWasQualificationStarted = "1/2015"
};

var mockHttpContextAccessor = SetCookieManagerWithExistingCookie(existingModel);
var mockLogger = new Mock<ILogger<UserJourneyCookieService>>();

var service = new UserJourneyCookieService(mockLogger.Object, mockHttpContextAccessor.cookieManager.Object);

service.WasStartedBetweenSeptember2014AndAugust2019().Should().BeTrue();
}

[TestMethod]
public void GetQualificationStartedBetween2014And2019_CookieHasValidValueIn2018_ReturnsTrue()
{
Expand Down Expand Up @@ -887,7 +819,8 @@ public void NoAdditionalQuestions_HasAdditionalQuestionsAnswers_ReturnsFalse()

var mockCookieManager = SetCookieManagerWithExistingCookie(model);

var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance, mockCookieManager.cookieManager.Object);
var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance,
mockCookieManager.cookieManager.Object);

service.UserHasAnsweredAdditionalQuestions().Should().BeFalse();
}
Expand All @@ -900,7 +833,8 @@ public void AdditionalQuestions_HasAdditionalQuestionsAnswers_ReturnsTrue()

var mockCookieManager = SetCookieManagerWithExistingCookie(model);

var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance, mockCookieManager.cookieManager.Object);
var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance,
mockCookieManager.cookieManager.Object);

service.UserHasAnsweredAdditionalQuestions().Should().BeTrue();
}
Expand All @@ -910,7 +844,8 @@ public void SetAwardingOrganisationNotOnList_True_SetsCookieToTrue()
{
var mockCookieManager = SetCookieManagerWithExistingCookie(new UserJourneyCookieService.UserJourneyModel());

var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance, mockCookieManager.cookieManager.Object);
var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance,
mockCookieManager.cookieManager.Object);

service.SetAwardingOrganisationNotOnList(true);

Expand All @@ -926,7 +861,8 @@ public void SetAwardingOrganisationNotOnList_False_SetsCookieToFalse()
var mockCookieManager = SetCookieManagerWithExistingCookie(new UserJourneyCookieService.UserJourneyModel
{ SelectedAwardingOrganisationNotOnTheList = true });

var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance, mockCookieManager.cookieManager.Object);
var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance,
mockCookieManager.cookieManager.Object);

service.SetAwardingOrganisationNotOnList(false);

Expand All @@ -941,7 +877,8 @@ public void SetSelectedFromList_Yes_SetsCookieToYes()
{
var mockCookieManager = SetCookieManagerWithExistingCookie(new UserJourneyCookieService.UserJourneyModel());

var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance, mockCookieManager.cookieManager.Object);
var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance,
mockCookieManager.cookieManager.Object);

service.SetUserSelectedQualificationFromList(YesOrNo.Yes);

Expand All @@ -959,7 +896,8 @@ public void SetSelectedFromList_No_SetsCookieToNo()
QualificationWasSelectedFromList = YesOrNo.Yes
});

var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance, mockCookieManager.cookieManager.Object);
var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance,
mockCookieManager.cookieManager.Object);

service.SetUserSelectedQualificationFromList(YesOrNo.No);

Expand All @@ -977,30 +915,55 @@ public void GetSelectedFromList_GetsValueInCookie()
QualificationWasSelectedFromList = YesOrNo.Yes
});

var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance, mockCookieManager.cookieManager.Object);
var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance,
mockCookieManager.cookieManager.Object);

var result = service.GetQualificationWasSelectedFromList();
result.Should().Be(YesOrNo.Yes);
}

[TestMethod]
public static void SetMultipleValues_AllSetInOutboundCookie()
public void SetMultipleValues_AllSetInOutboundCookie()
{
var mockCookieManager =
SetCookieManagerWithExistingCookie(new UserJourneyCookieService.UserJourneyModel());

var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance, mockCookieManager.cookieManager.Object);
var service = new UserJourneyCookieService(NullLogger<UserJourneyCookieService>.Instance,
mockCookieManager.cookieManager.Object);

service.SetAwardingOrganisation("Awarding Organisation");
service.SetUserSelectedQualificationFromList(YesOrNo.Yes);
service.SetAdditionalQuestionsAnswers(new Dictionary<string, string> { { "1", "Answer 1" } });
service.SetQualificationNameSearchCriteria("Search Criteria");
service.SetLevelOfQualification("6");
service.SetWhenWasQualificationStarted("12/2012");
service.SetWhereWasQualificationAwarded("York");
const string awardingOrganisation = "Awarding Organisation";
service.SetAwardingOrganisation(awardingOrganisation);

CheckSerializedModelWasSet(mockCookieManager,
new UserJourneyCookieService.UserJourneyModel());
const YesOrNo userSelectedQualificationFromList = YesOrNo.Yes;
service.SetUserSelectedQualificationFromList(userSelectedQualificationFromList);

var additionalQuestionsAnswers = new Dictionary<string, string> { { "1", "Answer 1" } };
service.SetAdditionalQuestionsAnswers(additionalQuestionsAnswers);

const string searchCriteria = "Search Criteria";
service.SetQualificationNameSearchCriteria(searchCriteria);

const string level = "6";
service.SetLevelOfQualification(level);

const string dateStarted = "12/2012";
service.SetWhenWasQualificationStarted(dateStarted);

const string location = "York";
service.SetWhereWasQualificationAwarded(location);

var expectedModel = new UserJourneyCookieService.UserJourneyModel
{
WhatIsTheAwardingOrganisation = awardingOrganisation,
QualificationWasSelectedFromList = userSelectedQualificationFromList,
AdditionalQuestionsAnswers = additionalQuestionsAnswers,
SearchCriteria = searchCriteria,
LevelOfQualification = level,
WhenWasQualificationStarted = dateStarted,
WhereWasQualificationAwarded = location
};

CheckSerializedModelWasSet(mockCookieManager, expectedModel);
}

[TestMethod]
Expand Down

0 comments on commit 94cd7e1

Please sign in to comment.