fix(core): Remove the <base> tag (continues #1230)

fix(core): Remove the <base> tag (continues #1230)
Merge pull request #1544 from mleanos/remove-base-tag
This commit is contained in:
Liran Tal
2016-10-12 14:20:37 +03:00
committed by GitHub
27 changed files with 174 additions and 105 deletions

View File

@@ -16,7 +16,7 @@
})
.state('admin.articles.list', {
url: '',
templateUrl: 'modules/articles/client/views/admin/list-articles.client.view.html',
templateUrl: '/modules/articles/client/views/admin/list-articles.client.view.html',
controller: 'ArticlesAdminListController',
controllerAs: 'vm',
data: {
@@ -25,7 +25,7 @@
})
.state('admin.articles.create', {
url: '/create',
templateUrl: 'modules/articles/client/views/admin/form-article.client.view.html',
templateUrl: '/modules/articles/client/views/admin/form-article.client.view.html',
controller: 'ArticlesAdminController',
controllerAs: 'vm',
data: {
@@ -37,7 +37,7 @@
})
.state('admin.articles.edit', {
url: '/:articleId/edit',
templateUrl: 'modules/articles/client/views/admin/form-article.client.view.html',
templateUrl: '/modules/articles/client/views/admin/form-article.client.view.html',
controller: 'ArticlesAdminController',
controllerAs: 'vm',
data: {

View File

@@ -16,7 +16,7 @@
})
.state('articles.list', {
url: '',
templateUrl: 'modules/articles/client/views/list-articles.client.view.html',
templateUrl: '/modules/articles/client/views/list-articles.client.view.html',
controller: 'ArticlesListController',
controllerAs: 'vm',
data: {
@@ -25,7 +25,7 @@
})
.state('articles.view', {
url: '/:articleId',
templateUrl: 'modules/articles/client/views/view-article.client.view.html',
templateUrl: '/modules/articles/client/views/view-article.client.view.html',
controller: 'ArticlesController',
controllerAs: 'vm',
resolve: {

View File

@@ -8,7 +8,7 @@
ArticlesService.$inject = ['$resource', '$log'];
function ArticlesService($resource, $log) {
var Article = $resource('api/articles/:articleId', {
var Article = $resource('/api/articles/:articleId', {
articleId: '@_id'
}, {
update: {

View File

@@ -48,6 +48,9 @@
ArticlesService = _ArticlesService_;
Notification = _Notification_;
// Ignore parent template get on state transitions
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
// create mock article
mockArticle = new ArticlesService({
_id: '525a8422f6d0f87f0e407a33',
@@ -87,7 +90,7 @@
it('should send a POST request with the form input values and then locate to new object URL', inject(function (ArticlesService) {
// Set POST response
$httpBackend.expectPOST('api/articles', sampleArticlePostData).respond(mockArticle);
$httpBackend.expectPOST('/api/articles', sampleArticlePostData).respond(mockArticle);
// Run controller functionality
$scope.vm.save(true);
@@ -101,7 +104,7 @@
it('should call Notification.error if error', function () {
var errorMessage = 'this is an error message';
$httpBackend.expectPOST('api/articles', sampleArticlePostData).respond(400, {
$httpBackend.expectPOST('/api/articles', sampleArticlePostData).respond(400, {
message: errorMessage
});

View File

@@ -53,7 +53,7 @@
});
it('Should have templateUrl', function () {
expect(liststate.templateUrl).toBe('modules/articles/client/views/admin/list-articles.client.view.html');
expect(liststate.templateUrl).toBe('/modules/articles/client/views/admin/list-articles.client.view.html');
});
});
@@ -64,7 +64,7 @@
beforeEach(inject(function ($controller, $state, $templateCache) {
createstate = $state.get('admin.articles.create');
$templateCache.put('modules/articles/client/views/admin/form-article.client.view.html', '');
$templateCache.put('/modules/articles/client/views/admin/form-article.client.view.html', '');
// Create mock article
mockArticle = new ArticlesService();
@@ -99,7 +99,7 @@
});
it('Should have templateUrl', function () {
expect(createstate.templateUrl).toBe('modules/articles/client/views/admin/form-article.client.view.html');
expect(createstate.templateUrl).toBe('/modules/articles/client/views/admin/form-article.client.view.html');
});
});
@@ -110,7 +110,7 @@
beforeEach(inject(function ($controller, $state, $templateCache) {
editstate = $state.get('admin.articles.edit');
$templateCache.put('modules/articles/client/views/admin/form-article.client.view.html', '');
$templateCache.put('/modules/articles/client/views/admin/form-article.client.view.html', '');
// Create mock article
mockArticle = new ArticlesService({
@@ -150,7 +150,7 @@
});
it('Should have templateUrl', function () {
expect(editstate.templateUrl).toBe('modules/articles/client/views/admin/form-article.client.view.html');
expect(editstate.templateUrl).toBe('/modules/articles/client/views/admin/form-article.client.view.html');
});
xit('Should go to unauthorized route', function () {

View File

@@ -46,6 +46,10 @@
Authentication = _Authentication_;
ArticlesService = _ArticlesService_;
// Ignore parent template get on state transitions
$httpBackend.whenGET('/modules/articles/client/views/list-articles.client.view.html').respond(200, '');
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
// create mock article
mockArticle = new ArticlesService({
_id: '525a8422f6d0f87f0e407a33',
@@ -76,7 +80,7 @@
it('should send a GET request and return all articles', inject(function (ArticlesService) {
// Set POST response
$httpBackend.expectGET('api/articles').respond(mockArticleList);
$httpBackend.expectGET('/api/articles').respond(mockArticleList);
$httpBackend.flush();

View File

@@ -53,7 +53,7 @@
});
it('Should have templateUrl', function () {
expect(liststate.templateUrl).toBe('modules/articles/client/views/list-articles.client.view.html');
expect(liststate.templateUrl).toBe('/modules/articles/client/views/list-articles.client.view.html');
});
});
@@ -64,7 +64,7 @@
beforeEach(inject(function ($controller, $state, $templateCache) {
viewstate = $state.get('articles.view');
$templateCache.put('modules/articles/client/views/view-article.client.view.html', '');
$templateCache.put('/modules/articles/client/views/view-article.client.view.html', '');
// create mock article
mockArticle = new ArticlesService({
@@ -104,12 +104,14 @@
});
it('Should have templateUrl', function () {
expect(viewstate.templateUrl).toBe('modules/articles/client/views/view-article.client.view.html');
expect(viewstate.templateUrl).toBe('/modules/articles/client/views/view-article.client.view.html');
});
});
describe('Handle Trailing Slash', function () {
beforeEach(inject(function ($state, $rootScope) {
beforeEach(inject(function ($state, $rootScope, $templateCache) {
$templateCache.put('/modules/articles/client/views/list-articles.client.view.html', '');
$state.go('articles.list');
$rootScope.$digest();
}));
@@ -119,7 +121,7 @@
$rootScope.$digest();
expect($location.path()).toBe('/articles');
expect($state.current.templateUrl).toBe('modules/articles/client/views/list-articles.client.view.html');
expect($state.current.templateUrl).toBe('/modules/articles/client/views/list-articles.client.view.html');
}));
});
});

View File

@@ -76,8 +76,10 @@
it('should send a GET request and return all articles', inject(function (ArticlesService) {
// Set POST response
$httpBackend.expectGET('api/articles').respond(mockArticleList);
$httpBackend.expectGET('/api/articles').respond(mockArticleList);
// Ignore parent template get on state transition
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
$httpBackend.flush();

View File

@@ -11,7 +11,7 @@
$stateProvider
.state('chat', {
url: '/chat',
templateUrl: 'modules/chat/client/views/chat.client.view.html',
templateUrl: '/modules/chat/client/views/chat.client.view.html',
controller: 'ChatController',
controllerAs: 'vm',
data: {

View File

@@ -18,7 +18,7 @@
<!-- List all messages -->
<li class="col-xs-12 col-md-offset-4 col-md-4 chat-message" ng-repeat="message in vm.messages">
<small class="pull-right text-muted" ng-bind="message.created | date:'mediumTime'"></small>
<img ng-src="{{message.profileImageURL}}" alt="{{message.username}}" class="pull-left chat-profile-image" />
<img ng-src="/{{message.profileImageURL}}" alt="{{message.username}}" class="pull-left chat-profile-image" />
<div class="pull-left chat-message-details">
<strong ng-bind="message.username"></strong>
<br>

View File

@@ -11,7 +11,8 @@
ChatController,
$timeout,
$state,
Authentication;
Authentication,
$httpBackend;
// Load the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
@@ -39,12 +40,17 @@
});
describe('when user logged in', function () {
beforeEach(inject(function ($controller, $rootScope, _Socket_, _Authentication_, _$timeout_, _$state_) {
beforeEach(inject(function ($controller, $rootScope, _$httpBackend_, _Socket_, _Authentication_, _$timeout_, _$state_) {
Authentication.user = {
name: 'user',
roles: ['user']
};
$httpBackend = _$httpBackend_;
// Ignore parent template get on state transitions
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
ChatController = $controller('ChatController as vm', {
$scope: $scope
});

View File

@@ -4,7 +4,8 @@
describe('Chat Route Tests', function () {
// Initialize global variables
var $scope,
Authentication;
Authentication,
$httpBackend;
// We can start by loading the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
@@ -34,27 +35,35 @@
});
it('Should have templateUrl', function () {
expect(mainstate.templateUrl).toBe('modules/chat/client/views/chat.client.view.html');
expect(mainstate.templateUrl).toBe('/modules/chat/client/views/chat.client.view.html');
});
});
describe('Handle Trailing Slash', function () {
beforeEach(inject(function ($state, $rootScope, _Authentication_) {
beforeEach(inject(function ($state, $rootScope, _$httpBackend_, _Authentication_) {
Authentication.user = {
name: 'user',
roles: ['user']
};
$httpBackend = _$httpBackend_;
// Ignore parent template get on state transition
$httpBackend.whenGET('/modules/chat/client/views/chat.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200, '');
$state.go('chat');
$rootScope.$digest();
}));
it('Should remove trailing slash', inject(function ($state, $location, $rootScope) {
it('Should remove trailing slash', inject(function ($state, $location, $rootScope, $templateCache) {
$templateCache.put('/modules/chat/client/views/chat.client.view.html', '');
$location.path('chat/');
$rootScope.$digest();
expect($location.path()).toBe('/chat');
expect($state.current.templateUrl).toBe('modules/chat/client/views/chat.client.view.html');
expect($state.current.templateUrl).toBe('/modules/chat/client/views/chat.client.view.html');
}));
});

View File

@@ -13,7 +13,10 @@
bootstrapConfig.$inject = ['$compileProvider', '$locationProvider', '$httpProvider', '$logProvider'];
function bootstrapConfig($compileProvider, $locationProvider, $httpProvider, $logProvider) {
$locationProvider.html5Mode(true).hashPrefix('!');
$locationProvider.html5Mode({
enabled: true,
requireBase: false
}).hashPrefix('!');
$httpProvider.interceptors.push('authInterceptor');

View File

@@ -29,13 +29,13 @@
$stateProvider
.state('home', {
url: '/',
templateUrl: 'modules/core/client/views/home.client.view.html',
templateUrl: '/modules/core/client/views/home.client.view.html',
controller: 'HomeController',
controllerAs: 'vm'
})
.state('not-found', {
url: '/not-found',
templateUrl: 'modules/core/client/views/404.client.view.html',
templateUrl: '/modules/core/client/views/404.client.view.html',
controller: 'ErrorController',
controllerAs: 'vm',
params: {
@@ -50,7 +50,7 @@
})
.state('bad-request', {
url: '/bad-request',
templateUrl: 'modules/core/client/views/400.client.view.html',
templateUrl: '/modules/core/client/views/400.client.view.html',
controller: 'ErrorController',
controllerAs: 'vm',
params: {
@@ -65,7 +65,7 @@
})
.state('forbidden', {
url: '/forbidden',
templateUrl: 'modules/core/client/views/403.client.view.html',
templateUrl: '/modules/core/client/views/403.client.view.html',
data: {
ignoreState: true,
pageTitle: 'Forbidden'

View File

@@ -32,7 +32,7 @@
<ul class="nav navbar-nav navbar-right" ng-show="vm.authentication.user">
<li class="dropdown" uib-dropdown>
<a class="dropdown-toggle user-header-dropdown-toggle" uib-dropdown-toggle role="button">
<img ng-src="{{vm.authentication.user.profileImageURL}}" alt="{{vm.authentication.user.displayName}}" class="header-profile-image" />
<img ng-src="/{{vm.authentication.user.profileImageURL}}" alt="{{vm.authentication.user.displayName}}" class="header-profile-image" />
<span ng-bind="vm.authentication.user.displayName"></span> <b class="caret"></b>
</a>
<ul class="dropdown-menu" role="menu">

View File

@@ -2,7 +2,7 @@
<div class="jumbotron text-center">
<div class="row">
<div class="col-md-6 col-md-offset-3 col-sm-6 col-sm-offset-3 col-xs-12">
<img alt="MEAN.JS" class="img-responsive text-center" src="modules/core/client/img/brand/logo.png" />
<img alt="MEAN.JS" class="img-responsive text-center" src="/modules/core/client/img/brand/logo.png" />
</div>
</div>
<br>

View File

@@ -4,7 +4,6 @@
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
<base href="/">
<title page-title></title>
<meta name="description" content="{{description}}">
<meta name="fragment" content="!">
@@ -29,10 +28,10 @@
<meta name="twitter:image" content="{{logo}}">
<!-- Fav Icon -->
<link href="{{favicon}}" rel="shortcut icon" type="image/x-icon">
<link href="/{{favicon}}" rel="shortcut icon" type="image/x-icon">
<!-- Application CSS Files -->
{{#each cssFiles}}<link rel="stylesheet" href="{{this}}">{{/each}}
{{#each cssFiles}}<link rel="stylesheet" href="/{{this}}">{{/each}}
</head>
<body class="ng-cloak">
@@ -64,7 +63,7 @@
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<!--Application JavaScript Files-->
{{#each jsFiles}}<script type="text/javascript" src="{{this}}"></script>{{/each}}
{{#each jsFiles}}<script type="text/javascript" src="/{{this}}"></script>{{/each}}
<!--owasp config sync-->
<script type="text/javascript">

View File

@@ -12,7 +12,7 @@
$stateProvider
.state('admin.users', {
url: '/users',
templateUrl: 'modules/users/client/views/admin/list-users.client.view.html',
templateUrl: '/modules/users/client/views/admin/list-users.client.view.html',
controller: 'UserListController',
controllerAs: 'vm',
data: {
@@ -21,7 +21,7 @@
})
.state('admin.user', {
url: '/users/:userId',
templateUrl: 'modules/users/client/views/admin/view-user.client.view.html',
templateUrl: '/modules/users/client/views/admin/view-user.client.view.html',
controller: 'UserController',
controllerAs: 'vm',
resolve: {
@@ -33,7 +33,7 @@
})
.state('admin.user-edit', {
url: '/users/:userId/edit',
templateUrl: 'modules/users/client/views/admin/edit-user.client.view.html',
templateUrl: '/modules/users/client/views/admin/edit-user.client.view.html',
controller: 'UserController',
controllerAs: 'vm',
resolve: {

View File

@@ -14,7 +14,7 @@
.state('settings', {
abstract: true,
url: '/settings',
templateUrl: 'modules/users/client/views/settings/settings.client.view.html',
templateUrl: '/modules/users/client/views/settings/settings.client.view.html',
controller: 'SettingsController',
controllerAs: 'vm',
data: {
@@ -23,7 +23,7 @@
})
.state('settings.profile', {
url: '/profile',
templateUrl: 'modules/users/client/views/settings/edit-profile.client.view.html',
templateUrl: '/modules/users/client/views/settings/edit-profile.client.view.html',
controller: 'EditProfileController',
controllerAs: 'vm',
data: {
@@ -32,7 +32,7 @@
})
.state('settings.password', {
url: '/password',
templateUrl: 'modules/users/client/views/settings/change-password.client.view.html',
templateUrl: '/modules/users/client/views/settings/change-password.client.view.html',
controller: 'ChangePasswordController',
controllerAs: 'vm',
data: {
@@ -41,7 +41,7 @@
})
.state('settings.accounts', {
url: '/accounts',
templateUrl: 'modules/users/client/views/settings/manage-social-accounts.client.view.html',
templateUrl: '/modules/users/client/views/settings/manage-social-accounts.client.view.html',
controller: 'SocialAccountsController',
controllerAs: 'vm',
data: {
@@ -50,7 +50,7 @@
})
.state('settings.picture', {
url: '/picture',
templateUrl: 'modules/users/client/views/settings/change-profile-picture.client.view.html',
templateUrl: '/modules/users/client/views/settings/change-profile-picture.client.view.html',
controller: 'ChangeProfilePictureController',
controllerAs: 'vm',
data: {
@@ -60,13 +60,13 @@
.state('authentication', {
abstract: true,
url: '/authentication',
templateUrl: 'modules/users/client/views/authentication/authentication.client.view.html',
templateUrl: '/modules/users/client/views/authentication/authentication.client.view.html',
controller: 'AuthenticationController',
controllerAs: 'vm'
})
.state('authentication.signup', {
url: '/signup',
templateUrl: 'modules/users/client/views/authentication/signup.client.view.html',
templateUrl: '/modules/users/client/views/authentication/signup.client.view.html',
controller: 'AuthenticationController',
controllerAs: 'vm',
data: {
@@ -75,7 +75,7 @@
})
.state('authentication.signin', {
url: '/signin?err',
templateUrl: 'modules/users/client/views/authentication/signin.client.view.html',
templateUrl: '/modules/users/client/views/authentication/signin.client.view.html',
controller: 'AuthenticationController',
controllerAs: 'vm',
data: {
@@ -89,7 +89,7 @@
})
.state('password.forgot', {
url: '/forgot',
templateUrl: 'modules/users/client/views/password/forgot-password.client.view.html',
templateUrl: '/modules/users/client/views/password/forgot-password.client.view.html',
controller: 'PasswordController',
controllerAs: 'vm',
data: {
@@ -103,21 +103,21 @@
})
.state('password.reset.invalid', {
url: '/invalid',
templateUrl: 'modules/users/client/views/password/reset-password-invalid.client.view.html',
templateUrl: '/modules/users/client/views/password/reset-password-invalid.client.view.html',
data: {
pageTitle: 'Password reset invalid'
}
})
.state('password.reset.success', {
url: '/success',
templateUrl: 'modules/users/client/views/password/reset-password-success.client.view.html',
templateUrl: '/modules/users/client/views/password/reset-password-success.client.view.html',
data: {
pageTitle: 'Password reset success'
}
})
.state('password.reset.form', {
url: '/:token',
templateUrl: 'modules/users/client/views/password/reset-password.client.view.html',
templateUrl: '/modules/users/client/views/password/reset-password.client.view.html',
controller: 'PasswordController',
controllerAs: 'vm',
data: {

View File

@@ -16,7 +16,7 @@
vm.upload = function (dataUrl, name) {
Upload.upload({
url: 'api/users/picture',
url: '/api/users/picture',
data: {
newProfilePicture: Upload.dataUrltoBlob(dataUrl, name)
}

View File

@@ -9,36 +9,36 @@
UsersService.$inject = ['$resource'];
function UsersService($resource) {
var Users = $resource('api/users', {}, {
var Users = $resource('/api/users', {}, {
update: {
method: 'PUT'
},
updatePassword: {
method: 'POST',
url: 'api/users/password'
url: '/api/users/password'
},
deleteProvider: {
method: 'DELETE',
url: 'api/users/accounts',
url: '/api/users/accounts',
params: {
provider: '@provider'
}
},
sendPasswordResetToken: {
method: 'POST',
url: 'api/auth/forgot'
url: '/api/auth/forgot'
},
resetPasswordWithToken: {
method: 'POST',
url: 'api/auth/reset/:token'
url: '/api/auth/reset/:token'
},
signup: {
method: 'POST',
url: 'api/auth/signup'
url: '/api/auth/signup'
},
signin: {
method: 'POST',
url: 'api/auth/signin'
url: '/api/auth/signin'
}
});
@@ -78,7 +78,7 @@
AdminService.$inject = ['$resource'];
function AdminService($resource) {
return $resource('api/users/:userId', {
return $resource('/api/users/:userId', {
userId: '@_id'
}, {
update: {

View File

@@ -9,7 +9,7 @@
</div>
</div>
<div class="form-group text-center">
<img ng-src="{{vm.fileSelected ? croppedDataUrl : vm.user.profileImageURL}}" alt="{{vm.user.displayName}}" class="img-thumbnail user-profile-picture" ngf-drop>
<img ng-src="{{vm.fileSelected ? croppedDataUrl : '/' + vm.user.profileImageURL}}" alt="{{vm.user.displayName}}" class="img-thumbnail user-profile-picture" ngf-drop>
</div>
<div ng-show="!vm.fileSelected" class="text-center form-group">
<button class="btn btn-default btn-file" ngf-select="vm.fileSelected = true" ng-model="picFile" accept="image/*">Select Picture</button>

View File

@@ -47,6 +47,10 @@
spyOn(Notification, 'error');
spyOn(Notification, 'success');
// Ignore parent template get on state transitions
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/400.client.view.html').respond(200);
// Initialize the Authentication controller
AuthenticationController = $controller('AuthenticationController as vm', {
$scope: scope
@@ -54,9 +58,11 @@
}));
describe('$scope.signin()', function () {
it('should login with a correct username and password', function () {
it('should login with a correct user and password', inject(function ($templateCache) {
$templateCache.put('/modules/core/client/views/home.client.view.html', '');
// Test expected GET request
$httpBackend.when('POST', 'api/auth/signin').respond(200, { username: 'Fred' });
$httpBackend.when('POST', '/api/auth/signin').respond(200, { username: 'Fred' });
scope.vm.signin(true);
$httpBackend.flush();
@@ -64,11 +70,12 @@
// Test scope value
expect(scope.vm.authentication.user.username).toEqual('Fred');
expect($location.url()).toEqual('/');
});
}));
it('should login with a correct email and password', function () {
it('should login with a correct email and password', inject(function ($templateCache) {
$templateCache.put('/modules/core/client/views/home.client.view.html', '');
// Test expected GET request
$httpBackend.when('POST', 'api/auth/signin').respond(200, { email: 'Fred@email.com' });
$httpBackend.when('POST', '/api/auth/signin').respond(200, { email: 'Fred@email.com' });
scope.vm.signin(true);
$httpBackend.flush();
@@ -76,7 +83,7 @@
// Test scope value
expect(scope.vm.authentication.user.email).toEqual('Fred@email.com');
expect($location.url()).toEqual('/');
});
}));
it('should be redirected to previous state after successful login',
inject(function (_$state_) {
@@ -93,7 +100,7 @@
spyOn($state, 'go');
// Test expected GET request
$httpBackend.when('POST', 'api/auth/signin').respond(200, 'Fred');
$httpBackend.when('POST', '/api/auth/signin').respond(200, 'Fred');
scope.vm.signin(true);
$httpBackend.flush();
@@ -106,7 +113,7 @@
it('should fail to log in with nothing', function () {
// Test expected POST request
$httpBackend.expectPOST('api/auth/signin').respond(400, {
$httpBackend.expectPOST('/api/auth/signin').respond(400, {
'message': 'Missing credentials'
});
@@ -123,7 +130,7 @@
scope.vm.credentials = 'Bar';
// Test expected POST request
$httpBackend.expectPOST('api/auth/signin').respond(400, {
$httpBackend.expectPOST('/api/auth/signin').respond(400, {
'message': 'Unknown user'
});
@@ -136,10 +143,12 @@
});
describe('$scope.signup()', function () {
it('should register with correct data', function () {
it('should register with correct data', inject(function ($templateCache) {
$templateCache.put('/modules/core/client/views/home.client.view.html', '');
// Test expected GET request
scope.vm.authentication.user = 'Fred';
$httpBackend.when('POST', 'api/auth/signup').respond(200, { username: 'Fred' });
$httpBackend.when('POST', '/api/auth/signup').respond(200, { username: 'Fred' });
scope.vm.signup(true);
$httpBackend.flush();
@@ -148,11 +157,11 @@
expect(scope.vm.authentication.user.username).toBe('Fred');
expect(Notification.success).toHaveBeenCalledWith({ message: '<i class="glyphicon glyphicon-ok"></i> Signup successful!' });
expect($location.url()).toBe('/');
});
}));
it('should fail to register with duplicate Username', function () {
// Test expected POST request
$httpBackend.when('POST', 'api/auth/signup').respond(400, {
$httpBackend.when('POST', '/api/auth/signup').respond(400, {
'message': 'Username already exists'
});

View File

@@ -51,6 +51,10 @@
spyOn(Notification, 'error');
spyOn(Notification, 'success');
// Ignore parent template gets on state transition
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/400.client.view.html').respond(200);
// Mock logged in user
Authentication.user = {
_id: '525a8422f6d0f87f0e407a33',

View File

@@ -40,6 +40,9 @@
$location = _$location_;
$location.path = jasmine.createSpy().and.returnValue(true);
// Ignore parent template gets on state transition
$httpBackend.whenGET('/modules/core/client/views/404.client.view.html').respond(200);
// Mock logged in user
_Authentication_.user = {
username: 'test',
@@ -74,6 +77,10 @@
spyOn(Notification, 'error');
spyOn(Notification, 'success');
// Ignore parent template gets on state transition
$httpBackend.whenGET('/modules/core/client/views/404.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/400.client.view.html').respond(200);
// Initialize the Authentication controller
PasswordController = $controller('PasswordController as vm', {
$scope: scope
@@ -96,7 +103,7 @@
describe('POST error', function() {
var errorMessage = 'No account with that username has been found';
beforeEach(function() {
$httpBackend.when('POST', 'api/auth/forgot', credentials).respond(400, {
$httpBackend.when('POST', '/api/auth/forgot', credentials).respond(400, {
'message': errorMessage
});
@@ -116,7 +123,7 @@
describe('POST success', function() {
var successMessage = 'An email has been sent to the provided email with further instructions.';
beforeEach(function() {
$httpBackend.when('POST', 'api/auth/forgot', credentials).respond({
$httpBackend.when('POST', '/api/auth/forgot', credentials).respond({
'message': successMessage
});
@@ -146,7 +153,7 @@
it('POST error should call Notification.error with response message', function() {
var errorMessage = 'Passwords do not match';
$httpBackend.when('POST', 'api/auth/reset/' + token, passwordDetails).respond(400, {
$httpBackend.when('POST', '/api/auth/reset/' + token, passwordDetails).respond(400, {
'message': errorMessage
});
@@ -161,7 +168,7 @@
username: 'test'
};
beforeEach(function() {
$httpBackend.when('POST', 'api/auth/reset/' + token, passwordDetails).respond(user);
$httpBackend.when('POST', '/api/auth/reset/' + token, passwordDetails).respond(user);
scope.vm.resetUserPassword(true);
$httpBackend.flush();

View File

@@ -4,7 +4,8 @@
describe('Users Admin Route Tests', function () {
// Initialize global variables
var $scope,
Authentication;
Authentication,
$httpBackend;
// We can start by loading the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
@@ -34,7 +35,7 @@
});
it('Should have templateUrl', function () {
expect(mainstate.templateUrl).toBe('modules/users/client/views/admin/list-users.client.view.html');
expect(mainstate.templateUrl).toBe('/modules/users/client/views/admin/list-users.client.view.html');
});
});
@@ -53,7 +54,7 @@
});
it('Should have templateUrl', function () {
expect(viewstate.templateUrl).toBe('modules/users/client/views/admin/view-user.client.view.html');
expect(viewstate.templateUrl).toBe('/modules/users/client/views/admin/view-user.client.view.html');
});
});
@@ -72,27 +73,36 @@
});
it('Should have templateUrl', function () {
expect(editstate.templateUrl).toBe('modules/users/client/views/admin/edit-user.client.view.html');
expect(editstate.templateUrl).toBe('/modules/users/client/views/admin/edit-user.client.view.html');
});
});
describe('Handle Trailing Slash', function () {
beforeEach(inject(function ($state, $rootScope, _Authentication_) {
beforeEach(inject(function ($state, $rootScope, _Authentication_, _$httpBackend_) {
Authentication.user = {
name: 'user',
roles: ['admin']
};
$httpBackend = _$httpBackend_;
// Ignore parent template gets on state transition
$httpBackend.whenGET('/modules/users/client/views/admin/list-users.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
$state.go('admin.users');
$rootScope.$digest();
}));
it('Should remove trailing slash', inject(function ($state, $location, $rootScope) {
it('Should remove trailing slash', inject(function ($state, $location, $rootScope, $templateCache) {
$templateCache.put('/modules/users/client/views/admin/list-users.client.view.html', '');
$templateCache.put('/modules/core/client/views/home.client.view.html', '');
$location.path('admin/users/');
$rootScope.$digest();
expect($location.path()).toBe('/admin/users');
expect($state.current.templateUrl).toBe('modules/users/client/views/admin/list-users.client.view.html');
expect($state.current.templateUrl).toBe('/modules/users/client/views/admin/list-users.client.view.html');
}));
});

View File

@@ -4,7 +4,8 @@
describe('Users Route Tests', function () {
// Initialize global variables
var $scope,
Authentication;
Authentication,
$httpBackend;
// We can start by loading the main application module
beforeEach(module(ApplicationConfiguration.applicationModuleName));
@@ -34,7 +35,7 @@
});
it('Should have templateUrl', function () {
expect(mainstate.templateUrl).toBe('modules/users/client/views/settings/settings.client.view.html');
expect(mainstate.templateUrl).toBe('/modules/users/client/views/settings/settings.client.view.html');
});
});
@@ -53,7 +54,7 @@
});
it('Should have templateUrl', function () {
expect(profilestate.templateUrl).toBe('modules/users/client/views/settings/edit-profile.client.view.html');
expect(profilestate.templateUrl).toBe('/modules/users/client/views/settings/edit-profile.client.view.html');
});
});
@@ -72,7 +73,7 @@
});
it('Should have templateUrl', function () {
expect(passwordstate.templateUrl).toBe('modules/users/client/views/settings/change-password.client.view.html');
expect(passwordstate.templateUrl).toBe('/modules/users/client/views/settings/change-password.client.view.html');
});
});
@@ -91,7 +92,7 @@
});
it('Should have templateUrl', function () {
expect(accountsstate.templateUrl).toBe('modules/users/client/views/settings/manage-social-accounts.client.view.html');
expect(accountsstate.templateUrl).toBe('/modules/users/client/views/settings/manage-social-accounts.client.view.html');
});
});
@@ -110,27 +111,37 @@
});
it('Should have templateUrl', function () {
expect(picturestate.templateUrl).toBe('modules/users/client/views/settings/change-profile-picture.client.view.html');
expect(picturestate.templateUrl).toBe('/modules/users/client/views/settings/change-profile-picture.client.view.html');
});
});
describe('Handle Trailing Slash', function () {
beforeEach(inject(function ($state, $rootScope, _Authentication_) {
beforeEach(inject(function ($state, $rootScope, _Authentication_, _$httpBackend_) {
Authentication.user = {
name: 'user',
roles: ['user']
};
$httpBackend = _$httpBackend_;
// Ignore parent template gets on state transitions
$httpBackend.whenGET('/modules/users/client/views/settings/settings.client.view.html').respond(200);
$httpBackend.whenGET('/modules/core/client/views/home.client.view.html').respond(200);
$httpBackend.whenGET('/modules/users/client/views/settings/edit-profile.client.view.html').respond(200);
$state.go('settings.profile');
$rootScope.$digest();
}));
it('Should remove trailing slash', inject(function ($state, $location, $rootScope) {
it('Should remove trailing slash', inject(function ($state, $location, $rootScope, $templateCache) {
$templateCache.put('/modules/users/client/views/settings/settings.client.view.html', '');
$templateCache.put('/modules/users/client/views/settings/edit-profile.client.view.html', '');
$location.path('settings/profile/');
$rootScope.$digest();
expect($location.path()).toBe('/settings/profile');
expect($state.current.templateUrl).toBe('modules/users/client/views/settings/edit-profile.client.view.html');
expect($state.current.templateUrl).toBe('/modules/users/client/views/settings/edit-profile.client.view.html');
}));
});
@@ -152,7 +163,7 @@
});
it('Should have templateUrl', function () {
expect(mainstate.templateUrl).toBe('modules/users/client/views/authentication/authentication.client.view.html');
expect(mainstate.templateUrl).toBe('/modules/users/client/views/authentication/authentication.client.view.html');
});
});
@@ -171,7 +182,7 @@
});
it('Should have templateUrl', function () {
expect(signupstate.templateUrl).toBe('modules/users/client/views/authentication/signup.client.view.html');
expect(signupstate.templateUrl).toBe('/modules/users/client/views/authentication/signup.client.view.html');
});
});
@@ -190,7 +201,7 @@
});
it('Should have templateUrl', function () {
expect(signinstate.templateUrl).toBe('modules/users/client/views/authentication/signin.client.view.html');
expect(signinstate.templateUrl).toBe('/modules/users/client/views/authentication/signin.client.view.html');
});
});
@@ -231,7 +242,7 @@
});
it('Should have templateUrl', function () {
expect(forgotstate.templateUrl).toBe('modules/users/client/views/password/forgot-password.client.view.html');
expect(forgotstate.templateUrl).toBe('/modules/users/client/views/password/forgot-password.client.view.html');
});
});
@@ -272,7 +283,7 @@
});
it('Should have templateUrl', function () {
expect(invalidstate.templateUrl).toBe('modules/users/client/views/password/reset-password-invalid.client.view.html');
expect(invalidstate.templateUrl).toBe('/modules/users/client/views/password/reset-password-invalid.client.view.html');
});
});
@@ -291,7 +302,7 @@
});
it('Should have templateUrl', function () {
expect(successstate.templateUrl).toBe('modules/users/client/views/password/reset-password-success.client.view.html');
expect(successstate.templateUrl).toBe('/modules/users/client/views/password/reset-password-success.client.view.html');
});
});
@@ -310,7 +321,7 @@
});
it('Should have templateUrl', function () {
expect(formstate.templateUrl).toBe('modules/users/client/views/password/reset-password.client.view.html');
expect(formstate.templateUrl).toBe('/modules/users/client/views/password/reset-password.client.view.html');
});
});