Skip to content

Instantly share code, notes, and snippets.

@nottyo
Created May 1, 2022 03:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nottyo/d46a6cc212938b64dd2f0a0e9fa739cf to your computer and use it in GitHub Desktop.
Save nottyo/d46a6cc212938b64dd2f0a0e9fa739cf to your computer and use it in GitHub Desktop.
login-with-session
Cypress.Commands.add('lineLoginWithSession', (email, password) => {
// v2 with session cache
const args = { email, password };
cy.intercept({
method: 'POST',
url: 'https://api.line.me/oauth2/v2.1/token',
}).as('createToken');
cy.session(
// use email, password as a session cache key
args,
() => {
cy.visit(Cypress.config('baseUrl'));
cy.get('[data-testid="login"]').click();
cy.origin('https://access.line.me', { args }, ({ email, password }) => {
cy.get('input[type="text"]').type(email);
cy.get('input[type="password"]').type(password);
cy.get('button[type="submit"]').click();
});
// confirm that login is success!
cy.wait('@createToken').its('response.statusCode').should('eq', 200);
},
{
validate: () => {
const accessTokenKey = `LIFF_STORE:${Cypress.env('LIFF_ID')}:accessToken`;
expect(localStorage.getItem(accessTokenKey)).to.not.be.empty;
},
},
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment