-
-
Notifications
You must be signed in to change notification settings - Fork 768
/
Copy pathextract-user.test.ts
35 lines (28 loc) · 1.21 KB
/
extract-user.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { SYSTEM_USER } from '../../lib/types';
import type { IUser } from '../server-impl';
import { extractUserIdFromUser, extractUsernameFromUser } from './extract-user';
describe('extractUsernameFromUser', () => {
test('Should return the email if it exists', () => {
const user = {
email: 'ratatoskr@yggdrasil.com',
username: 'ratatoskr',
} as IUser;
expect(extractUsernameFromUser(user)).toBe(user.email);
});
test('Should return the username if it exists and email does not', () => {
const user = {
username: 'ratatoskr',
} as IUser;
expect(extractUsernameFromUser(user)).toBe(user.username);
});
test('Should return the system user if neither email nor username exists', () => {
const user = {} as IUser;
expect(extractUsernameFromUser(user)).toBe(SYSTEM_USER.username);
expect(extractUserIdFromUser(user)).toBe(SYSTEM_USER.id);
});
test('Should return the system user if user is null', () => {
const user = null as unknown as IUser;
expect(extractUsernameFromUser(user)).toBe(SYSTEM_USER.username);
expect(extractUserIdFromUser(user)).toBe(SYSTEM_USER.id);
});
});