Skip to content

Commit

Permalink
Add test to check for authorization redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
andreassolberg committed Dec 22, 2014
1 parent c6cd70d commit 785bb82
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 4 deletions.
5 changes: 3 additions & 2 deletions test/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
<head>
<meta charset="utf-8">
<title>JSO Test (QUnit)</title>
<link rel="stylesheet" href="//code.jquery.com/qunit/qunit-1.16.0.css">
<link rel="stylesheet" href="../bower_components/qunit/qunit/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script src="//code.jquery.com/qunit/qunit-1.16.0.js"></script>
<script type="text/javascript" src="../build/jso.js"></script>
<script src="../bower_components/qunit/qunit/qunit.js"></script>
<script src="tests.js"></script>
</body>
</html>
67 changes: 65 additions & 2 deletions test/tests.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,66 @@
QUnit.test( "hello test", function( assert ) {
assert.ok( 1 == "1", "Passed!" );


var config = {
providerID: "google",
client_id: "541950296471.apps.googleusercontent.com",
redirect_uri: "http://bridge.uninett.no/jso/index.html",
authorization: "https://accounts.google.com/o/oauth2/auth",
scopes: { request: ["https://www.googleapis.com/auth/userinfo.profile"]},
debug:true
};


var RedirectCatcher = function() {
var that = this;
this.callback = null;
this.url = null;
setTimeout(function() {
if (that.url === null) {
if (typeof that.callback === 'function') {
that.callback(null);
}
}
}, 2000);
};
RedirectCatcher.prototype.onRedirect = function(callback) {
this.callback = callback;
};
RedirectCatcher.prototype.redirect = function(url) {
console.log("RedirectCatcherreceived redirect to ", url);
this.url = url;
if (typeof this.callback === 'function') {
this.callback(this.url);
} else {
console.error("Callback was not defined");
}
};


QUnit.test( "JSO Loaded", function( assert ) {
console.log("JSO", JSO);
assert.ok(typeof JSO === 'function', "JSO successfully loaded.");
assert.ok( 1 == "1", "Passed!" );

});
QUnit.test( "JSO Authorization redirect", function( assert ) {
var done = assert.async();
var r = new RedirectCatcher();
r.onRedirect(function(url) {
assert.ok(url !== null, 'Redirect was performed');
console.log("Redirect to ", url);
done();
});

var jso = new JSO(config);
jso.on('redirect', function(url) {
r.redirect(url);
});

jso.getToken(function(token) {

console.log("I got the token: ", token);

}, {});


});

0 comments on commit 785bb82

Please sign in to comment.