mirror of
https://github.com/directus/directus.git
synced 2026-04-03 03:00:39 -04:00
* add unit tests to several API util functions * fix timezone tests to account for daylight saving * add a note for future reference * Update api/src/utils/get-date-formatted.test.ts Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> * remove unnecessary note as it is not an issue * fix getEnv mock in validate-env test Co-authored-by: Brainslug <br41nslug@users.noreply.github.com> Co-authored-by: Rijk van Zanten <rijkvanzanten@me.com>
26 lines
873 B
TypeScript
26 lines
873 B
TypeScript
import { expect, test } from 'vitest';
|
|
|
|
import { userName } from './user-name';
|
|
|
|
const unknownUser = 'Unknown User';
|
|
|
|
test('should return "Unknown User" when user is undefined', () => {
|
|
expect(userName(undefined as any)).toBe(unknownUser);
|
|
});
|
|
|
|
test('should return "Test User" when user first name is "Test" and last name is "User"', () => {
|
|
expect(userName({ first_name: 'Test', last_name: 'User' })).toBe('Test User');
|
|
});
|
|
|
|
test('should return "Test" when user first name is "Test" but does not have last name', () => {
|
|
expect(userName({ first_name: 'Test' })).toBe('Test');
|
|
});
|
|
|
|
test('should return user email when user only has email without first name and last name', () => {
|
|
expect(userName({ email: 'test@example.com' })).toBe('test@example.com');
|
|
});
|
|
|
|
test('should return "Unknown User" when user is empty', () => {
|
|
expect(userName({})).toBe(unknownUser);
|
|
});
|