summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorAzul <azul@riseup.net>2012-11-19 15:58:46 +0100
committerAzul <azul@riseup.net>2012-11-19 15:58:46 +0100
commit49bfe6ab74229ba4da5342382b87dcd6fca239fa (patch)
tree05c70ca228e28a3a5fa3d35b9ffd441aac0a8ede /spec
parent2859af0287d7672df0a8965be43fb9859fca8bf8 (diff)
works - but not quite what i want. Exposing jqXHR to error function
Diffstat (limited to 'spec')
-rw-r--r--spec/helper.js4
-rw-r--r--spec/login_spec.js18
2 files changed, 18 insertions, 4 deletions
diff --git a/spec/helper.js b/spec/helper.js
index 11327af..8bae2c6 100644
--- a/spec/helper.js
+++ b/spec/helper.js
@@ -30,11 +30,11 @@ var specHelper = (function() {
request.respond(200, header, body);
}
- function respondJSON(object) {
+ function respondJSON(object, responseCode) {
var request = this.requests.pop();
header = { "Content-Type": "application/json;charset=utf-8" };
body = JSON.stringify(object);
- request.respond(200, header, body);
+ request.respond(responseCode || 200, header, body);
}
return {
diff --git a/spec/login_spec.js b/spec/login_spec.js
index 4df62a8..3c30d28 100644
--- a/spec/login_spec.js
+++ b/spec/login_spec.js
@@ -48,7 +48,7 @@ describe("Login", function() {
expect(this.srp.session.key()).toBe(K);
});
- it("works with JSON responses", function(){
+ it("authenticates successfully", function(){
var success = sinon.spy();
this.srp.identify(success);
@@ -60,6 +60,20 @@ describe("Login", function() {
expect(success).toHaveBeenCalled();
});
+ it("reports errors during handshake", function(){
+ this.srp.error = sinon.spy();
+ var error = {login: "something went wrong on the server side"};
+ this.srp.identify();
+
+ this.expectRequest('sessions.json', 'login=' +login+ '&A=' +A, 'POST');
+ this.respondJSON(error, 422);
+ //this.expectNoMoreRequests();
+
+ expect(this.srp.error).toHaveBeenCalled;
+ var args = this.srp.error.args[0];
+ expect($.parseJSON(args[0].responseText)).toEqual(error);
+ });
+
it("rejects B = 0", function(){
var success = sinon.spy();
var error = sinon.spy();
@@ -69,7 +83,7 @@ describe("Login", function() {
this.respondJSON({salt: salt, B: 0});
// aborting if B=0
expect(this.requests).toEqual([]);
- expect(error).toHaveBeenCalled();
+ expect(error).toHaveBeenCalledWith("Server send random number 0 - could not login.");
expect(success).not.toHaveBeenCalled();
});
});