-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.unit.js
40 lines (34 loc) · 1.06 KB
/
app.unit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
'use strict';
describe('Token Interceptor', function() {
var tokenInterceptor;
var authenticationService, _window, $q;
beforeEach(module('UserService'));
beforeEach(inject(function(_$q_, AuthenticationService, $window, TokenInterceptor) {
authenticationService = AuthenticationService;
_window = $window;
$q = _$q_;
tokenInterceptor = TokenInterceptor;
$window.sessionStorage.token = true;
authenticationService.isAuthenticated = false;
}));
it('should have TokenInterceptor be defined', function() {
expect(tokenInterceptor).toBeDefined();
});
it('HTTP status : is 200 ok', function() {
var response = {
status: 200,
config: {}
};
var promise = tokenInterceptor.response(response)
expect(authenticationService.isAuthenticated).toBeTruthy();
});
it('HTTP status : is 401 Unauthorized', function() {
var response = {
status: 401,
config: {}
};
spyOn($q, 'reject');
var promise = tokenInterceptor.responseError(response)
expect($q.reject).toHaveBeenCalled();
});
});