improve tests
This commit is contained in:
parent
ef659724c7
commit
cd02c1bad4
|
@ -4,7 +4,8 @@ angular.module('warehost', [
|
||||||
'ui.router',
|
'ui.router',
|
||||||
'ui.bootstrap',
|
'ui.bootstrap',
|
||||||
'config',
|
'config',
|
||||||
'session'
|
'session',
|
||||||
|
'alert'
|
||||||
])
|
])
|
||||||
.config(['$urlRouterProvider','$httpProvider',function($urlRouterProvider,$httpProvider){
|
.config(['$urlRouterProvider','$httpProvider',function($urlRouterProvider,$httpProvider){
|
||||||
$urlRouterProvider.otherwise('/');
|
$urlRouterProvider.otherwise('/');
|
||||||
|
|
|
@ -8,7 +8,10 @@ angular.module('warehost')
|
||||||
})
|
})
|
||||||
.state('app.index', {
|
.state('app.index', {
|
||||||
url:'/',
|
url:'/',
|
||||||
templateUrl: 'app/home.html'
|
templateUrl: 'app/home.html',
|
||||||
|
controller:function(alert){
|
||||||
|
alert.set({});
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.state('app.L', {
|
.state('app.L', {
|
||||||
templateUrl: 'app/loggedin.html'
|
templateUrl: 'app/loggedin.html'
|
||||||
|
|
|
@ -31,11 +31,17 @@
|
||||||
span.glyphicon.glyphicon-user
|
span.glyphicon.glyphicon-user
|
||||||
.navbar-text
|
.navbar-text
|
||||||
span.glyphicon.glyphicon-log-out(ng-click="logout()")
|
span.glyphicon.glyphicon-log-out(ng-click="logout()")
|
||||||
form.navbar-form.navbar-right(ng-if="!session.login.active",ng-class="{'has-warning':globals.currentUser.authdata}",ng-submit="login()")
|
form.navbar-form.navbar-right(ng-if="!session.login.active",ng-submit="login()")
|
||||||
input.form-control(ng-model="obj.username",placeholder="Username")
|
.form-group(ng-class="{'has-error': (error.fields.indexOf('username') >= 0)}")
|
||||||
.input-group
|
input.form-control(ng-model="obj.username",placeholder="Username",pattern=".{3,}")
|
||||||
input.form-control(type="password",ng-model="obj.password",placeholder="Password")
|
.form-group(ng-class="{'has-error': (error.fields.indexOf('password') >= 0)}")
|
||||||
.input-group-btn
|
.input-group
|
||||||
button.btn.btn-default(type="submit")
|
input.form-control(type="password",ng-model="obj.password",placeholder="Password")
|
||||||
span.glyphicon.glyphicon-log-in
|
.input-group-btn
|
||||||
div(ui-view="",style="margin-top:53px;")
|
button.btn.btn-default(type="submit")
|
||||||
|
span.glyphicon.glyphicon-log-in
|
||||||
|
div(style="margin-top:53px;")
|
||||||
|
.container(ng-if="error.msg")
|
||||||
|
.alert.alert-danger(style="margin-top:20px;")
|
||||||
|
{{error.msg}}
|
||||||
|
div(ui-view="")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('warehost')
|
angular.module('warehost')
|
||||||
.controller('MainCtrl',function($scope,$http,$state,config,session){
|
.controller('MainCtrl',function($scope,alert,$http,$state,config,session){
|
||||||
$scope.isOpen = false;
|
$scope.isOpen = false;
|
||||||
$scope.obj = {};
|
$scope.obj = {};
|
||||||
$scope.$state = $state;
|
$scope.$state = $state;
|
||||||
|
@ -12,11 +12,13 @@ angular.module('warehost')
|
||||||
$scope.logout = function(){
|
$scope.logout = function(){
|
||||||
$http.get(config.api+'/logout').then(function(res){
|
$http.get(config.api+'/logout').then(function(res){
|
||||||
session.set(res);
|
session.set(res);
|
||||||
|
alert.set(res);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
$scope.login = function(){
|
$scope.login = function(){
|
||||||
$http.post(config.api+'/login',$scope.obj).then(function(res){
|
$http.post(config.api+'/login',$scope.obj).then(function(res){
|
||||||
session.set(res);
|
session.set(res);
|
||||||
|
alert.set(res);
|
||||||
$scope.obj = {};
|
$scope.obj = {};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
|
@ -3,19 +3,19 @@
|
||||||
.row
|
.row
|
||||||
.col-md-6
|
.col-md-6
|
||||||
h2 Global
|
h2 Global
|
||||||
form.well.well-sm(ng-submit="submit()")
|
form.well.well-sm(ng-submit="submit()",name="myform")
|
||||||
.form-group
|
.form-group
|
||||||
label(for="globalUsername") Username
|
label(for="globalUsername") Username
|
||||||
input.form-control(id="globalUsername",ng-model="session.login.username",readonly)
|
input.form-control(id="globalUsername",ng-model="session.login.username",readonly)
|
||||||
.form-group
|
.form-group(ng-class="{'has-error': (error.fields.indexOf('currentpassword') >= 0)}")
|
||||||
label(for="currentPassword") Current Password
|
label(for="currentPassword") Current Password
|
||||||
input.form-control(id="currentPassword",type="password",ng-model="obj.currentPassword")
|
input.form-control(id="currentPassword",type="password",ng-model="obj.currentPassword")
|
||||||
.form-group
|
.form-group(ng-class="{'has-error': (error.fields.indexOf('newpassword') >= 0 || !myform.newPassword.$valid)}")
|
||||||
label(for="newPassword") New Password
|
label(for="newPassword") New Password
|
||||||
input.form-control(id="newPassword",type="password",ng-model="obj.newPassword")
|
input.form-control(id="newPassword",type="password",name="newPassword",ng-model="obj.newPassword",ng-minlength="3")
|
||||||
.form-group
|
.form-group(ng-class="{'has-error': (obj.newPassword != obj.repeatPassword && myform.repeatPassword.$dirty)}")
|
||||||
label(for="repeatPassword") Again Password
|
label(for="repeatPassword") Again Password
|
||||||
input.form-control(id="repeatPassword",type="password",ng-model="obj.repeatPassword")
|
input.form-control(id="repeatPassword",type="password",name="repeatPassword",ng-model="obj.repeatPassword")
|
||||||
.row
|
.row
|
||||||
.col-xs-6
|
.col-xs-6
|
||||||
button.btn.btn-primary(type="submit")
|
button.btn.btn-primary(type="submit")
|
||||||
|
|
|
@ -1,19 +1,28 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
angular.module('warehost')
|
angular.module('warehost')
|
||||||
.controller('SettingsCtrl',function(session,config,$scope,$http){
|
.controller('SettingsCtrl',function(session,config,alert,$scope,$http){
|
||||||
$scope.obj = {};
|
$scope.obj = {};
|
||||||
|
alert.set({});
|
||||||
$scope.submit = function(){
|
$scope.submit = function(){
|
||||||
$http.post(config.api+'/password',$scope.obj).then(function(res){
|
if($scope.obj.newPassword === $scope.obj.repeatPassword){
|
||||||
session.set(res);
|
$http.post(config.api+'/password',$scope.obj).then(function(res){
|
||||||
$scope.obj = {};
|
session.set(res);
|
||||||
});
|
alert.set(res);
|
||||||
|
$scope.obj = {};
|
||||||
|
});
|
||||||
|
}else{
|
||||||
|
alert.set({msg:'Not equal Passwords'});
|
||||||
|
}
|
||||||
};
|
};
|
||||||
$scope.delete = function(){
|
$scope.delete = function(){
|
||||||
if(window.confirm('realy delete your login and everything else on warehost?')){
|
if(window.confirm('realy delete your login and everything else on warehost?')){
|
||||||
$http.get(config.api+'/delete').then(function(res){
|
$http.get(config.api+'/delete').then(function(res){
|
||||||
session.set(res);
|
session.set(res);
|
||||||
|
alert.set(res);
|
||||||
});
|
});
|
||||||
|
}else{
|
||||||
|
alert.set({msg:'Account not deleted'});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
'use strict';
|
||||||
|
angular.module('alert', [])
|
||||||
|
.factory('alert', ['$rootScope',function($rootScope) {
|
||||||
|
return {
|
||||||
|
set: function (res){
|
||||||
|
if(res.data){
|
||||||
|
$rootScope.error = res.data.error;
|
||||||
|
}else{
|
||||||
|
$rootScope.error = res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}]);
|
|
@ -2,6 +2,6 @@
|
||||||
angular.module('config', [])
|
angular.module('config', [])
|
||||||
.factory('config', function() {
|
.factory('config', function() {
|
||||||
return {
|
return {
|
||||||
api: 'http://[::1]:8080',
|
api: 'http://[::1]:8080'
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,7 +7,6 @@ angular.module('session', [])
|
||||||
},
|
},
|
||||||
set: function (res){
|
set: function (res){
|
||||||
$rootScope.session = res.data.session;
|
$rootScope.session = res.data.session;
|
||||||
console.log(res,$rootScope.session);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}]);
|
}]);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<!-- bower:css -->
|
<!-- bower:css -->
|
||||||
<!-- endbower -->
|
<!-- endbower -->
|
||||||
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css" />
|
<link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css" />
|
||||||
<link rel="stylesheet" href="bower_components/bootswatch/lumen/bootstrap.min.css" />
|
<link rel="stylesheet" href="bower_components/bootswatch/paper/bootstrap.min.css" />
|
||||||
<!-- endbuild -->
|
<!-- endbuild -->
|
||||||
<!-- build:css({.tmp,public}) app/app.css -->
|
<!-- build:css({.tmp,public}) app/app.css -->
|
||||||
<link rel="stylesheet" href="app/app.css">
|
<link rel="stylesheet" href="app/app.css">
|
||||||
|
@ -48,6 +48,7 @@
|
||||||
<script src="app/main.js"></script>
|
<script src="app/main.js"></script>
|
||||||
<script src="app/settings.js"></script>
|
<script src="app/settings.js"></script>
|
||||||
<script src="app/shift/index.js"></script>
|
<script src="app/shift/index.js"></script>
|
||||||
|
<script src="components/alert.js"></script>
|
||||||
<script src="components/config.js"></script>
|
<script src="components/config.js"></script>
|
||||||
<script src="components/session.js"></script>
|
<script src="components/session.js"></script>
|
||||||
<!-- endinjector -->
|
<!-- endinjector -->
|
||||||
|
|
|
@ -10,8 +10,10 @@ describe('API',->
|
||||||
request({method: 'GET',uri:config.ADDRESS+"/status"},(err,res,body)->
|
request({method: 'GET',uri:config.ADDRESS+"/status"},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
x = JSON.parse(body)
|
if(typeof body == "string")
|
||||||
expect(x.data).to.be.true
|
body = JSON.parse(body)
|
||||||
|
expect(body.data).to.be.true
|
||||||
|
expect(body.error).to.be.null
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -23,7 +25,11 @@ describe('API',->
|
||||||
}},(err,res,body)->
|
}},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
|
if(typeof body == "string")
|
||||||
|
body = JSON.parse(body)
|
||||||
expect(body.data).to.be.false
|
expect(body.data).to.be.false
|
||||||
|
expect(body.error.msg).to.not.be.null
|
||||||
|
expect(body.error.fields).to.include('username')
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -34,7 +40,11 @@ describe('API',->
|
||||||
}},(err,res,body)->
|
}},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
|
if(typeof body == "string")
|
||||||
|
body = JSON.parse(body)
|
||||||
expect(body.data).to.be.false
|
expect(body.data).to.be.false
|
||||||
|
expect(body.error.msg).to.not.be.null
|
||||||
|
expect(body.error.fields).to.include('password')
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -45,7 +55,10 @@ describe('API',->
|
||||||
}},(err,res,body)->
|
}},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
|
if(typeof body == "string")
|
||||||
|
body = JSON.parse(body)
|
||||||
expect(body.data).to.be.true
|
expect(body.data).to.be.true
|
||||||
|
expect(body.error).to.be.null
|
||||||
expect(body.session.login.active).to.be.true
|
expect(body.session.login.active).to.be.true
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
|
@ -56,9 +69,11 @@ describe('API',->
|
||||||
request({method: 'GET',uri:config.ADDRESS+"/logout"},(err,res,body)->
|
request({method: 'GET',uri:config.ADDRESS+"/logout"},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
x = JSON.parse(body)
|
if(typeof body == "string")
|
||||||
expect(x.data).to.be.true
|
body = JSON.parse(body)
|
||||||
expect(x.session.login).to.be.null
|
expect(body.data).to.be.false
|
||||||
|
expect(body.error.msg).to.not.be.null
|
||||||
|
expect(body.error.fields).to.include('session')
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -67,9 +82,11 @@ describe('API',->
|
||||||
request({method: 'GET',uri:config.ADDRESS+"/logout",jar:j},(err,res,body)->
|
request({method: 'GET',uri:config.ADDRESS+"/logout",jar:j},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
x = JSON.parse(body)
|
if(typeof body == "string")
|
||||||
expect(x.data).to.be.true
|
body = JSON.parse(body)
|
||||||
expect(x.session.login).to.be.null
|
expect(body.data).to.be.true
|
||||||
|
expect(body.error).to.be.null
|
||||||
|
expect(body.session.login).to.be.null
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -83,9 +100,12 @@ describe('API',->
|
||||||
}},(err,res,body)->
|
}},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
x = JSON.parse(body)
|
if(typeof body == "string")
|
||||||
expect(x.data).to.be.true
|
body = JSON.parse(body)
|
||||||
expect(x.session.login).to.be.null
|
expect(body.data).to.be.false
|
||||||
|
expect(body.error.msg).to.not.be.null
|
||||||
|
expect(body.error.fields).to.include('session')
|
||||||
|
expect(body.session.login).to.be.null
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -97,9 +117,12 @@ describe('API',->
|
||||||
},jar:j},(err,res,body)->
|
},jar:j},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
x = JSON.parse(body)
|
if(typeof body == "string")
|
||||||
expect(x.data).to.be.false
|
body = JSON.parse(body)
|
||||||
expect(x.session.login).to.be.null
|
expect(body.data).to.be.false
|
||||||
|
expect(body.error.msg).to.not.be.null
|
||||||
|
expect(body.error.fields).to.include('currentpassword')
|
||||||
|
expect(body.session.login).to.not.be.null
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -112,9 +135,12 @@ describe('API',->
|
||||||
},jar:j},(err,res,body)->
|
},jar:j},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
x = JSON.parse(body)
|
if(typeof body == "string")
|
||||||
expect(x.data).to.be.false
|
body = JSON.parse(body)
|
||||||
expect(x.session.login).to.be.null
|
expect(body.data).to.be.false
|
||||||
|
expect(body.error.msg).to.not.be.null
|
||||||
|
expect(body.error.fields).to.include('newpassword')
|
||||||
|
expect(body.session.login).to.not.be.null
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -127,13 +153,15 @@ describe('API',->
|
||||||
},jar:j},(err,res,body)->
|
},jar:j},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
x = JSON.parse(body)
|
if(typeof body == "string")
|
||||||
expect(x.data).to.be.true
|
body = JSON.parse(body)
|
||||||
expect(x.session.login).to.be.null
|
expect(body.data).to.be.true
|
||||||
|
expect(body.error).to.be.null
|
||||||
request({method: 'POST',uri: config.ADDRESS+"/password",json:{
|
request({method: 'POST',uri: config.ADDRESS+"/password",json:{
|
||||||
currentpassword: config.testdata.password+"f",
|
currentpassword: config.testdata.password+"f",
|
||||||
newpassword: config.testdata.password,
|
newpassword: config.testdata.password,
|
||||||
},jar:j},(err,res,body)->
|
},jar:j},(err,res,body)->
|
||||||
|
expect(body.data).to.be.true
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -145,9 +173,12 @@ describe('API',->
|
||||||
request({method: 'GET',uri:config.ADDRESS+"/delete"},(err,res,body)->
|
request({method: 'GET',uri:config.ADDRESS+"/delete"},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
x = JSON.parse(body)
|
if(typeof body == "string")
|
||||||
expect(x.data).to.be.true
|
body = JSON.parse(body)
|
||||||
expect(x.session.login).to.be.null
|
expect(body.data).to.be.false
|
||||||
|
expect(body.error.msg).to.not.be.null
|
||||||
|
expect(body.error.fields).to.include('session')
|
||||||
|
expect(body.session.login).to.be.null
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -156,9 +187,11 @@ describe('API',->
|
||||||
request({method: 'GET',uri:config.ADDRESS+"/delete",jar:j},(err,res,body)->
|
request({method: 'GET',uri:config.ADDRESS+"/delete",jar:j},(err,res,body)->
|
||||||
expect(err).to.be.null
|
expect(err).to.be.null
|
||||||
expect(res.statusCode).to.be.equal(200)
|
expect(res.statusCode).to.be.equal(200)
|
||||||
x = JSON.parse(body)
|
if(typeof body == "string")
|
||||||
expect(x.data).to.be.true
|
body = JSON.parse(body)
|
||||||
expect(x.session.login).to.be.null
|
expect(body.data).to.be.true
|
||||||
|
expect(body.error).to.be.null
|
||||||
|
expect(body.session.login).to.be.null
|
||||||
done()
|
done()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
Reference in New Issue