4746 create created listener on blocklist for calendar (#5046)

Follows #5031.
Closes #4746
This commit is contained in:
bosiraphael
2024-04-23 11:46:27 +02:00
committed by GitHub
parent 8f6460bec5
commit 824786ff04
20 changed files with 278 additions and 31 deletions

View File

@ -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);
});
});

View File

@ -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;
});
};