{"size": 1376, "ext": "js", "max_stars_repo_path": "__tests__/src/clients/paymentServer/address/validateUsername.test.js", "max_stars_repo_name": "blockfirm/wallet-id-app", "max_stars_repo_stars_event_min_datetime": "2019-01-30T18:45:51.000Z", "max_stars_repo_stars_event_max_datetime": "2021-08-25T05:46:01.000Z", "max_issues_repo_path": "__tests__/src/clients/paymentServer/address/validateUsername.test.js", "max_issues_repo_name": "blockfirm/wallet-id-app", "max_issues_repo_issues_event_min_datetime": "2018-11-27T21:30:42.000Z", "max_issues_repo_issues_event_max_datetime": "2021-09-01T04:53:44.000Z", "max_forks_repo_path": "__tests__/src/clients/paymentServer/address/validateUsername.test.js", "max_forks_repo_name": "blockfirm/wallet-id-app", "max_forks_repo_forks_event_min_datetime": "2019-03-31T08:26:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-02-27T22:27:03.000Z"}
{"max_stars_count": 20, "max_issues_count": 8, "max_forks_count": 6, "avg_line_length": 34.4, "max_line_length": 97, "alphanum_fraction": 0.6598837209}
import validateUsername from '../../../../../src/clients/paymentServer/address/validateUsername';

describe('validateUsername', () => {
  it('is a function', () => {
    expect(typeof validateUsername).toBe('function');
  });

  it('accepts one argument', () => {
    expect(validateUsername.length).toBe(1);
  });

  it('throws an error when the username is empty', () => {
    expect(validateUsername.bind(null, '')).toThrowError();
  });

  it('throws an error when the username is undefined', () => {
    expect(validateUsername.bind(null)).toThrowError();
  });

  it('throws an error when the username is longer than 30 characters', () => {
    const longUsername = '5cbfc5ed-65a1-47c8-abeb-b6b08a';
    expect(validateUsername.bind(null, longUsername)).toThrowError();
  });

  it('throws an error when the username contains non-latin letters', () => {
    expect(validateUsername.bind(null, 'åäösd')).toThrowError();
  });

  it('throws an error when the username contains uppercase letters', () => {
    expect(validateUsername.bind(null, 'UpperCase')).toThrowError();
  });

  it('returns true when the username only contains a-z, 0-9, _, and .', () => {
    expect(validateUsername('joe')).toBe(true);
    expect(validateUsername('john_123')).toBe(true);
    expect(validateUsername('test.')).toBe(true);
    expect(validateUsername('98798')).toBe(true);
  });
});
