diff --git a/client/cypress/integration/login.spec.js b/client/cypress/integration/login.spec.js new file mode 100644 index 00000000..1fa53081 --- /dev/null +++ b/client/cypress/integration/login.spec.js @@ -0,0 +1,51 @@ +const schema = require('../fixtures/schema.json'); + +const isEmailAvailableUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/customers/isEmailAvailable'; +const checkPasswordUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/customers'; + +describe('Login', () => { + beforeEach(() => { + cy.server(); + }); + + it('works with valid email and password', () => { + cy.viewport('macbook-15'); + cy.route('POST', isEmailAvailableUrl, "false"); + cy.route('POST', checkPasswordUrl, "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'); + }); + + 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'); + }) +}); diff --git a/client/cypress/support/commands.js b/client/cypress/support/commands.js index 208fac7e..dffead6c 100644 --- a/client/cypress/support/commands.js +++ b/client/cypress/support/commands.js @@ -29,6 +29,7 @@ // import 'cypress-graphql-mock'; import '@iam4x/cypress-graphql-mock'; + Cypress.Commands.add('apolloLogin', (username, password) => { const payload = { 'operationName': 'Login', @@ -129,3 +130,14 @@ Cypress.Commands.add('register', (firstname, lastname, email, licenseKey) => { cy.get('[data-cy=register-button]').click(); }); + +Cypress.Commands.add("checkEmailAvailable", (email) => { + cy.get('[data-cy="email-input"]').type(email); + cy.get('[data-cy="hello-button"]').click(); +}); + +Cypress.Commands.add("enterPassword", (password) => { + cy.get('[data-cy="password-input"]').type(password); + cy.get('[data-cy="login-button"]').click(); +}); + diff --git a/client/package-lock.json b/client/package-lock.json index b27a9409..9cf5a439 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -7164,7 +7164,7 @@ }, "minimist": { "version": "1.2.0", - "resolved": "http://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", + "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.0.tgz", "integrity": "sha1-o1AIsg9BOD7sH7kU9M1d95omQoQ=", "dev": true }, @@ -11569,6 +11569,7 @@ "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" diff --git a/client/src/pages/hello.vue b/client/src/pages/hello.vue index 899573b3..00e9d17c 100644 --- a/client/src/pages/hello.vue +++ b/client/src/pages/hello.vue @@ -23,12 +23,6 @@ class="skillboxform-input__error" data-cy="email-local-errors" >{{ errors.first('email') }} - {{ error }}
@@ -82,7 +76,6 @@ export default { data() { return { email: '', - emailErrors: [], submitted: false }; }, diff --git a/client/src/pages/license-activation.vue b/client/src/pages/license-activation.vue index bf1ce55d..94869b01 100644 --- a/client/src/pages/license-activation.vue +++ b/client/src/pages/license-activation.vue @@ -54,7 +54,7 @@