4746 create created listener on blocklist for calendar (#5046)
Follows #5031. Closes #4746
This commit is contained in:
@ -0,0 +1,39 @@
|
||||
import { isEmailBlocklisted } from 'src/modules/calendar-messaging-participant/utils/is-email-blocklisted.util';
|
||||
|
||||
describe('isEmailBlocklisted', () => {
|
||||
it('should return true if email is blocklisted', () => {
|
||||
const email = 'hello@example.com';
|
||||
const blocklist = ['hello@example.com', 'hey@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
it('should return false if email is not blocklisted', () => {
|
||||
const email = 'hello@twenty.com';
|
||||
const blocklist = ['hey@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return false if email is null', () => {
|
||||
const email = null;
|
||||
const blocklist = ['@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return false if email is undefined', () => {
|
||||
const email = undefined;
|
||||
const blocklist = ['@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return true if email ends with blocklisted domain', () => {
|
||||
const email = 'hello@example.com';
|
||||
const blocklist = ['@example.com'];
|
||||
const result = isEmailBlocklisted(email, blocklist);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
@ -0,0 +1,16 @@
|
||||
export const isEmailBlocklisted = (
|
||||
email: string | null | undefined,
|
||||
blocklist: string[],
|
||||
): boolean => {
|
||||
if (!email) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return blocklist.some((item) => {
|
||||
if (item.startsWith('@')) {
|
||||
return email.endsWith(item);
|
||||
}
|
||||
|
||||
return email === item;
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user