-
Notifications
You must be signed in to change notification settings - Fork 183
Expand file tree
/
Copy pathoauth-token-provider.spec.js
More file actions
102 lines (80 loc) · 2.72 KB
/
Copy pathoauth-token-provider.spec.js
File metadata and controls
102 lines (80 loc) · 2.72 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/**
* Test `OAuthTokenProvider`.
*/
describe('OAuthTokenProvider', function() {
describe('configure()', function() {
var provider;
beforeEach(function() {
angular.module('angular-oauth2.test', [])
.config(function(OAuthTokenProvider) {
provider = OAuthTokenProvider;
});
angular.mock.module('angular-oauth2', 'angular-oauth2.test');
angular.mock.inject(function() {});
});
it('should throw an error if configuration is not an object', function() {
try {
provider.configure(false);
should.fail();
} catch(e) {
e.should.be.an.instanceOf(TypeError);
e.message.should.match(/config/);
}
});
});
describe('$get()', function() {
beforeEach(function() {
angular.module('angular-oauth2.test', ['angular-cookies.mock'])
.config(function(OAuthProvider) {
OAuthProvider.configure({
baseUrl: 'https://api.website.com',
clientId: 'CLIENT_ID'
});
});
angular.mock.module('angular-oauth2', 'angular-oauth2.test');
angular.mock.inject(function(OAuthToken) {
OAuthToken.setToken({ token_type: 'bearer', access_token: 'foo', expires_in: 3600, refresh_token: 'bar' });
});
});
afterEach(inject(function(OAuthToken) {
OAuthToken.removeToken();
}));
it('configure()', inject(function(OAuthToken) {
var params = { options: { expires: new Date() } };
OAuthToken.configure(params).should.eql(params);
}));
it('getAuthorizationHeader()', inject(function(OAuthToken) {
OAuthToken.getAuthorizationHeader().should.eql('Bearer foo');
}));
it('getAccessToken()', inject(function(OAuthToken) {
OAuthToken.getAccessToken().should.eql('foo');
}));
it('getRefreshToken()', inject(function(OAuthToken) {
OAuthToken.getRefreshToken().should.eql('bar');
}));
it('setToken()', inject(function(OAuthToken) {
OAuthToken.setToken({ token_type: 'bearer', access_token: 'qux', expires_in: 3600, refresh_token: 'biz' });
OAuthToken.getToken().should.eql({
token_type: 'bearer',
access_token: 'qux',
expires_in: 3600,
refresh_token: 'biz'
});
}));
it('getToken()', inject(function(OAuthToken) {
OAuthToken.getToken().should.eql({
token_type: 'bearer',
access_token: 'foo',
expires_in: 3600,
refresh_token: 'bar'
});
}));
it('getTokenType()', inject(function(OAuthToken) {
OAuthToken.getTokenType().should.eql('bearer');
}));
it('removeToken()', inject(function(OAuthToken) {
OAuthToken.removeToken();
(undefined === OAuthToken.getToken()).should.true;
}));
});
});