Skip to content
This repository has been archived by the owner on Oct 9, 2018. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
Update tests to handle the new Persona watch API.
  • Loading branch information
Shane Tomlinson committed Aug 18, 2012
1 parent 79aadb7 commit 4969059
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 10 deletions.
11 changes: 10 additions & 1 deletion client/static/scripts/models/authentication.js
@@ -1,3 +1,4 @@
/*global TestMob: true*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Expand All @@ -12,6 +13,7 @@ TestMob.Models.Authentication = (function() {
browserid;

function authenticate(assertion, callback) {
/*jshint validthis: true*/
var self=this;
ajax.post("/wsapi/login", {
assertion: assertion,
Expand All @@ -29,15 +31,19 @@ TestMob.Models.Authentication = (function() {
}

function signin(callback) {
/*jshint validthis: true*/
var self=this;
self.onlogin = callback;
browserid.request({
siteName: "TestMob",
siteLogo: "/img/logo_small.png"
});
}

function signout(callback) {
/*jshint validthis: true*/
var self=this;
self.onlogout = callback;
ajax.post("/wsapi/logout", {}, function(err, resp) {
if(err) {
// XXX handle error;
Expand All @@ -49,20 +55,23 @@ TestMob.Models.Authentication = (function() {
}

function watch() {
/*jshint validthis: true*/
var self=this;
browserid.watch({
loggedInEmail: window.authenticated_email || null,
onlogin: function(assertion) {
if(assertion) {
authenticate.call(self, assertion);
complete(self.onlogin, null, true);
}
else {
// XXX handle error;
complete(self.onlogin, "no assertion");
}
},
onlogout: function() {
self.set("authenticated", false);
self.set("email", null);
complete(self.onlogout);
}
});
}
Expand Down
1 change: 1 addition & 0 deletions client/static/test/cases/cookie_check.js
@@ -1,3 +1,4 @@
/*global TestMob: true*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Expand Down
5 changes: 3 additions & 2 deletions client/static/test/cases/models/authentication.js
@@ -1,3 +1,4 @@
/*global TestMob: true*/
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
Expand Down Expand Up @@ -50,7 +51,7 @@
start();
});

BrowserID.complete("assertion");
BrowserID.completeLogin("assertion");
});

asyncTest("signout - signs out authenticated user", function() {
Expand All @@ -60,6 +61,6 @@
start();
});

BrowserID.complete();
BrowserID.completeLogout();
});
}());
4 changes: 2 additions & 2 deletions client/static/test/cases/views/authentication.js
Expand Up @@ -67,7 +67,7 @@
start();
});

BrowserID.complete("assertion");
BrowserID.completeLogin("assertion");
});
});

Expand All @@ -81,7 +81,7 @@
start();
});

BrowserID.complete("assertion");
BrowserID.completeLogout("assertion");
});
});

Expand Down
19 changes: 14 additions & 5 deletions client/static/test/mocks/browserid.js
Expand Up @@ -14,16 +14,25 @@ TestMob.Mocks.BrowserID = (function() {

},

get: function(callback, options) {
this.callback = callback;
watch: function(options) {
this.onlogin = options.onlogin;
this.onlogout = options.onlogout;
},

request: function(options) {

},

logout: function(callback) {
this.callback = callback;
this.onlogout();
},

completeLogin: function(status) {
this.onlogin(status);
},

complete: function(status) {
this.callback(status);
completeLogout: function(status) {
this.onlogout(status);
}
};

Expand Down
1 change: 1 addition & 0 deletions client/templates/test.ejs
Expand Up @@ -6,6 +6,7 @@
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
<script src="qunit/qunit.js"></script>

<script src="https://login.persona.org/include.js"></script>
<%- cachify_js("/production/main.min.js") %>

<script src="mocks/mocks.js"></script>
Expand Down

0 comments on commit 4969059

Please sign in to comment.