2013-09-14 01:19:02 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
2015-03-22 13:06:37 +00:00
|
|
|
describe('Auth Controller', function() {
|
2013-09-14 01:19:02 +00:00
|
|
|
|
|
|
|
|
describe('AuthCtrl', function(){
|
2013-10-02 02:20:10 +00:00
|
|
|
var scope, ctrl, user, $httpBackend, $window;
|
2013-09-14 01:19:02 +00:00
|
|
|
|
|
|
|
|
beforeEach(inject(function(_$httpBackend_, $rootScope, $controller) {
|
|
|
|
|
$httpBackend = _$httpBackend_;
|
|
|
|
|
scope = $rootScope.$new();
|
2015-03-07 21:48:23 +00:00
|
|
|
scope.loginUsername = 'user';
|
|
|
|
|
scope.loginPassword = 'pass';
|
2015-06-20 19:48:38 +00:00
|
|
|
$window = { location: { href: ""}, alert: sandbox.spy() };
|
|
|
|
|
user = { user: {}, authenticate: sandbox.spy() };
|
2013-09-14 01:19:02 +00:00
|
|
|
|
2013-10-02 02:20:10 +00:00
|
|
|
ctrl = $controller('AuthCtrl', {$scope: scope, $window: $window, User: user});
|
|
|
|
|
}));
|
2013-09-14 01:19:02 +00:00
|
|
|
|
|
|
|
|
it('should log in users with correct uname / pass', function() {
|
2013-12-24 01:38:15 +00:00
|
|
|
$httpBackend.expectPOST('/api/v2/user/auth/local').respond({id: 'abc', token: 'abc'});
|
2013-10-02 02:20:10 +00:00
|
|
|
scope.auth();
|
|
|
|
|
$httpBackend.flush();
|
2015-06-20 19:48:38 +00:00
|
|
|
expect(user.authenticate).to.be.calledOnce;
|
|
|
|
|
expect($window.alert).to.not.be.called;
|
2013-10-02 02:20:10 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it('should not log in users with incorrect uname / pass', function() {
|
2013-12-24 01:38:15 +00:00
|
|
|
$httpBackend.expectPOST('/api/v2/user/auth/local').respond(404, '');
|
2013-10-02 02:20:10 +00:00
|
|
|
scope.auth();
|
|
|
|
|
$httpBackend.flush();
|
2015-06-20 19:48:38 +00:00
|
|
|
expect(user.authenticate).to.not.be.called;
|
|
|
|
|
expect($window.alert).to.be.calledOnce;
|
2013-09-14 01:19:02 +00:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2014-01-12 23:00:47 +00:00
|
|
|
});
|