2023-11-29 04:55:41 -08:00
|
|
|
import validator from 'validator';
|
2023-11-27 02:56:06 -08:00
|
|
|
import type { PublicUser } from '@/Interfaces';
|
2023-11-29 04:55:41 -08:00
|
|
|
import type { User } from '@/databases/entities/User';
|
2023-11-27 02:56:06 -08:00
|
|
|
|
|
|
|
export const validateUser = (user: PublicUser) => {
|
|
|
|
expect(typeof user.id).toBe('string');
|
|
|
|
expect(user.email).toBeDefined();
|
|
|
|
expect(user.firstName).toBeDefined();
|
|
|
|
expect(user.lastName).toBeDefined();
|
|
|
|
expect(typeof user.isOwner).toBe('boolean');
|
|
|
|
expect(user.isPending).toBe(false);
|
|
|
|
expect(user.signInType).toBe('email');
|
|
|
|
expect(user.settings).toBe(null);
|
|
|
|
expect(user.personalizationAnswers).toBeNull();
|
|
|
|
expect(user.password).toBeUndefined();
|
|
|
|
expect(user.globalRole).toBeDefined();
|
|
|
|
};
|
2023-11-29 04:55:41 -08:00
|
|
|
|
|
|
|
export const assertInviteUserSuccessResponse = (data: UserInvitationResponse) => {
|
|
|
|
expect(validator.isUUID(data.user.id)).toBe(true);
|
|
|
|
expect(data.user.inviteAcceptUrl).toBeUndefined();
|
|
|
|
expect(data.user.email).toBeDefined();
|
|
|
|
expect(data.user.emailSent).toBe(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
export const assertInviteUserErrorResponse = (data: UserInvitationResponse) => {
|
|
|
|
expect(validator.isUUID(data.user.id)).toBe(true);
|
|
|
|
expect(data.user.inviteAcceptUrl).toBeDefined();
|
|
|
|
expect(data.user.email).toBeDefined();
|
|
|
|
expect(data.user.emailSent).toBe(false);
|
|
|
|
expect(data.error).toBeDefined();
|
|
|
|
};
|
|
|
|
|
|
|
|
export const assertInvitedUsersOnDb = (user: User) => {
|
|
|
|
expect(user.firstName).toBeNull();
|
|
|
|
expect(user.lastName).toBeNull();
|
|
|
|
expect(user.personalizationAnswers).toBeNull();
|
|
|
|
expect(user.password).toBeNull();
|
|
|
|
expect(user.isPending).toBe(true);
|
|
|
|
};
|
|
|
|
|
|
|
|
export type UserInvitationResponse = {
|
|
|
|
user: Pick<User, 'id' | 'email'> & { inviteAcceptUrl: string; emailSent: boolean };
|
|
|
|
error?: string;
|
|
|
|
};
|