<commit_before>const process = require('process');
const E2eHelpers = require('./e2e-helpers');
const Timeouts = require('./timeouts');
const mock = require('./mock-helpers');

function setUserToken(token, client) {
  client.execute((inToken) => {
    window.sessionStorage.userToken = inToken;
  },
  [token],
  (val) => {
    if (val.state !== 'success') {
      // eslint-disable-next-line no-console
      console.log(`Result of setting user token: ${JSON.stringify(val)}`);
    }
  });
}

function getLogoutUrl() {
  return 'http://example.com/fake_logout_url';
}

/* eslint-disable camelcase */
function initUserMock(token, level) {
  mock(token, {
    path: '/v0/user',
    verb: 'get',
    value: {
      data: {
        attributes: {
          profile: {
            email: '<EMAIL>',
            loa: {
              current: level
            },
            first_name: 'Jane',
            middle_name: '',
            last_name: 'Doe',
            gender: 'F',
            birth_date: '1985-01-01'
          },
          veteran_status: {
            status: "OK",
            is_veteran: true,
          },
          in_progress_forms: [],
          prefills_available: [],
          services: ['facilities', 'hca', 'edu-benefits', 'evss-claims', 'user-profile', 'rx', 'messaging'],
          health_terms_current: true,
          va_profile: {
            status: 'OK',
            birth_date: '19511118',
            family_name: 'Hunter',
            gender: 'M',
            given_names: ['Julio', 'E'],
            active_status: 'active'
          }
        }
      }
    }
  });
}

function initLogoutMock(token) {
  mock(token, {
    path: '/v0/sessions',
    verb: 'delete',
    value: {
      logout_via_get: getLogoutUrl()
    }
  });
}
/* eslint-enable camelcase */

let tokenCounter = 0;

function getUserToken() {
  return `token-${process.pid}-${tokenCounter++}`;
}

function logIn(token, client, url, level) {
  initUserMock(token, level);
  initLogoutMock(token);

  client
    .url(`${E2eHelpers.baseUrl}${url}`)
    .waitForElementVisible('body', Timeouts.normal);

  setUserToken(token, client);

  client
    .url(`${E2eHelpers.baseUrl}${url}`)
    .waitForElementVisible('body', Timeouts.normal);

  E2eHelpers.overrideSmoothScrolling(client);

  return client;
}

function testUnauthedUserFlow(client, path) {
  const token = getUserToken();
  const appURL = `${E2eHelpers.baseUrl}${path}`;

  initLogoutMock(token);

  client
    .url(appURL)
    .waitForElementVisible('body', Timeouts.normal);

  client
    .waitForElementVisible('.react-container', Timeouts.normal)
    .expect.element('h1').text.to.equal('Log In to Your Vets.gov Account');

  logIn(token, client, path, 1)
    .waitForElementVisible('.react-container', Timeouts.normal)
    .expect.element('h1').text.to.equal('Verify your Identity with ID.me');
  client
    .expect.element('button.usa-button-big').text.to.equal('Get Started');
}

module.exports = {
  getLogoutUrl,
  getUserToken,
  initLogoutMock,
  initUserMock,
  logIn,
  testUnauthedUserFlow,
  setUserToken
};
<commit_msg>Change to singlequote to satisfy lint<commit_after>const process = require('process');
const E2eHelpers = require('./e2e-helpers');
const Timeouts = require('./timeouts');
const mock = require('./mock-helpers');

function setUserToken(token, client) {
  client.execute((inToken) => {
    window.sessionStorage.userToken = inToken;
  },
  [token],
  (val) => {
    if (val.state !== 'success') {
      // eslint-disable-next-line no-console
      console.log(`Result of setting user token: ${JSON.stringify(val)}`);
    }
  });
}

function getLogoutUrl() {
  return 'http://example.com/fake_logout_url';
}

/* eslint-disable camelcase */
function initUserMock(token, level) {
  mock(token, {
    path: '/v0/user',
    verb: 'get',
    value: {
      data: {
        attributes: {
          profile: {
            email: '<EMAIL>',
            loa: {
              current: level
            },
            first_name: 'Jane',
            middle_name: '',
            last_name: 'Doe',
            gender: 'F',
            birth_date: '1985-01-01'
          },
          veteran_status: {
            status: 'OK',
            is_veteran: true,
          },
          in_progress_forms: [],
          prefills_available: [],
          services: ['facilities', 'hca', 'edu-benefits', 'evss-claims', 'user-profile', 'rx', 'messaging'],
          health_terms_current: true,
          va_profile: {
            status: 'OK',
            birth_date: '19511118',
            family_name: 'Hunter',
            gender: 'M',
            given_names: ['Julio', 'E'],
            active_status: 'active'
          }
        }
      }
    }
  });
}

function initLogoutMock(token) {
  mock(token, {
    path: '/v0/sessions',
    verb: 'delete',
    value: {
      logout_via_get: getLogoutUrl()
    }
  });
}
/* eslint-enable camelcase */

let tokenCounter = 0;

function getUserToken() {
  return `token-${process.pid}-${tokenCounter++}`;
}

function logIn(token, client, url, level) {
  initUserMock(token, level);
  initLogoutMock(token);

  client
    .url(`${E2eHelpers.baseUrl}${url}`)
    .waitForElementVisible('body', Timeouts.normal);

  setUserToken(token, client);

  client
    .url(`${E2eHelpers.baseUrl}${url}`)
    .waitForElementVisible('body', Timeouts.normal);

  E2eHelpers.overrideSmoothScrolling(client);

  return client;
}

function testUnauthedUserFlow(client, path) {
  const token = getUserToken();
  const appURL = `${E2eHelpers.baseUrl}${path}`;

  initLogoutMock(token);

  client
    .url(appURL)
    .waitForElementVisible('body', Timeouts.normal);

  client
    .waitForElementVisible('.react-container', Timeouts.normal)
    .expect.element('h1').text.to.equal('Log In to Your Vets.gov Account');

  logIn(token, client, path, 1)
    .waitForElementVisible('.react-container', Timeouts.normal)
    .expect.element('h1').text.to.equal('Verify your Identity with ID.me');
  client
    .expect.element('button.usa-button-big').text.to.equal('Get Started');
}

module.exports = {
  getLogoutUrl,
  getUserToken,
  initLogoutMock,
  initUserMock,
  logIn,
  testUnauthedUserFlow,
  setUserToken
};

{'fraction_non_alphanumeric': 0.15565581695133743, 'fraction_numerical': 0.009023525620367387, 'mean_word_length': 2.6511764705882355, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1749393', 'n_tokens_mistral': 2064, 'n_tokens_neox': 2033, 'n_words': 363}