title: how to prevent cypress POST request creating actual data in database
body: <p>I have react app testing with cypress.
  I am trying to create custom login command to use it throughout the testing. </p>
  
  <p>The issue is that <code>cy.request('POST', '/api/admin/user/register', {userInfo})</code> creates actual data in database which I absolutely don't want.</p>
  
  <p>another issue is that 'login' button does not change to 'logout'. On the test, request returns 200, token exist in localStorage. I guess 'isLoggedIn' state (which is saved in redux storage on login success) need to be set in cypress.</p>
  
  <p>How can I work around ?</p>
  
  <h2>commands.js</h2>
  
  <pre><code>Cypress.Commands.add('login', userType =&gt; {
    const types = {
      admin: {
        username,
        companyName,
        password,
        contactNo,
        bankAccountId,
        email,
        mealPrice,
        businessType,
        admin: true,
      },
      user: {
        username,
        companyName,
        password,
        contactNo,
        bankAccountId,
        email,
        mealPrice,
        businessType,
        admin: false,
      },
    };
  
    const userInfo = types[userType];
  
    return cy
      .request('POST', '/api/admin/user/register', { userInfo })
  .then(()=&gt;{
    cy.route({
      url: '/api/auth/login',
      method: 'POST',
      body: {
        username: userInfo.username,
        password: userInfo.password,
      },
    }).then(({ body }) =&gt; window.localStorage.setItem('token', body.token));
  })
  });
  </code></pre>
  
  <h2>user.spec.js</h2>
  
  <pre><code>describe('user', () =&gt; {
    beforeEach(() =&gt; {});
    it('can visit the app', () =&gt; {
      cy.login('user').then(() =&gt; {
        expect(window.localStorage.getItem('token')).to.exist;
        cy.visit('/');
        cy.contains('로그아웃');
      });
    });
  });
  </code></pre>
  
  <h2>navBar.js</h2>
  
  <pre><code>const Navbar = ({ isLoggedIn, handleUserLogout }) =&gt; (
    &lt;div className="flex justify-between"&gt;
      {/* calling isLoggedIn() directly from localStoragy does not re-render the component on router history change. */}
      {isLoggedIn ? (
        &lt;button
          type="button"
          className="nav--login-btn td-none c-text br f-mini"
          onClick={handleUserLogout}
        &gt;
          logout
        &lt;/button&gt;
      ) : (
        &lt;Link className="nav--login-btn td-none c-text br f-mini" to="/login"&gt;
          login
        &lt;/Link&gt;
      )}
    &lt;/div&gt;
  );
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/G4iYP.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/G4iYP.jpg" alt="enter image description here"></a></p>