Skip to content

Commit

Permalink
Merge pull request #247 from DFE-Digital/mailing-list-event-subscript…
Browse files Browse the repository at this point in the history
…ion-logic

Only create event subscription if postcode is provided
  • Loading branch information
ethax-ross authored Sep 14, 2020
2 parents 5c2e03e + 6803807 commit cacf16f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
15 changes: 6 additions & 9 deletions GetIntoTeachingApi/Models/MailingListAddMember.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,20 @@ private void ConfigureSubscriptions(Candidate candidate)
candidate.MailingListSubscriptionDoNotPostalMail = true;
candidate.MailingListSubscriptionDoNotSendMm = false;

if (string.IsNullOrWhiteSpace(AddressPostcode))
{
return;
}

candidate.HasEventsSubscription = true;
candidate.EventsSubscriptionTypeId = (int)Candidate.SubscriptionType.LocalEvent;
candidate.EventsSubscriptionChannelId = ChannelId ?? (int)Candidate.SubscriptionChannel.Events;
candidate.EventsSubscriptionStartAt = DateTime.UtcNow;
candidate.EventsSubscriptionDoNotEmail = false;
candidate.EventsSubscriptionDoNotBulkEmail = false;
candidate.EventsSubscriptionDoNotBulkPostalMail = true;
candidate.EventsSubscriptionDoNotPostalMail = true;
candidate.EventsSubscriptionDoNotSendMm = false;

if (string.IsNullOrWhiteSpace(AddressPostcode))
{
candidate.EventsSubscriptionTypeId = (int)Candidate.SubscriptionType.SingleEvent;
}
else
{
candidate.EventsSubscriptionTypeId = (int)Candidate.SubscriptionType.LocalEvent;
}
}

private void AcceptPrivacyPolicy(Candidate candidate)
Expand Down
6 changes: 3 additions & 3 deletions GetIntoTeachingApiTests/Models/MailingListAddMemberTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,14 @@ public void Candidate_MapsCorrectly()
}

[Fact]
public void Candidate_AddressPostcodeNotProvided_EventsSubscriptionTypeIsSingleEvent()
public void Candidate_AddressPostcodeNotProvided_EventsSubscriptionIsNotCreated()
{
var request = new MailingListAddMember()
{
AddressPostcode = null,
};

request.Candidate.EventsSubscriptionTypeId.Should().Be((int)Candidate.SubscriptionType.SingleEvent);
request.Candidate.HasEventsSubscription.Should().BeNull();
}

[Fact]
Expand All @@ -154,7 +154,7 @@ public void Candidate_ChannelIdWhenCandidateIdIsNotNull_IsNull()
[Fact]
public void Candidate_WhenChannelIsProvided_SetsOnAllModels()
{
var request = new MailingListAddMember() { ChannelId = 123 };
var request = new MailingListAddMember() { ChannelId = 123, AddressPostcode = "TE7 8KE" };

request.Candidate.ChannelId.Should().Be(123);
request.Candidate.MailingListSubscriptionChannelId.Should().Be(123);
Expand Down

0 comments on commit cacf16f

Please sign in to comment.