Skip to content

The open alternative to Salesforce, designed for AI.

1.4 KB
Raw Blame
import { getValidInviteEmails } from '@/onboarding/utils/getValidInviteEmails';

describe('getValidInviteEmails', () => {
  it('should keep valid emails in their original order', () => {
    expect(
      getValidInviteEmails(['[email protected]', '[email protected]']),
    ).toEqual(['[email protected]', '[email protected]']);
  });

  it('should count a repeated email once', () => {
    expect(
      getValidInviteEmails([
        '[email protected]',
        '[email protected]',
        '[email protected]',
      ]),
    ).toEqual(['[email protected]', '[email protected]']);
  });

  it('should count an email once whatever its case', () => {
    expect(
      getValidInviteEmails([
        '[email protected]',
        '[email protected]',
        '[email protected]',
      ]),
    ).toEqual(['[email protected]', '[email protected]']);
  });

  it('should skip empty and undefined fields', () => {
    expect(getValidInviteEmails(['', undefined, '[email protected]'])).toEqual([
      '[email protected]',
    ]);
  });

  it('should skip malformed emails', () => {
    expect(
      getValidInviteEmails([
        'katherine@example',
        'not an email',
        '[email protected]',
      ]),
    ).toEqual(['[email protected]']);
  });

  it('should skip emails with surrounding whitespace', () => {
    expect(getValidInviteEmails([' [email protected] '])).toEqual([]);
  });
});