Skip to content

Commit 05fd19c

Browse files
authored
CSCTTV-4024 trim whitespaces from name properties (#244)
1 parent 1c76d3d commit 05fd19c

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

aspnetcore/src/api.Tests/Services_Tests/UserProfileServiceTest.cs

+48
Original file line numberDiff line numberDiff line change
@@ -560,5 +560,53 @@ public void GetProfileSettings()
560560
Assert.Equal(expectedProfileSettings.Hidden, actualProfileSettings.Hidden);
561561
Assert.Equal(expectedProfileSettings.PublishNewOrcidData, actualProfileSettings.PublishNewOrcidData);
562562
}
563+
564+
[Fact(DisplayName = "ProfileSettings from DimUserProfile")]
565+
public void GetFullNameFromLastNameAndFistNames_01()
566+
{
567+
// Arrange
568+
UserProfileService userProfileService = new();
569+
string expectedFullname = "Smith John";
570+
// Act
571+
string actualFullname = userProfileService.GetFullname("Smith", "John");
572+
// Assert
573+
Assert.Equal(expectedFullname, actualFullname);
574+
}
575+
576+
[Fact(DisplayName = "ProfileSettings from DimUserProfile - last name is empty")]
577+
public void GetFullNameFromLastNameAndFistNames_02()
578+
{
579+
// Arrange
580+
UserProfileService userProfileService = new();
581+
string expectedFullname = "John";
582+
// Act
583+
string actualFullname = userProfileService.GetFullname("", "John");
584+
// Assert
585+
Assert.Equal(expectedFullname, actualFullname);
586+
}
587+
588+
[Fact(DisplayName = "ProfileSettings from DimUserProfile - fist name is empty")]
589+
public void GetFullNameFromLastNameAndFistNames_03()
590+
{
591+
// Arrange
592+
UserProfileService userProfileService = new();
593+
string expectedFullname = "Smith";
594+
// Act
595+
string actualFullname = userProfileService.GetFullname("Smith", "");
596+
// Assert
597+
Assert.Equal(expectedFullname, actualFullname);
598+
}
599+
600+
[Fact(DisplayName = "ProfileSettings from DimUserProfile - trim whitespaces")]
601+
public void GetFullNameFromLastNameAndFistNames_04()
602+
{
603+
// Arrange
604+
UserProfileService userProfileService = new();
605+
string expectedFullname = "Smith John";
606+
// Act
607+
string actualFullname = userProfileService.GetFullname(" Smith ", " John ");
608+
// Assert
609+
Assert.Equal(expectedFullname, actualFullname);
610+
}
563611
}
564612
}

aspnetcore/src/api/Services/UserProfileService.cs

+11-4
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,13 @@ public bool IsResearchActivityDuplicate(int aYear, string aNameFi, string aNameE
550550
aNameSv == bNameSv);
551551
}
552552

553+
/*
554+
* Get fullName from lastName and firstNames
555+
*/
556+
public string GetFullname(string lastName, string firstNames)
557+
{
558+
return $"{lastName.Trim()} {firstNames.Trim()}".Trim();
559+
}
553560

554561
/*
555562
* Search and add data from TTV database.
@@ -1120,9 +1127,9 @@ public async Task<ProfileEditorDataResponse> GetProfileDataAsync(int userprofile
11201127
profileDataResponse.personal.names.Add(
11211128
new ProfileEditorName()
11221129
{
1123-
FirstNames = p.DimName_FirstNames,
1124-
LastName = p.DimName_LastName,
1125-
FullName = $"{p.DimName_LastName} {p.DimName_FirstNames}", // Populate for Elasticsearch queries
1130+
FirstNames = p.DimName_FirstNames.Trim(),
1131+
LastName = p.DimName_LastName.Trim(),
1132+
FullName = GetFullname(p.DimName_LastName, p.DimName_FirstNames), // Populate for Elasticsearch queries
11261133
itemMeta = new ProfileEditorItemMeta(
11271134

11281135
id: p.FactFieldValues_DimNameId,
@@ -1140,7 +1147,7 @@ public async Task<ProfileEditorDataResponse> GetProfileDataAsync(int userprofile
11401147
profileDataResponse.personal.otherNames.Add(
11411148
new ProfileEditorName()
11421149
{
1143-
FullName = p.DimName_FullName,
1150+
FullName = p.DimName_FullName.Trim(),
11441151
itemMeta = new ProfileEditorItemMeta(
11451152
id: p.FactFieldValues_DimNameId,
11461153
type: Constants.ItemMetaTypes.PERSON_OTHER_NAMES,

0 commit comments

Comments
 (0)