Fix login & tests

This commit is contained in:
Christian Cueni 2020-02-18 10:05:07 +01:00
parent 36c43bf4e1
commit 677d8dbf44
7 changed files with 83 additions and 54 deletions

View File

@ -1,5 +1,6 @@
const schema = require('../fixtures/schema_public.json');
const isEmailAvailableUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/customers/isEmailAvailable'; const isEmailAvailableUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/customers/isEmailAvailable';
const checkPasswordUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/customers'; const checkPasswordUrl = 'https://stage.hep-verlag.ch/rest/deutsch/V1/integration/customer/token';
describe('Login', () => { describe('Login', () => {
beforeEach(() => { beforeEach(() => {
@ -8,14 +9,37 @@ describe('Login', () => {
it('works with valid email and password', () => { it('works with valid email and password', () => {
cy.viewport('macbook-15'); cy.viewport('macbook-15');
cy.route('POST', isEmailAvailableUrl, "false");
cy.route('POST', checkPasswordUrl, "token12345ABCD+"); 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.visit('/hello');
cy.checkEmailAvailable('feuz@aebi.ch'); cy.checkEmailAvailable('feuz@aebi.ch');
cy.get('[data-cy="login-title"]').contains('Bitte geben Sie das passende Passwort ein'); cy.get('[data-cy="login-title"]').contains('Bitte geben Sie das passende Passwort ein');
cy.enterPassword('abcd1234'); cy.enterPassword('abcd1234');
// As we cannot set the cookie in the right manner, we just check for the absence of erros.
// 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', () => { it('displays error message if password is wrong', () => {

View File

@ -147,23 +147,21 @@ function networkErrorCallback(statusCode) {
} }
router.beforeEach(async (to, from, next) => { router.beforeEach(async (to, from, next) => {
// handle logout // handle logout
if (to.path === '/logout') { if (to.path === '/logout') {
privateApolloClient.resetStore(); privateApolloClient.resetStore();
next({name: 'login'}); next({name: 'login'});
return return;
} }
getCookieValue('loginStatus')
if (unauthorizedAccess(to)) { if (unauthorizedAccess(to)) {
const redirectUrl = `/login?redirect=${to.path}`; const redirectUrl = `/login?redirect=${to.path}`;
next(redirectUrl); next(redirectUrl);
return return;
} }
if ((to.name !== 'noClass' && to.name !== 'licenseActivation') && loginRequired(to) && await redirectStudentsWithoutClass()) {
if ((to.name !== 'noClass' || to.name !== 'licenseActivation') && loginRequired(to) && await redirectStudentsWithoutClass()) {
next({name: 'noClass'}) next({name: 'noClass'})
return return;
} }
next(); next();

View File

@ -47,7 +47,6 @@ export default {
}, },
fetchPolicy: 'no-cache' fetchPolicy: 'no-cache'
}).then(({data}) => { }).then(({data}) => {
this.loading = false; this.loading = false;
if (data.registration.success) { if (data.registration.success) {
this.keyValid = true; this.keyValid = true;

View File

@ -38,6 +38,7 @@
<script> <script>
import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql'; import HELLO_EMAIL from '@/graphql/gql/local/helloEmail.gql';
import LOGIN_MUTATION from '@/graphql/gql/mutations/login.gql';
import {login} from '../hep-client/index'; import {login} from '../hep-client/index';
export default { export default {
@ -51,54 +52,61 @@ export default {
if (result) { if (result) {
login(this.helloEmail.email, this.password) login(this.helloEmail.email, this.password)
.then((response) => { .then((response) => {
console.log(response) if (response.status === 200) {
this.mySkillboxLogin(response.data);
} else {
this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
}
}) })
.catch((error) => { .catch((error) => {
console.log(error)
if (error.response.data.message && error.response.data.message === 'Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vor\u00fcbergehend deaktiviert.') { if (error.response.data.message && error.response.data.message === 'Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vor\u00fcbergehend deaktiviert.') {
this.passwordErrors = ['Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vorübergehend deaktiviert.']; this.passwordErrors = ['Sie haben sich nicht korrekt eingeloggt oder Ihr Konto ist vorübergehend deaktiviert.'];
} else { } else {
this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.']; this.passwordErrors = ['Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'];
} }
}); });
}
// this.$apollo.mutate({ });
// client: 'publicClient', },
// mutation: LOGIN_MUTATION, mySkillboxLogin(token) {
// variables: { const that = this;
// input: { this.$apollo.mutate({
// usernameInput: this.email, client: 'publicClient',
// passwordInput: this.password mutation: LOGIN_MUTATION,
// } variables: {
// }, input: {
// update( usernameInput: that.helloEmail,
// store, passwordInput: token
// { }
// data: { },
// login update(
// } store,
// } {
// ) { data: {
// try { login
// if (login.success) { }
// const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/' }
// that.$router.push(redirectUrl); ) {
// } else { try {
// const firstError = login.errors[0]; if (login.success) {
// switch (firstError.field) { const redirectUrl = that.$route.query.redirect ? that.$route.query.redirect : '/';
// case 'invalid_credentials': that.$router.push(redirectUrl);
// that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.'; } else {
// break; const firstError = login.errors[0];
// case 'license_inactive': switch (firstError.field) {
// that.loginError = 'Ihre Lizenz ist nicht mehr aktiv.'; case 'invalid_credentials':
// break; that.loginError = 'Die E-Mail oder das Passwort ist falsch. Bitte versuchen Sie nochmals.';
// } break;
// } case 'no_valid_license':
// } catch (e) { this.$router.push({name: 'licenseActivation'})
// console.warn(e); break;
// that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.'; }
// } }
// } } catch (e) {
// }); console.warn(e);
that.loginError = 'Es ist ein Fehler aufgetreten. Bitte versuchen Sie nochmals.';
}
} }
}); });
}, },

View File

@ -151,12 +151,12 @@ export default {
}; };
register(registrationData).then((response) => { register(registrationData).then((response) => {
console.log(response)
if (response.data.id && response.data.id > 0) { if (response.data.id && response.data.id > 0) {
this.$router.push({name: 'checkEmail'}); this.$router.push({name: 'checkEmail'});
} }
}) })
.catch((error) => { .catch((error) => {
console.warn(error);
if (error.response.data.message && error.response.data.message === 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.') { if (error.response.data.message && error.response.data.message === 'Ein Kunde mit der gleichen E-Mail-Adresse existiert bereits in einer zugeordneten Website.') {
this.emailErrors = ['Die angegebene E-Mail ist bereits registriert.']; this.emailErrors = ['Die angegebene E-Mail ist bereits registriert.'];
} else { } else {

View File

@ -370,7 +370,7 @@ TASKBASE_SUPERPASSWORD = os.environ.get("TASKBASE_SUPERPASSWORD")
TASKBASE_BASEURL = os.environ.get("TASKBASE_BASEURL") TASKBASE_BASEURL = os.environ.get("TASKBASE_BASEURL")
USE_LOCAL_REGISTRATION = True USE_LOCAL_REGISTRATION = False
# HEP # HEP

View File

@ -44,7 +44,7 @@ class Login(relay.ClientIDMutation):
else: else:
hep_client = HepClient() hep_client = HepClient()
token = kwargs.get('token') token = kwargs.get('password_input')
try: try:
user_data = hep_client.customer_me(token) user_data = hep_client.customer_me(token)