Skip to content

Commit fe9359a

Browse files
committed
test: add integration test for implicit grant's token response type
1 parent 6e006bf commit fe9359a

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

test/integration/grant-types/implicit-grant-type_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ var should = require('should');
1414
* Test `ImplicitGrantType` integration.
1515
*/
1616

17-
describe.only('ImplicitGrantType integration', function() {
17+
describe('ImplicitGrantType integration', function() {
1818
describe('constructor()', function() {
1919
it('should throw an error if `model` is missing', function() {
2020
try {
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
'use strict';
2+
3+
/**
4+
* Module dependencies.
5+
*/
6+
7+
var TokenResponseType = require('../../../lib/response-types/token-response-type');
8+
var InvalidArgumentError = require('../../../lib/errors/invalid-argument-error');
9+
var should = require('should');
10+
var url = require('url');
11+
12+
/**
13+
* Test `TokenResponseType` integration.
14+
*/
15+
16+
describe('TokenResponseType integration', function() {
17+
describe('constructor()', function() {
18+
it('should throw an error if `options.accessTokenLifetime` is missing', function() {
19+
try {
20+
new TokenResponseType();
21+
22+
should.fail();
23+
} catch (e) {
24+
e.should.be.an.instanceOf(InvalidArgumentError);
25+
e.message.should.equal('Missing parameter: `accessTokenLifetime`');
26+
}
27+
});
28+
29+
it('should set `accessTokenLifetime`', function() {
30+
var responseType = new TokenResponseType({
31+
accessTokenLifetime: 120,
32+
model: {}
33+
});
34+
35+
responseType.accessTokenLifetime.should.equal(120);
36+
});
37+
38+
it('should set the `model`', function() {
39+
var model = {
40+
foobar: function() {}
41+
};
42+
var handler = new TokenResponseType({ accessTokenLifetime: 120, model: model });
43+
44+
handler.model.should.equal(model);
45+
});
46+
});
47+
48+
describe('buildRedirectUri()', function() {
49+
it('should throw an error if the `redirectUri` is missing', function() {
50+
var responseType = new TokenResponseType({
51+
accessTokenLifetime: 120,
52+
model: {}
53+
});
54+
55+
try {
56+
responseType.buildRedirectUri();
57+
58+
should.fail();
59+
} catch (e) {
60+
e.should.be.an.instanceOf(InvalidArgumentError);
61+
e.message.should.equal('Missing parameter: `redirectUri`');
62+
}
63+
});
64+
65+
it('should return the new redirect uri and set `access_token` and `state` in the query', function() {
66+
var responseType = new TokenResponseType({
67+
accessTokenLifetime: 120,
68+
model: {}
69+
});
70+
71+
responseType.accessToken = 'foobar-token';
72+
var redirectUri = responseType.buildRedirectUri(url.parse('http://example.com/cb'));
73+
74+
url.format(redirectUri).should.equal('http://example.com/cb#access_token=foobar-token');
75+
});
76+
77+
it('should return the new redirect uri and append `access_token` and `state` in the query', function() {
78+
var responseType = new TokenResponseType({
79+
accessTokenLifetime: 120,
80+
model: {}
81+
});
82+
83+
responseType.accessToken = 'foobar-token';
84+
var redirectUri = responseType.buildRedirectUri(url.parse('http://example.com/cb?foo=bar', true));
85+
86+
url.format(redirectUri).should.equal('http://example.com/cb?foo=bar#access_token=foobar-token');
87+
});
88+
});
89+
});

0 commit comments

Comments
 (0)