Skip to content

Commit 785bb82

Browse files
Add test to check for authorization redirect
1 parent c6cd70d commit 785bb82

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

test/index.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
<head>
44
<meta charset="utf-8">
55
<title>JSO Test (QUnit)</title>
6-
<link rel="stylesheet" href="//code.jquery.com/qunit/qunit-1.16.0.css">
6+
<link rel="stylesheet" href="../bower_components/qunit/qunit/qunit.css">
77
</head>
88
<body>
99
<div id="qunit"></div>
1010
<div id="qunit-fixture"></div>
11-
<script src="//code.jquery.com/qunit/qunit-1.16.0.js"></script>
11+
<script type="text/javascript" src="../build/jso.js"></script>
12+
<script src="../bower_components/qunit/qunit/qunit.js"></script>
1213
<script src="tests.js"></script>
1314
</body>
1415
</html>

test/tests.js

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,66 @@
1-
QUnit.test( "hello test", function( assert ) {
2-
assert.ok( 1 == "1", "Passed!" );
1+
2+
3+
var config = {
4+
providerID: "google",
5+
client_id: "541950296471.apps.googleusercontent.com",
6+
redirect_uri: "http://bridge.uninett.no/jso/index.html",
7+
authorization: "https://accounts.google.com/o/oauth2/auth",
8+
scopes: { request: ["https://www.googleapis.com/auth/userinfo.profile"]},
9+
debug:true
10+
};
11+
12+
13+
var RedirectCatcher = function() {
14+
var that = this;
15+
this.callback = null;
16+
this.url = null;
17+
setTimeout(function() {
18+
if (that.url === null) {
19+
if (typeof that.callback === 'function') {
20+
that.callback(null);
21+
}
22+
}
23+
}, 2000);
24+
};
25+
RedirectCatcher.prototype.onRedirect = function(callback) {
26+
this.callback = callback;
27+
};
28+
RedirectCatcher.prototype.redirect = function(url) {
29+
console.log("RedirectCatcherreceived redirect to ", url);
30+
this.url = url;
31+
if (typeof this.callback === 'function') {
32+
this.callback(this.url);
33+
} else {
34+
console.error("Callback was not defined");
35+
}
36+
};
37+
38+
39+
QUnit.test( "JSO Loaded", function( assert ) {
40+
console.log("JSO", JSO);
41+
assert.ok(typeof JSO === 'function', "JSO successfully loaded.");
42+
assert.ok( 1 == "1", "Passed!" );
43+
44+
});
45+
QUnit.test( "JSO Authorization redirect", function( assert ) {
46+
var done = assert.async();
47+
var r = new RedirectCatcher();
48+
r.onRedirect(function(url) {
49+
assert.ok(url !== null, 'Redirect was performed');
50+
console.log("Redirect to ", url);
51+
done();
52+
});
53+
54+
var jso = new JSO(config);
55+
jso.on('redirect', function(url) {
56+
r.redirect(url);
57+
});
58+
59+
jso.getToken(function(token) {
60+
61+
console.log("I got the token: ", token);
62+
63+
}, {});
64+
65+
366
});

0 commit comments

Comments
 (0)