Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/utils/resend.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ describe('emailIsBad', () => {
expect(result).toBe(true);
});

it('should return true for emails with an integer local part', () => {
const result = emailIsBad('123456@example.com');
expect(result).toBe(true);
});

it('should return false for legitimate email domains', () => {
const legitimateEmails = [
'user@gmail.com',
Expand Down Expand Up @@ -163,6 +168,11 @@ describe('fakeSubscribe', () => {
const result = await fakeSubscribe({ email: '4@apexgunparts.space' });
expect(result).toEqual({ success: true });
});

it('should return success for integer local part emails', async () => {
const result = await fakeSubscribe({ email: '123@example.com' });
expect(result).toEqual({ success: true });
});
});

describe('isContactEvent', () => {
Expand Down Expand Up @@ -475,6 +485,23 @@ describe('subscribe', () => {
expect(resend.contacts.create).not.toHaveBeenCalled();
});

it('should return fake response for integer local part emails', async () => {
const badSubscriber = {
email: '999@example.com',
firstName: 'Spam',
lastName: 'Bot',
};

const result = await subscribe(badSubscriber);
expect(result).toEqual({
data: {
id: '123',
},
error: null,
});
expect(resend.contacts.create).not.toHaveBeenCalled();
});

it('should create contact for legitimate emails when contact does not exist', async () => {
const legitimateSubscriber = {
email: 'user@example.com',
Expand Down
4 changes: 3 additions & 1 deletion src/utils/resend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,10 @@ export const getSubscriberCount = async () => {
const BAD_DOMAINS = ['mailinator.com', 'abhoward.site', 'apexgunparts.space'];

export const emailIsBad = (email: string) => {
const localPart = email.split('@')[0];
const domain = email.split('@')[1]?.toLowerCase();
return BAD_DOMAINS.includes(domain);
const hasIntegerLocalPart = /^\d+$/.test(localPart);
return BAD_DOMAINS.includes(domain) || hasIntegerLocalPart;
Comment on lines +241 to +244
};

/**
Expand Down