Skip to main content
Skip table of contents

Mock user functions

This page contains information on any currently-used custom Cypress commands focused on the use of mock users for e2e testing.

Mock User: cy.login(userData)

Without providing any arguments, it will use a default user. To be signed in as a custom-defined user, you may pass in a compatible object as the argument. It should have the same shape as the response body for the /v0/user API endpoint. See src/platform/testing/e2e/cypress/support/commands/login.js for the default user object as an example to copy and modify as needed.

CODE
cy.login();

const myUser = {
  data: {
    attributes: {
      ...
    },
  },
};

cy.login(myUser);

Source file:

vets-website/login.js at main ยท department-of-veterans-affairs/vets-website

Description:

Allows us to simulate a signed-in session.

Arguments:

cy.login() takes an optional argument which is assigned to the userData parameter which defaults to the following mockUser object if no argument is given:

CODE
const mockUser = {
  data: {
    attributes: {
      profile: {
        sign_in: {
          service_name: 'idme',
        },
        email: 'fake@fake.com',
        loa: { current: 3 },
        first_name: 'Jane',
        middle_name: '',
        last_name: 'Doe',
        gender: 'F',
        birth_date: '1985-01-01',
        verified: true,
      },
      veteran_status: {
        status: 'OK',
        is_veteran: true,
        served_in_military: true,
      },
      in_progress_forms: [
        {
          form: VA_FORM_IDS.FORM_10_10EZ,
          metadata: {},
        },
      ],
      prefills_available: [VA_FORM_IDS.FORM_21_526EZ],
      services: [
        'facilities',
        'hca',
        'edu-benefits',
        'evss-claims',
        'form526',
        'user-profile',
        'health-records',
        'rx',
        'messaging',
      ],
      va_profile: {
        status: 'OK',
        birth_date: '19511118',
        family_name: 'Hunter',
        gender: 'M',
        given_names: ['Julio', 'E'],
        active_status: 'active',
        facilities: [
          {
            facility_id: '983',
            isCerner: false,
          },
          {
            facility_id: '984',
            isCerner: false,
          },
        ],
      },
    },
  },
  meta: { errors: null },
};

To sign in as a custom-defined user, copy the mockUser object, modify it as needed, and pass it as an argument to cy.login(). The custom-defined user object should have the same shape as the response body for the /v0/user API endpoint.



JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.