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

CSCTTV-4024 trim whitespaces from name properties #244

Merged
merged 1 commit into from
Oct 4, 2024
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
48 changes: 48 additions & 0 deletions aspnetcore/src/api.Tests/Services_Tests/UserProfileServiceTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,5 +560,53 @@ public void GetProfileSettings()
Assert.Equal(expectedProfileSettings.Hidden, actualProfileSettings.Hidden);
Assert.Equal(expectedProfileSettings.PublishNewOrcidData, actualProfileSettings.PublishNewOrcidData);
}

[Fact(DisplayName = "ProfileSettings from DimUserProfile")]
public void GetFullNameFromLastNameAndFistNames_01()
{
// Arrange
UserProfileService userProfileService = new();
string expectedFullname = "Smith John";
// Act
string actualFullname = userProfileService.GetFullname("Smith", "John");
// Assert
Assert.Equal(expectedFullname, actualFullname);
}

[Fact(DisplayName = "ProfileSettings from DimUserProfile - last name is empty")]
public void GetFullNameFromLastNameAndFistNames_02()
{
// Arrange
UserProfileService userProfileService = new();
string expectedFullname = "John";
// Act
string actualFullname = userProfileService.GetFullname("", "John");
// Assert
Assert.Equal(expectedFullname, actualFullname);
}

[Fact(DisplayName = "ProfileSettings from DimUserProfile - fist name is empty")]
public void GetFullNameFromLastNameAndFistNames_03()
{
// Arrange
UserProfileService userProfileService = new();
string expectedFullname = "Smith";
// Act
string actualFullname = userProfileService.GetFullname("Smith", "");
// Assert
Assert.Equal(expectedFullname, actualFullname);
}

[Fact(DisplayName = "ProfileSettings from DimUserProfile - trim whitespaces")]
public void GetFullNameFromLastNameAndFistNames_04()
{
// Arrange
UserProfileService userProfileService = new();
string expectedFullname = "Smith John";
// Act
string actualFullname = userProfileService.GetFullname(" Smith ", " John ");
// Assert
Assert.Equal(expectedFullname, actualFullname);
}
}
}
15 changes: 11 additions & 4 deletions aspnetcore/src/api/Services/UserProfileService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,13 @@ public bool IsResearchActivityDuplicate(int aYear, string aNameFi, string aNameE
aNameSv == bNameSv);
}

/*
* Get fullName from lastName and firstNames
*/
public string GetFullname(string lastName, string firstNames)
{
return $"{lastName.Trim()} {firstNames.Trim()}".Trim();
}

/*
* Search and add data from TTV database.
Expand Down Expand Up @@ -1120,9 +1127,9 @@ public async Task<ProfileEditorDataResponse> GetProfileDataAsync(int userprofile
profileDataResponse.personal.names.Add(
new ProfileEditorName()
{
FirstNames = p.DimName_FirstNames,
LastName = p.DimName_LastName,
FullName = $"{p.DimName_LastName} {p.DimName_FirstNames}", // Populate for Elasticsearch queries
FirstNames = p.DimName_FirstNames.Trim(),
LastName = p.DimName_LastName.Trim(),
FullName = GetFullname(p.DimName_LastName, p.DimName_FirstNames), // Populate for Elasticsearch queries
itemMeta = new ProfileEditorItemMeta(

id: p.FactFieldValues_DimNameId,
Expand All @@ -1140,7 +1147,7 @@ public async Task<ProfileEditorDataResponse> GetProfileDataAsync(int userprofile
profileDataResponse.personal.otherNames.Add(
new ProfileEditorName()
{
FullName = p.DimName_FullName,
FullName = p.DimName_FullName.Trim(),
itemMeta = new ProfileEditorItemMeta(
id: p.FactFieldValues_DimNameId,
type: Constants.ItemMetaTypes.PERSON_OTHER_NAMES,
Expand Down
Loading