Commit 126bcbe9 authored by chdorner's avatar chdorner

Refactor store profile API call

Make `store.profile` an object containing `read` in preperation for the
upcoming changes where we will use the update profile endpoint for
updating a user's preferences.
parent cca76111
...@@ -89,7 +89,7 @@ function session($http, $resource, $rootScope, annotationUI, auth, ...@@ -89,7 +89,7 @@ function session($http, $resource, $rootScope, annotationUI, auth,
authority = settings.services[0].authority; authority = settings.services[0].authority;
} }
if (authority) { if (authority) {
return store.profile({authority: authority}).then(update); return store.profile.read({authority: authority}).then(update);
} else { } else {
return resource._load().$promise; return resource._load().$promise;
} }
......
...@@ -143,7 +143,9 @@ function store($http, $q, auth, settings) { ...@@ -143,7 +143,9 @@ function store($http, $q, auth, settings) {
get: apiCall('annotation.read'), get: apiCall('annotation.read'),
update: apiCall('annotation.update'), update: apiCall('annotation.update'),
}, },
profile: apiCall('profile.read'), profile: {
read: apiCall('profile.read'),
},
}; };
} }
......
...@@ -43,7 +43,9 @@ describe('session', function () { ...@@ -43,7 +43,9 @@ describe('session', function () {
setUserInfo: sandbox.spy(), setUserInfo: sandbox.spy(),
}; };
fakeStore = { fakeStore = {
profile: sandbox.stub(), profile: {
read: sandbox.stub(),
},
}; };
fakeSettings = { fakeSettings = {
serviceUrl: 'https://test.hypothes.is/root/', serviceUrl: 'https://test.hypothes.is/root/',
...@@ -168,14 +170,14 @@ describe('session', function () { ...@@ -168,14 +170,14 @@ describe('session', function () {
authority: 'publisher.org', authority: 'publisher.org',
grantToken: 'a.jwt.token', grantToken: 'a.jwt.token',
}]; }];
fakeStore.profile.returns(Promise.resolve({ fakeStore.profile.read.returns(Promise.resolve({
userid: 'acct:user@publisher.org', userid: 'acct:user@publisher.org',
})); }));
}); });
it('should fetch profile data from the API', function () { it('should fetch profile data from the API', function () {
return session.load().then(function () { return session.load().then(function () {
assert.calledWith(fakeStore.profile, {authority: 'publisher.org'}); assert.calledWith(fakeStore.profile.read, {authority: 'publisher.org'});
}); });
}); });
......
...@@ -150,7 +150,7 @@ describe('store', function () { ...@@ -150,7 +150,7 @@ describe('store', function () {
it("fetches the user's profile", function (done) { it("fetches the user's profile", function (done) {
var profile = {userid: 'acct:user@publisher.org'}; var profile = {userid: 'acct:user@publisher.org'};
store.profile({authority: 'publisher.org'}).then(function (profile_) { store.profile.read({authority: 'publisher.org'}).then(function (profile_) {
assert.deepEqual(profile_, profile); assert.deepEqual(profile_, profile);
done(); done();
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment