diff options
author | Azul <azul@leap.se> | 2012-06-29 14:46:42 +0200 |
---|---|---|
committer | Azul <azul@leap.se> | 2012-06-29 14:48:24 +0200 |
commit | 9d6f2f9f991920f02863464fe4720ced2804f8da (patch) | |
tree | 95b4530d47c2a6583a8abf0d5907079d3b0d95f6 /javascript/spec/signup.js | |
parent | dcdfd2d5b166e563b6b4f76eb91ace0aca0259f0 (diff) |
added tests for registration with jasmin and sinon
Diffstat (limited to 'javascript/spec/signup.js')
-rw-r--r-- | javascript/spec/signup.js | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/javascript/spec/signup.js b/javascript/spec/signup.js new file mode 100644 index 0000000..fb5c014 --- /dev/null +++ b/javascript/spec/signup.js @@ -0,0 +1,68 @@ + + +describe("Signup", function() { + + beforeEach(function() { + this.srp = new SRP(); + this.xhr = sinon.useFakeXMLHttpRequest(); + var requests = this.requests = []; + this.xhr.onCreate = function (xhr) { + requests.push(xhr); + }; + }); + + afterEach(function() { + this.xhr.restore(); + }); + + it("instantiates SRP with a register function", function() { + expect(typeof this.srp.register).toBe('function'); + }); + + it("fetches a salt from /register/salt", function(){ + var callback = sinon.spy(); + this.srp.register_receive_salt = callback; + this.srp.register(); + expect(this.requests.length).toBe(1); + + respondXML(this.requests[0], "<salt>5d3055e0acd3ddcfc15</salt>"); + expect(callback.called).toBeTruthy(); + }); + + it("receives the salt from /register/salt", function(){ + var callback = sinon.spy(); + this.srp.register_send_verifier = callback; + this.srp.register(); + expect(this.requests.length).toBe(1); + + respondXML(this.requests[0], "<salt>5d3055e0acd3ddcfc15</salt>"); + expect(callback).toHaveBeenCalledWith("adcd57b4a4a05c2e205b0b7b30014d9ff635d8d8db2f502f08e9b9c132800c44"); + }); + + it("identifies after successful registration (INTEGRATION)", function(){ + var callback = sinon.spy(); + this.srp.identify = callback; + this.srp.register(); + expect(this.requests.length).toBe(1); + expect(this.requests[0].url).toBe("register/salt/"); + expect(this.requests[0].requestBody).toBe("I=user"); + respondXML(this.requests[0], "<salt>5d3055e0acd3ddcfc15</salt>"); + expect(this.requests.length).toBe(2); + expect(this.requests[1].url).toBe("register/user/"); + expect(this.requests[1].requestBody).toBe("v=adcd57b4a4a05c2e205b0b7b30014d9ff635d8d8db2f502f08e9b9c132800c44"); + respondXML(this.requests[1], "<ok/>"); + expect(callback).toHaveBeenCalled(); + }); + + + // HELPERS + + function respondXML(request, content) { + header = { "Content-Type": "application/xml;charset=utf-8" }; + body = '<?xml version="1.0" encoding="UTF-8"?>\n'; + body += content; + request.respond(200, header, body); + } +}); + + |