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,
authority = settings.services[0].authority;
}
if (authority) {
return store.profile({authority: authority}).then(update);
return store.profile.read({authority: authority}).then(update);
} else {
return resource._load().$promise;
}
......
......@@ -143,7 +143,9 @@ function store($http, $q, auth, settings) {
get: apiCall('annotation.read'),
update: apiCall('annotation.update'),
},
profile: apiCall('profile.read'),
profile: {
read: apiCall('profile.read'),
},
};
}
......
......@@ -43,7 +43,9 @@ describe('session', function () {
setUserInfo: sandbox.spy(),
};
fakeStore = {
profile: sandbox.stub(),
profile: {
read: sandbox.stub(),
},
};
fakeSettings = {
serviceUrl: 'https://test.hypothes.is/root/',
......@@ -168,14 +170,14 @@ describe('session', function () {
authority: 'publisher.org',
grantToken: 'a.jwt.token',
}];
fakeStore.profile.returns(Promise.resolve({
fakeStore.profile.read.returns(Promise.resolve({
userid: 'acct:user@publisher.org',
}));
});
it('should fetch profile data from the API', 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 () {
it("fetches the user's profile", function (done) {
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);
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