Тесты для стейтов AuthFlow

This commit is contained in:
SleepWalker
2016-03-21 08:16:37 +02:00
parent 1e9b48bd9b
commit 21bbba399f
17 changed files with 985 additions and 17 deletions

View File

@@ -10,14 +10,13 @@ import ForgotPasswordState from './ForgotPasswordState';
const availableActions = {
...actions,
updateUser
updateUser,
redirect(url) {
location.href = url;
}
};
export default class AuthFlow {
constructor(states) {
this.states = states;
}
setStore(store) {
this.navigate = (route) => {
const {routing} = this.getState();

View File

@@ -9,14 +9,11 @@ export default class CompleteState extends AbstractState {
constructor(options = {}) {
super(options);
if ('accept' in options) {
this.isPermissionsAccepted = options.accept;
this.isUserReviewedPermissions = true;
}
this.isPermissionsAccepted = options.accept;
}
enter(context) {
const {auth, user} = context.getState();
const {auth = {}, user} = context.getState();
if (user.isGuest) {
context.setState(new LoginState());
@@ -28,18 +25,19 @@ export default class CompleteState extends AbstractState {
if (auth.oauth.code) {
context.setState(new FinishState());
} else {
let data = {};
if (this.isUserReviewedPermissions) {
const data = {};
if (typeof this.isPermissionsAccepted !== 'undefined') {
data.accept = this.isPermissionsAccepted;
}
context.run('oAuthComplete', data).then((resp) => {
if (resp.redirectUri.startsWith('static_page')) {
// TODO: пусть в стейт попадает флаг или тип авторизации
// вместо волшебства над редирект урлой
if (resp.redirectUri.indexOf('static_page') === 0) {
context.setState(new FinishState());
} else {
location.href = resp.redirectUri;
context.run('redirect', resp.redirectUri);
}
}, (resp) => {
// TODO
if (resp.unauthorized) {
context.setState(new LoginState());
} else if (resp.acceptRequired) {

View File

@@ -1,6 +1,6 @@
import AbstractState from './AbstractState';
export default class CompleteState extends AbstractState {
export default class FinishState extends AbstractState {
enter(context) {
context.navigate('/oauth/finish');
}