diff --git a/goofy-client/libs/user-profile-shared/src/lib/user-profile.util.spec.ts b/goofy-client/libs/user-profile-shared/src/lib/user-profile.util.spec.ts index ae917f16f9f511ccb7370dece2ff6d1ac0902981..85fd3359240dc3c3354d6150938cbb2d097f15a9 100644 --- a/goofy-client/libs/user-profile-shared/src/lib/user-profile.util.spec.ts +++ b/goofy-client/libs/user-profile-shared/src/lib/user-profile.util.spec.ts @@ -7,20 +7,20 @@ describe('UserProfileUtil', () => { describe('existsName', () => { - it('should return true if only firstName exists', () => { - const exists: boolean = existsName({ ...createUserProfileResource(), lastName: null }); + it.each([null, EMPTY_STRING])('should return true if only firstName exists and lastName has value %s', (value: null | string) => { + const exists: boolean = existsName({ ...createUserProfileResource(), lastName: value }); expect(exists).toBeTruthy(); }) - it('should return true if only lastName exists', () => { - const exists: boolean = existsName({ ...createUserProfileResource(), firstName: null }); + it.each([null, EMPTY_STRING])('should return true if only lastName exists and firstName has value %s', (value: null | string) => { + const exists: boolean = existsName({ ...createUserProfileResource(), firstName: value }); expect(exists).toBeTruthy(); }) - it('should return false if either firstName nor lastName exists', () => { - const exists: boolean = existsName({ ...createUserProfileResource(), firstName: null, lastName: null }); + it.each([null, EMPTY_STRING])('should return false if either firstName nor lastName exists', (value: null | string) => { + const exists: boolean = existsName({ ...createUserProfileResource(), firstName: value, lastName: value }); expect(exists).toBeFalsy(); }) diff --git a/goofy-client/libs/user-profile-shared/src/lib/user-profile.util.ts b/goofy-client/libs/user-profile-shared/src/lib/user-profile.util.ts index b9c72b2074c642e428fc5c15ed3e72cd62f724ed..1746fece6f93669f2d00c0ea672883eb7b2abb45 100644 --- a/goofy-client/libs/user-profile-shared/src/lib/user-profile.util.ts +++ b/goofy-client/libs/user-profile-shared/src/lib/user-profile.util.ts @@ -1,4 +1,4 @@ -import { EMPTY_STRING, getFirstLetter, getStringValue, isNotNull } from '@goofy-client/tech-shared'; +import { EMPTY_STRING, getFirstLetter, getStringValue, isNotEmpty, isNotNull } from '@goofy-client/tech-shared'; import { isNull } from 'lodash-es'; import { UserProfileResource } from './user-profile.model'; @@ -6,7 +6,7 @@ export const NO_NAME_MESSAGE: string = 'Benutzer ohne hinterlegtem Namen'; export const UNKNOWN_USER: string = 'Unbekannter Benutzer'; export function existsName(userProfile: UserProfileResource): boolean { - return isNotNull(userProfile.firstName) || isNotNull(userProfile.lastName); + return (isNotEmpty(userProfile.firstName) && isNotNull(userProfile.firstName)) || (isNotEmpty(userProfile.lastName) && isNotNull(userProfile.lastName)); } export function getUserName(userProfile: UserProfileResource): string {