const schema = require('../fixtures/schema_public.json'); const isEmailAvailableUrl = '**/rest/deutsch/V1/customers/isEmailAvailable'; const checkPasswordUrl = '**/rest/deutsch/V1/integration/customer/token'; describe('Login', () => { beforeEach(() => { cy.server(); }); it('works with valid email and password', () => { cy.viewport('macbook-15'); cy.mockGraphql({ schema: schema, operations: { Login: variables => { return { login: { errors: [], message: "success", success: true } } }, } }); cy.route('POST', isEmailAvailableUrl, 'false'); cy.route({ method: 'POST', url: checkPasswordUrl, response: 'token12345ABCD+', }); cy.visit('/hello'); cy.checkEmailAvailable('feuz@aebi.ch'); cy.get('[data-cy="login-title"]').contains('Bitte geben Sie das passende Passwort ein'); cy.enterPassword('abcd1234'); // As we cannot set the cookie in the right manner, we just check for the absence of errors. // In real world the user gets redirect to another page cy.get('[data-cy="email-local-errors"]').should('not.exist'); }); it('displays error message if password is wrong', () => { cy.viewport('macbook-15'); cy.route('POST', isEmailAvailableUrl, 'false'); cy.route({ method: 'POST', status: 401, response: { message: "Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vor\u00fcbergehend deaktiviert." }, url: checkPasswordUrl }); cy.visit('/hello'); cy.checkEmailAvailable('feuz@aebi.ch'); cy.get('[data-cy="login-title"]').contains('Bitte geben Sie das passende Passwort ein'); cy.enterPassword('abcd1234'); cy.get('[data-cy="password-errors"]').contains('Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vorübergehend deaktiviert.'); }); it('displays error message if input is not an email address', () => { cy.viewport('macbook-15'); cy.visit('/hello'); cy.checkEmailAvailable('feuzaebi.ch'); cy.get('[data-cy="email-local-errors"]').contains('Bitte geben Sie eine gülitge E-Mail an'); }) });