Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
vlavrynovych committed Aug 23, 2017
2 parents 3841426 + fedb4a1 commit 0d44c31
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 11 deletions.
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"authors": [
"Volodymyr Lavrynovych <volodyalavrynovych@gmail.com>"
],
"version": "1.0.0",
"version": "1.0.1",
"description": "Provides ability to easily handle most of the logic related to the authentication process and page load for the AngularJS SPA",
"main": "dist/angular-spa-auth.min.js",
"keywords": [
Expand Down
4 changes: 3 additions & 1 deletion dist/angular-spa-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@
config.handlers.success(user);
})
.catch(function (err) {
openLogin();
if(!service.isPublic($location.path())) {
openLogin();
}
return onError(err);
});
}
Expand Down
2 changes: 1 addition & 1 deletion dist/angular-spa-auth.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/angular-spa-auth.min.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "angular-spa-auth",
"title": "Angular SPA Auth",
"version": "1.0.0",
"version": "1.0.1",
"author": "Volodymyr Lavrynovych <volodyalavrynovych@gmail.com>",
"contributors": [
"Volodymyr Lavrynovych <volodyalavrynovych@gmail.com>"
Expand Down
4 changes: 3 additions & 1 deletion src/angular-spa-auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,9 @@
config.handlers.success(user);
})
.catch(function (err) {
openLogin();
if(!service.isPublic($location.path())) {
openLogin();
}
return onError(err);
});
}
Expand Down
1 change: 0 additions & 1 deletion test/public-methods/test.run.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ describe('Public methods:', function () {
//then:
expect(success).not.toBeNull();
expect(success).toEqual(false);
expect($location.path()).toEqual(loginPage);
});

it('No config provided', function () {
Expand Down
32 changes: 28 additions & 4 deletions test/test.app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,22 @@ describe('angular-spa-auth', function () {
expect($rootScope.currentUser).toBeUndefined();
watch($location);

//when: isAuthenticated method is triggered but we still do not know status of user
//when: isAuthenticated method is triggered
$location.path('/public');
$httpBackend.flush(1);

//then: public page is always available
expect($location.path()).toEqual('/public');
expect($rootScope.currentUser).toBeUndefined();
expect($rootScope.currentUser).toEqual(false);
checkEvent(false, '/public');

//when: isAuthenticated method is triggered but we still do not know status of user
//when: isAuthenticated method is triggered
$location.path('/private');

//then: private page is rejected
checkEvent(true, '/private');
expect($rootScope.currentUser).toBeUndefined();
expect($rootScope.currentUser).toEqual(false);
expect($location.path()).not.toEqual('/private');

//when: trigger after init
$httpBackend.flush();
Expand Down Expand Up @@ -188,6 +190,28 @@ describe('angular-spa-auth', function () {
expect($rootScope.currentUser).toEqual(USER);
});

it('User is not logged in on start, check home page', function () {
//given:
expect($rootScope.currentUser).toBeUndefined();
watch($location);

//when: isAuthenticated method is triggered but we still do not know status of user
$location.path(AuthService.config.uiRoutes.home);

//then: public page is always available
expect($location.path()).toEqual(AuthService.config.uiRoutes.home);
expect($rootScope.currentUser).toBeUndefined();
checkEvent(false, AuthService.config.uiRoutes.home);

//when: trigger after init
$httpBackend.flush();

//then: we are on login page and user is set to false, because we checked his authentication status
expect($location.path()).toEqual(AuthService.config.uiRoutes.home);
expect($rootScope.currentUser).toEqual(false);
});


function watch($location) {
events = [];
$rootScope.$on("$routeChangeStart", function(e, next) {
Expand Down

0 comments on commit 0d44c31

Please sign in to comment.