Commit 2450954f authored by chdorner's avatar chdorner

Use new profile update endpoint for dismissing tutorial

parent 806925fa
...@@ -20,11 +20,6 @@ function sessionActions(options) { ...@@ -20,11 +20,6 @@ function sessionActions(options) {
}, },
_load: { method: 'GET' }, _load: { method: 'GET' },
dismiss_sidebar_tutorial: {
method: 'POST',
params: { path: 'dismiss_sidebar_tutorial' },
},
}; };
Object.keys(actions).forEach(function (action) { Object.keys(actions).forEach(function (action) {
...@@ -104,6 +99,16 @@ function session($http, $resource, $rootScope, annotationUI, auth, ...@@ -104,6 +99,16 @@ function session($http, $resource, $rootScope, annotationUI, auth,
return lastLoad; return lastLoad;
}; };
/**
* @name session.dismissSidebarTutorial()
*
* @description Stores the preference server-side that the user dismissed
* the sidebar tutorial, and then updates the session state.
*/
function dismissSidebarTutorial() {
return store.profile.update({}, {preferences: {show_sidebar_tutorial: false}}).then(update);
}
/** /**
* @name session.update() * @name session.update()
* *
...@@ -203,7 +208,7 @@ function session($http, $resource, $rootScope, annotationUI, auth, ...@@ -203,7 +208,7 @@ function session($http, $resource, $rootScope, annotationUI, auth,
} }
return { return {
dismissSidebarTutorial: resource.dismiss_sidebar_tutorial, dismissSidebarTutorial: dismissSidebarTutorial,
load: resource.load, load: resource.load,
login: resource.login, login: resource.login,
logout: logout, logout: logout,
......
...@@ -45,6 +45,7 @@ describe('session', function () { ...@@ -45,6 +45,7 @@ describe('session', function () {
fakeStore = { fakeStore = {
profile: { profile: {
read: sandbox.stub(), read: sandbox.stub(),
update: sandbox.stub().returns(Promise.resolve({})),
}, },
}; };
fakeSettings = { fakeSettings = {
...@@ -292,11 +293,21 @@ describe('session', function () { ...@@ -292,11 +293,21 @@ describe('session', function () {
}); });
describe('#dismissSidebarTutorial()', function () { describe('#dismissSidebarTutorial()', function () {
var url = 'https://test.hypothes.is/root/app/dismiss_sidebar_tutorial'; beforeEach(function () {
fakeStore.profile.update.returns(Promise.resolve({
preferences: {},
}));
});
it('disables the tutorial for the user', function () { it('disables the tutorial for the user', function () {
$httpBackend.expectPOST(url).respond({});
session.dismissSidebarTutorial(); session.dismissSidebarTutorial();
$httpBackend.flush(); assert.calledWith(fakeStore.profile.update, {}, {preferences: {show_sidebar_tutorial: false}});
});
it('should update the session with the response from the API', function () {
return session.dismissSidebarTutorial().then(function () {
assert.isNotOk(session.state.preferences.show_sidebar_tutorial);
});
}); });
}); });
......
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