6657 Refactor and fix blocklist (#6803)
Closes #6657 - Fix listeners - Refactor jobs to take array of events - Fix calendar events and messages deletion --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -2,67 +2,67 @@ import { isEmailBlocklisted } from 'src/modules/blocklist/utils/is-email-blockli
|
||||
|
||||
describe('isEmailBlocklisted', () => {
|
||||
it('should return true if email is blocklisted', () => {
|
||||
const channelHandle = 'abc@example.com';
|
||||
const channelHandles = ['abc@example.com'];
|
||||
const email = 'hello@twenty.com';
|
||||
const blocklist = ['hello@twenty.com', 'hey@twenty.com'];
|
||||
const result = isEmailBlocklisted(channelHandle, email, blocklist);
|
||||
const result = isEmailBlocklisted(channelHandles, email, blocklist);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
it('should return false if email is not blocklisted', () => {
|
||||
const channelHandle = 'abc@example.com';
|
||||
const channelHandles = ['abc@example.com'];
|
||||
const email = 'hello@twenty.com';
|
||||
const blocklist = ['hey@example.com'];
|
||||
const result = isEmailBlocklisted(channelHandle, email, blocklist);
|
||||
const result = isEmailBlocklisted(channelHandles, email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return false if email is null', () => {
|
||||
const channelHandle = 'abc@twenty.com';
|
||||
const channelHandles = ['abc@twenty.com'];
|
||||
const email = null;
|
||||
const blocklist = ['@example.com'];
|
||||
const result = isEmailBlocklisted(channelHandle, email, blocklist);
|
||||
const result = isEmailBlocklisted(channelHandles, email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return true for subdomains', () => {
|
||||
const channelHandle = 'abc@example.com';
|
||||
const channelHandles = ['abc@example.com'];
|
||||
const email = 'hello@twenty.twenty.com';
|
||||
const blocklist = ['@twenty.com'];
|
||||
const result = isEmailBlocklisted(channelHandle, email, blocklist);
|
||||
const result = isEmailBlocklisted(channelHandles, email, blocklist);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
it('should return false for domains which end with blocklisted domain but are not subdomains', () => {
|
||||
const channelHandle = 'abc@example.com';
|
||||
const channelHandles = ['abc@example.com'];
|
||||
const email = 'hello@twentytwenty.com';
|
||||
const blocklist = ['@twenty.com'];
|
||||
const result = isEmailBlocklisted(channelHandle, email, blocklist);
|
||||
const result = isEmailBlocklisted(channelHandles, email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return false if email is undefined', () => {
|
||||
const channelHandle = 'abc@example.com';
|
||||
const channelHandles = ['abc@example.com'];
|
||||
const email = undefined;
|
||||
const blocklist = ['@twenty.com'];
|
||||
const result = isEmailBlocklisted(channelHandle, email, blocklist);
|
||||
const result = isEmailBlocklisted(channelHandles, email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
it('should return true if email ends with blocklisted domain', () => {
|
||||
const channelHandle = 'abc@example.com';
|
||||
const channelHandles = ['abc@example.com'];
|
||||
const email = 'hello@twenty.com';
|
||||
const blocklist = ['@twenty.com'];
|
||||
const result = isEmailBlocklisted(channelHandle, email, blocklist);
|
||||
const result = isEmailBlocklisted(channelHandles, email, blocklist);
|
||||
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('should return false if email is same as channel handle', () => {
|
||||
const channelHandle = 'hello@twenty.com';
|
||||
const channelHandles = ['hello@twenty.com'];
|
||||
const email = 'hello@twenty.com';
|
||||
const blocklist = ['@twenty.com'];
|
||||
const result = isEmailBlocklisted(channelHandle, email, blocklist);
|
||||
const result = isEmailBlocklisted(channelHandles, email, blocklist);
|
||||
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
@ -1,11 +1,9 @@
|
||||
// TODO: Move inside blocklist module
|
||||
|
||||
export const isEmailBlocklisted = (
|
||||
channelHandle: string,
|
||||
channelHandle: string[],
|
||||
email: string | null | undefined,
|
||||
blocklist: string[],
|
||||
): boolean => {
|
||||
if (!email || email === channelHandle) {
|
||||
if (!email || channelHandle.includes(email)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user