From 09a6d9eb8d0467f311bbae3d6fe2d923244edb21 Mon Sep 17 00:00:00 2001 From: Azul Date: Mon, 15 Oct 2012 11:10:35 +0200 Subject: all rest tests passing, using proper verbs --- spec/restful/login.js | 6 +++--- spec/restful/signup.js | 2 +- spec/specHelper.js | 5 ++++- src/jqueryRest.js | 21 +++++++++------------ 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/spec/restful/login.js b/spec/restful/login.js index 3bf9dda..0f6aa4f 100644 --- a/spec/restful/login.js +++ b/spec/restful/login.js @@ -49,21 +49,21 @@ describe("Login", function() { this.expectRequest('sessions', 'login=' +login+ '&A=' +A, 'POST'); this.respondJSON({s: salt, B: B}); - this.expectRequest('sessions/'+login, 'client_auth='+M); + this.expectRequest('sessions/'+login, 'client_auth='+M, 'PUT'); this.respondJSON({M: M2}); expect(this.srp.success).toHaveBeenCalled(); }); it("rejects B = 0", function(){ - this.srp.error_message = sinon.spy(); + this.srp.error = sinon.spy(); this.srp.identify(); this.expectRequest('sessions', 'login=' +login+ '&A=' +A, 'POST'); this.respondJSON({s: salt, B: 0}); // aborting if B=0 expect(this.requests).toEqual([]); - expect(this.srp.error_message).toHaveBeenCalled(); + expect(this.srp.error).toHaveBeenCalled(); }); }); diff --git a/spec/restful/signup.js b/spec/restful/signup.js index bc20b14..7b66dd7 100644 --- a/spec/restful/signup.js +++ b/spec/restful/signup.js @@ -22,7 +22,7 @@ describe("Signup", function() { this.srp.identify = callback; this.srp.session.getSalt = function() {return "4c78c3f8"}; this.srp.register(); - this.expectRequest('users', "user[login]=testuser&user[password_salt]=4c78c3f8&user[password_verifier]=474c26aa42d11f20544a00f7bf9711c4b5cf7aab95ed448df82b95521b96668e7480b16efce81c861870302560ddf6604c67df54f1d04b99d5bb9d0f02c6051ada5dc9d594f0d4314e12f876cfca3dcd99fc9c98c2e6a5e04298b11061fb8549a22cde0564e91514080df79bca1c38c682214d65d590f66b3719f954b078b83c") + this.expectRequest('users', "user[login]=testuser&user[password_salt]=4c78c3f8&user[password_verifier]=474c26aa42d11f20544a00f7bf9711c4b5cf7aab95ed448df82b95521b96668e7480b16efce81c861870302560ddf6604c67df54f1d04b99d5bb9d0f02c6051ada5dc9d594f0d4314e12f876cfca3dcd99fc9c98c2e6a5e04298b11061fb8549a22cde0564e91514080df79bca1c38c682214d65d590f66b3719f954b078b83c", 'POST') this.respondJSON({password_salt: "4c78c3f8", login: "testuser", ok: "true"}); expect(callback).toHaveBeenCalled(); }); diff --git a/spec/specHelper.js b/spec/specHelper.js index 893f8a4..11327af 100644 --- a/spec/specHelper.js +++ b/spec/specHelper.js @@ -13,10 +13,13 @@ var specHelper = (function() { } // TODO: validate http verb - function expectRequest(url, content) { + function expectRequest(url, content, verb) { expect(this.requests.length).toBe(1); expect(this.requests[0].url).toBe(url); expect(decodeURI(this.requests[0].requestBody)).toBe(content); + if (verb) { + expect(this.requests[0].method).toBe(verb); + } } function respondXML(content) { diff --git a/src/jqueryRest.js b/src/jqueryRest.js index 64c8080..f50080b 100644 --- a/src/jqueryRest.js +++ b/src/jqueryRest.js @@ -1,12 +1,5 @@ jqueryRest = function() { - // Perform ajax requests at the specified path, with the specified parameters - // Calling back the specified function. - function ajaxRequest(relative_path, params, callback) - { - $.post(relative_path, params, callback) - } - function parseResponse() { if (responseIsXML()) { return parseXML(xhr.responseXML); @@ -61,7 +54,7 @@ jqueryRest = function() { function sendVerifier(session, callback) { var salt = session.getSalt(); - ajaxRequest("users", { user: + $.post("users", { user: { login: session.getI(), password_salt: salt, password_verifier: session.getV(salt).toString(16)} @@ -69,16 +62,20 @@ jqueryRest = function() { } function handshake(session, callback) { - ajaxRequest("sessions", { login: session.getI(), + $.post("sessions", { login: session.getI(), A: session.getAstr()}, callback); } - function authenticate(session, callback) { - ajaxRequest("sessions/" + session.getI(), {client_auth: session.getM()}, callback); + function authenticate(session, success) { + $.ajax({ + url: "sessions/" + session.getI(), + type: 'PUT', + data: {client_auth: session.getM()}, + success: success + }); } return { - ajaxRequest: ajaxRequest, register: register, register_send_verifier: sendVerifier, handshake: handshake, -- cgit v1.2.3