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