From a4e480a3ab7903c812a2b4bf1c71c2bcf9ca3a82 Mon Sep 17 00:00:00 2001 From: Tom MacWright Date: Mon, 3 Dec 2012 12:28:11 -0500 Subject: [PATCH] Test oauth --- js/id/connection.js | 4 ++-- js/id/oauth.js | 5 +++-- test/index.html | 1 + test/spec/oauth.js | 19 +++++++++++++++++++ 4 files changed, 25 insertions(+), 4 deletions(-) create mode 100644 test/spec/oauth.js diff --git a/js/id/connection.js b/js/id/connection.js index eaa25ea93..baf767c6a 100644 --- a/js/id/connection.js +++ b/js/id/connection.js @@ -5,7 +5,7 @@ iD.Connection = function() { connection = {}, refNodes = {}, user = {}, - oauth = iD.OAuth().setAPI(apiURL); + oauth = iD.OAuth().api(apiURL); // Request data within the bbox from an external OSM server. function bboxFromAPI(box, callback) { @@ -134,7 +134,7 @@ iD.Connection = function() { connection.url = function(x) { if (!arguments.length) return apiURL; apiURL = x; - oauth.setAPI(x); + oauth.api(x); return connection; }; diff --git a/js/id/oauth.js b/js/id/oauth.js index 70eef0a0a..b613b30cd 100644 --- a/js/id/oauth.js +++ b/js/id/oauth.js @@ -109,8 +109,9 @@ iD.OAuth = function() { }); }; - oauth.setAPI = function(x) { - apibase = x; + oauth.api = function(_) { + if (!arguments.length) return apibase; + apibase = _; return oauth; }; diff --git a/test/index.html b/test/index.html index 33e0ebd73..ee2e98c3e 100644 --- a/test/index.html +++ b/test/index.html @@ -53,6 +53,7 @@ + diff --git a/test/spec/oauth.js b/test/spec/oauth.js new file mode 100644 index 000000000..192a5b93a --- /dev/null +++ b/test/spec/oauth.js @@ -0,0 +1,19 @@ +describe('OAuth', function() { + var o; + beforeEach(function() { + o = iD.OAuth(); + }); + describe('#logout', function() { + it('can log out and will no longer be authenticated', function() { + expect(o.logout()).toEqual(o); + expect(o.authenticated()).toBeFalsy(); + }); + }); + describe('#api', function() { + it('gets and sets url', function() { + expect(o.api('foo')).toEqual(o); + expect(o.api()).toBe('foo'); + }); + }); + +});