Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mailing list creation channel #1495

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public class MailingListAddMember
public int? DegreeStatusId { get; set; }
[SwaggerSchema(WriteOnly = true)]
public int? ChannelId { get; set; }

[SwaggerSchema(WriteOnly = true)]
public int? CreationChannelSourceId { get; set; }
[SwaggerSchema(WriteOnly = true)]
public int? CreationChannelServiceId { get; set; }
[SwaggerSchema(WriteOnly = true)]
public int? CreationChannelActivityId { get; set; }

public string Email { get; set; }
public string FirstName { get; set; }
Expand Down Expand Up @@ -104,9 +111,38 @@ private void ConfigureChannel(Candidate candidate)
{
spanersoraferty marked this conversation as resolved.
Show resolved Hide resolved
if (CandidateId == null)
{
candidate.ChannelId = ChannelId ?? (int?)Candidate.Channel.MailingList;
if (CreationChannelSourceId.HasValue)
{
candidate.ChannelId = null;
// NB: CreationChannel should be true only if it is the first ContactChannelCreation record
AddCandidateCreationChannel(candidate, !candidate.ContactChannelCreations.Any());
}
else
{
candidate.ChannelId = ChannelId ?? (int?)Candidate.Channel.MailingList;
}
}
else // Candidate record already exists
{
// NB: we do not update a candidate's ChannelId for an existing record
// NB: CreationChannel should always be false for existing candidates
if (CreationChannelSourceId.HasValue)
{
AddCandidateCreationChannel(candidate, false);
}
}
}

private void AddCandidateCreationChannel(Candidate candidate, bool creationChannel)
{
candidate.ContactChannelCreations.Add(new ContactChannelCreation()
{
CreationChannel = creationChannel,
CreationChannelSourceId = CreationChannelSourceId,
CreationChannelServiceId = CreationChannelServiceId,
CreationChannelActivityId = CreationChannelActivityId,
});
}

private void AddQualification(Candidate candidate)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public void Constructor_WithCandidate_MapsCorrectly()
}

[Fact]
public void Candidate_MapsCorrectly()
public void ExistingCandidate_MapsCorrectly()
{
var request = new MailingListAddMember()
{
Expand All @@ -76,7 +76,10 @@ public void Candidate_MapsCorrectly()
FirstName = "John",
LastName = "Doe",
AddressPostcode = "KY11 9YU",
WelcomeGuideVariant = "variant1"
WelcomeGuideVariant = "variant1",
CreationChannelSourceId = 222750003,
CreationChannelServiceId = 222750002,
CreationChannelActivityId = 222750001,
};

var candidate = request.Candidate;
Expand Down Expand Up @@ -112,6 +115,32 @@ public void Candidate_MapsCorrectly()
candidate.Qualifications.First().DegreeStatusId.Should().Be(request.DegreeStatusId);
candidate.Qualifications.First().TypeId.Should().Be((int)CandidateQualification.DegreeType.Degree);
candidate.Qualifications.First().Id.Should().Be(request.QualificationId);

var contactChannelCreation = candidate.ContactChannelCreations.First();
contactChannelCreation.CreationChannel.Should().Be(false);
contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId);
contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId);
contactChannelCreation.CreationChannelActivityId.Should().Be(request.CreationChannelActivityId);
candidate.ChannelId.Should().Be(null);
}

[Fact]
public void NewCandidate_MapsCreationChannelCorrectly()
{
var request = new MailingListAddMember()
{
CandidateId = null,
CreationChannelSourceId = 222750003,
CreationChannelServiceId = 222750002,
CreationChannelActivityId = 222750001,
};

var contactChannelCreation = request.Candidate.ContactChannelCreations.First();
contactChannelCreation.CreationChannel.Should().Be(true);
contactChannelCreation.CreationChannelSourceId.Should().Be(request.CreationChannelSourceId);
contactChannelCreation.CreationChannelServiceId.Should().Be(request.CreationChannelServiceId);
contactChannelCreation.CreationChannelActivityId.Should().Be(request.CreationChannelActivityId);
request.Candidate.ChannelId.Should().Be(null);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ public void Validate_WhenValid_HasNoErrors()
FirstName = "John",
LastName = "Doe",
AddressPostcode = "KY11 9YU",
CreationChannelSourceId = 222750003,
CreationChannelServiceId = 222750002,
CreationChannelActivityId = 222750001,
};

var result = _validator.TestValidate(request);
Expand Down
Loading