<commit_before>import authUtils from './index.js';
import { getCurrentUser } from './AuthUtilsConsumer.js';
import { SIGN_IN } from '../../constants/routes.js';

const mockDisplayName = '<NAME>';
const mockEmail = '<EMAIL>';
const mockPhotoURL = 'http://www.photo-hosters.com/qwerty';
const mockUid = '1234567890';
const mockAuthenticatedUser = {
  displayName: mockDisplayName,
  email: mockEmail,
  photoURL: mockPhotoURL,
  uid: mockUid
};
const mockUnauthenticatedUser = null;

jest.mock('./AuthUtilsConsumer.js', () => ({
  getCurrentUser: jest.fn()
}));

describe('auth utility functions when authenticated', () => {
  beforeEach(() => {
    getCurrentUser.mockImplementation(() => mockAuthenticatedUser);
    expect(getCurrentUser()).toBe(mockAuthenticatedUser);
  })

  test('getUserDisplayName function', () => {
    expect(authUtils.getUserDisplayName()).toBe(mockDisplayName);
  });

  test('getUserEmail function', () => {
    expect(authUtils.getUserEmail()).toBe(mockEmail);
  });

  test('getUserPhotoUrl function', () => {
    expect(authUtils.getUserPhotoUrl()).toBe(mockPhotoURL);
  });

  test('getUserUid function', () => {
    expect(authUtils.getUserUid()).toBe(mockUid);
  });
});

// All utility functions in this scenario should do the same thing: redirect to
// the SIGN_IN page.
describe('auth utility functions when not authenticated', () => {
  beforeAll(() => {
    delete window.location;
  });

  beforeEach(() => {
    window.location = {
      href: ''
    }
    getCurrentUser.mockImplementation(() => mockUnauthenticatedUser);
    expect(getCurrentUser()).toBe(mockUnauthenticatedUser);
  });

  afterEach(() => {
    expect(window.location.href).toBe(SIGN_IN);
  })

  test('getUserDisplayName function', () => {
    authUtils.getUserDisplayName();
  });

  test('getUserEmail function', () => {
    authUtils.getUserEmail();
  });

  test('getUserPhotoUrl function', () => {
    authUtils.getUserPhotoUrl();
  });

  test('getUserUid function', () => {
    authUtils.getUserUid();
  });
});<commit_msg>Move afterEach expect statement to each test individually<commit_after>import authUtils from './index.js';
import { getCurrentUser } from './AuthUtilsConsumer.js';
import { SIGN_IN } from '../../constants/routes.js';

const mockDisplayName = '<NAME>';
const mockEmail = '<EMAIL>';
const mockPhotoURL = 'http://www.photo-hosters.com/qwerty';
const mockUid = '1234567890';
const mockAuthenticatedUser = {
  displayName: mockDisplayName,
  email: mockEmail,
  photoURL: mockPhotoURL,
  uid: mockUid
};
const mockUnauthenticatedUser = null;

jest.mock('./AuthUtilsConsumer.js', () => ({
  getCurrentUser: jest.fn()
}));

describe('auth utility functions when authenticated', () => {
  beforeEach(() => {
    getCurrentUser.mockImplementation(() => mockAuthenticatedUser);
    expect(getCurrentUser()).toBe(mockAuthenticatedUser);
  })

  test('getUserDisplayName function', () => {
    expect(authUtils.getUserDisplayName()).toBe(mockDisplayName);
  });

  test('getUserEmail function', () => {
    expect(authUtils.getUserEmail()).toBe(mockEmail);
  });

  test('getUserPhotoUrl function', () => {
    expect(authUtils.getUserPhotoUrl()).toBe(mockPhotoURL);
  });

  test('getUserUid function', () => {
    expect(authUtils.getUserUid()).toBe(mockUid);
  });
});

// All utility functions in this scenario should do the same thing: redirect to
// the SIGN_IN page.
describe('auth utility functions when not authenticated', () => {
  beforeAll(() => {
    delete window.location;
  });

  beforeEach(() => {
    window.location = {
      href: ''
    }
    getCurrentUser.mockImplementation(() => mockUnauthenticatedUser);
    expect(getCurrentUser()).toBe(mockUnauthenticatedUser);
  });

  test('getUserDisplayName function', () => {
    authUtils.getUserDisplayName();
    expect(window.location.href).toBe(SIGN_IN);
  });

  test('getUserEmail function', () => {
    authUtils.getUserEmail();
    expect(window.location.href).toBe(SIGN_IN);
  });

  test('getUserPhotoUrl function', () => {
    authUtils.getUserPhotoUrl();
    expect(window.location.href).toBe(SIGN_IN);
  });

  test('getUserUid function', () => {
    authUtils.getUserUid();
    expect(window.location.href).toBe(SIGN_IN);
  });
});
{'fraction_non_alphanumeric': 0.1702027345591702, 'fraction_numerical': 0.004714757190004715, 'mean_word_length': 4.503242542153048, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 40, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '817641', 'n_tokens_mistral': 1328, 'n_tokens_neox': 1293, 'n_words': 221}