diff --git a/client/cypress/integration/login-page.spec.js b/client/cypress/integration/local-login.spec.js similarity index 100% rename from client/cypress/integration/login-page.spec.js rename to client/cypress/integration/local-login.spec.js diff --git a/client/cypress/integration/registration-page.spec.js b/client/cypress/integration/registration-page.spec.js deleted file mode 100644 index d01d40de..00000000 --- a/client/cypress/integration/registration-page.spec.js +++ /dev/null @@ -1,77 +0,0 @@ -describe('The Regstration Page', () => { - // works locally, but not in pipelines. - // it('register user', () => { - - // let timestamp = Math.round((new Date()).getTime() / 1000); - - // const firstname = 'pesche'; - // const lastname = 'peschemann'; - // const email = `skillboxtest${timestamp}@iterativ.ch`; - // const licenseKey = 'c1fa2e2a-2e27-480d-8469-2e88414c4ad8'; - - // cy.visit('/register'); - // cy.register(firstname, lastname, email, licenseKey); - // cy.get('.reset__heading').contains('Schauen Sie in Ihr Postfach'); - // }); - - it('user sees error message if firstname is omitted', () => { - let timestamp = Math.round((new Date()).getTime() / 1000); - const firstname = ''; - const lastname = 'peschemann'; - const email = `skillboxtest${timestamp}@iterativ.ch`; - const licenseKey = 'c1fa2e2a-2e27-480d-8469-2e88414c4ad8'; - - cy.visit('/register'); - cy.register(firstname, lastname, email, licenseKey); - cy.get('[data-cy="firstname-local-errors"]').contains('Vorname ist ein Pflichtfeld.'); - }); - - it('user sees error message if lastname is omitted', () => { - let timestamp = Math.round((new Date()).getTime() / 1000); - const firstname = 'pesche'; - const lastname = ''; - const email = `skillboxtest${timestamp}@iterativ.ch`; - const licenseKey = 'c1fa2e2a-2e27-480d-8469-2e88414c4ad8'; - - cy.visit('/register'); - cy.register(firstname, lastname, email, licenseKey); - cy.get('[data-cy="lastname-local-errors"]').contains('Nachname ist ein Pflichtfeld.'); - }); - - it('user sees error message if email is omitted', () => { - let timestamp = Math.round((new Date()).getTime() / 1000); - const firstname = 'pesche'; - const lastname = 'peschemann'; - const email = ``; - const licenseKey = 'c1fa2e2a-2e27-480d-8469-2e88414c4ad8'; - - cy.visit('/register'); - cy.register(firstname, lastname, email, licenseKey); - cy.get('[data-cy="email-local-errors"]').contains('E-Mail ist ein Pflichtfeld.'); - }); - - it('user sees error message if license is omitted', () => { - let timestamp = Math.round((new Date()).getTime() / 1000); - const firstname = 'pesche'; - const lastname = 'peschemann'; - const email = `skillboxtest${timestamp}@iterativ.ch`; - const licenseKey = ''; - - cy.visit('/register'); - cy.register(firstname, lastname, email, licenseKey); - cy.get('[data-cy="licenseKey-local-errors"]').contains('Lizenz ist ein Pflichtfeld.'); - }); - - it('user sees error message if license key is wrong', () => { - let timestamp = Math.round((new Date()).getTime() / 1000); - const firstname = 'pesche'; - const lastname = 'peschemann'; - const email = `skillboxtest${timestamp}@iterativ.ch`; - const licenseKey = 'asdsafsadfsadfasdf'; - - cy.visit('/register'); - cy.register(firstname, lastname, email, licenseKey); - cy.get('[data-cy="licenseKey-remote-errors"]').contains('Die angegebenen Lizenz ist unglültig'); - }); - -}) diff --git a/client/cypress/integration/registration.spec.js b/client/cypress/integration/registration.spec.js new file mode 100644 index 00000000..c747399a --- /dev/null +++ b/client/cypress/integration/registration.spec.js @@ -0,0 +1,118 @@ +const schema = require('../fixtures/schema.json'); + +const isEmailAvailableUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/customers/isEmailAvailable'; +const registerUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/customers'; + +let registrationResponse = { + id: 84215, + group_id: 1, + confirmation: "91cf39007547feae7e33778d89fc71db", + created_at: "2020-02-06 13:56:54", + updated_at: "2020-02-06 13:56:54", + created_in: "hep verlag", + email: "feuz@aebi.ch", + firstname: "Kari", + lastname: "Feuz", + prefix: "Herr", + gender: 1, + store_id: 1, + website_id: 1, + addresses: [] +}; + +describe('Registration', () => { + beforeEach(() => { + cy.viewport('macbook-15'); + cy.server(); + }); + + it('works with valid data', () => { + cy.route('POST', isEmailAvailableUrl, "true"); + cy.route('POST', registerUrl, registrationResponse); + + cy.visit('/hello'); + cy.checkEmailAvailable(registrationResponse.email); + + cy.get('[data-cy="registration-title"]').contains('Damit Sie mySkillbox verwenden können, müssen Sie ein Konto erstellen.'); + cy.register(registrationResponse.gender, registrationResponse.firstname, registrationResponse.lastname, 'Abcd1234!', 'Abcd1234!'); + cy.get('[data-cy="email-check"]').contains('Ein Email ist auf dem Weg, bitte überprüfen sie ihre E-mail Konto.'); + }); + + it('displays error if firstname is missing', () => { + cy.route('POST', isEmailAvailableUrl, "true"); + cy.route('POST', registerUrl, registrationResponse); + + cy.visit('/hello'); + cy.checkEmailAvailable(registrationResponse.email); + + cy.get('[data-cy="registration-title"]').contains('Damit Sie mySkillbox verwenden können, müssen Sie ein Konto erstellen.'); + cy.register(registrationResponse.gender, '', registrationResponse.lastname, 'Abcd1234!', 'Abcd1234!'); + cy.get('[data-cy="firstname-local-errors"]').contains('Vorname ist ein Pflichtfeld'); + }); + + it('displays error if lastname is missing', () => { + cy.route('POST', isEmailAvailableUrl, "true"); + cy.route('POST', registerUrl, registrationResponse); + + cy.visit('/hello'); + cy.checkEmailAvailable(registrationResponse.email); + + cy.get('[data-cy="registration-title"]').contains('Damit Sie mySkillbox verwenden können, müssen Sie ein Konto erstellen.'); + cy.register(registrationResponse.gender, registrationResponse.firstname, '', 'Abcd1234!', 'Abcd1234!'); + cy.get('[data-cy="lastname-local-errors"]').contains('Nachname ist ein Pflichtfeld'); + }); + + it('displays error if password is missing', () => { + cy.route('POST', isEmailAvailableUrl, "true"); + cy.route('POST', registerUrl, registrationResponse); + + cy.visit('/hello'); + cy.checkEmailAvailable(registrationResponse.email); + + cy.get('[data-cy="registration-title"]').contains('Damit Sie mySkillbox verwenden können, müssen Sie ein Konto erstellen.'); + cy.register(registrationResponse.gender, registrationResponse.firstname, registrationResponse.lastname, '', 'Abcd1234!'); + cy.get('[data-cy="password-local-errors"]').contains('Passwort ist ein Pflichtfeld'); + }); + + it('displays error if passwords are not secure', () => { + cy.route('POST', isEmailAvailableUrl, "true"); + cy.route('POST', registerUrl, registrationResponse); + + cy.visit('/hello'); + cy.checkEmailAvailable(registrationResponse.email); + + cy.get('[data-cy="registration-title"]').contains('Damit Sie mySkillbox verwenden können, müssen Sie ein Konto erstellen.'); + cy.register(registrationResponse.gender, registrationResponse.firstname, registrationResponse.lastname, 'Abcd1234', 'Abcd1234'); + cy.get('[data-cy="password-local-errors"]').contains('Das Passwort muss Grossbuchstaben, Zahlen und Sonderzeichen beinhalten und mindestens 8 Zeichen lang sein'); + }); + + it('displays error if passwords are too short', () => { + cy.route('POST', isEmailAvailableUrl, "true"); + cy.route('POST', registerUrl, registrationResponse); + + cy.visit('/hello'); + cy.checkEmailAvailable(registrationResponse.email); + + cy.get('[data-cy="registration-title"]').contains('Damit Sie mySkillbox verwenden können, müssen Sie ein Konto erstellen.'); + cy.register(registrationResponse.gender, registrationResponse.firstname, registrationResponse.lastname, 'Abcd12!', 'Abcd12!'); + cy.get('[data-cy="password-local-errors"]').contains('Das Passwort muss Grossbuchstaben, Zahlen und Sonderzeichen beinhalten und mindestens 8 Zeichen lang sein'); + }); + + it('displays error if passwords are not matching', () => { + cy.route('POST', isEmailAvailableUrl, "true"); + cy.route('POST', registerUrl, registrationResponse); + + cy.visit('/hello'); + cy.checkEmailAvailable(registrationResponse.email); + + cy.get('[data-cy="registration-title"]').contains('Damit Sie mySkillbox verwenden können, müssen Sie ein Konto erstellen.'); + cy.register(registrationResponse.gender, registrationResponse.firstname, registrationResponse.lastname, 'Abcd1234!', 'Abcd129999!'); + cy.get('[data-cy="passwordConfirmation-local-errors"]').contains('Die Bestätigung von Passwort wiederholen stimmt nicht überein'); + }); + + it('redirects to hello if email is missing', () => { + cy.visit('/register'); + cy.get('[data-cy="hello-title"]').contains('Wollen sie mySkillbox jetzt im Unterricht verwenden?'); + }); + +}); diff --git a/client/cypress/support/commands.js b/client/cypress/support/commands.js index dffead6c..8781507d 100644 --- a/client/cypress/support/commands.js +++ b/client/cypress/support/commands.js @@ -131,13 +131,31 @@ Cypress.Commands.add('register', (firstname, lastname, email, licenseKey) => { cy.get('[data-cy=register-button]').click(); }); -Cypress.Commands.add("checkEmailAvailable", (email) => { +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) => { +Cypress.Commands.add('enterPassword', (password) => { cy.get('[data-cy="password-input"]').type(password); cy.get('[data-cy="login-button"]').click(); }); +Cypress.Commands.add('register', (prefix, firstname, lastname, password, passwordConfirmation) => { + cy.get('[data-cy="prefix-selection"]').type(prefix); + + if (firstname !== '') { + cy.get('[data-cy="firstname-input"]').type(firstname); + } + if (lastname !== '') { + cy.get('[data-cy="lastname-input"]').type(lastname); + } + + if (password !== '') { + cy.get('[data-cy="password-input"]').type(password); + } + + cy.get('[data-cy="passwordConfirmation-input"]').type(passwordConfirmation); + cy.get('[data-cy="register-button"]').click(); +}); + diff --git a/client/src/main.js b/client/src/main.js index 8cc587f5..a64bcfd1 100644 --- a/client/src/main.js +++ b/client/src/main.js @@ -96,7 +96,7 @@ Validator.localize('de', dict) // https://github.com/baianat/vee-validate/issues/51 Validator.extend('strongPassword', { - getMessage: field => 'Das Passwort muss Grossbuchstaben, Zahlen und Sonderzeichen beinhalten', + getMessage: field => 'Das Passwort muss Grossbuchstaben, Zahlen und Sonderzeichen beinhalten und mindestens 8 Zeichen lang sein', validate: value => { const strongRegex = /^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#$%^&*?(),.":{}|<>+])(?=.{8,})/; return strongRegex.test(value); diff --git a/client/src/pages/check-email.vue b/client/src/pages/check-email.vue index d983c3ec..b4eebee7 100644 --- a/client/src/pages/check-email.vue +++ b/client/src/pages/check-email.vue @@ -1,6 +1,6 @@