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) {
},
_load: { method: 'GET' },
dismiss_sidebar_tutorial: {
method: 'POST',
params: { path: 'dismiss_sidebar_tutorial' },
},
};
Object.keys(actions).forEach(function (action) {
......@@ -104,6 +99,16 @@ function session($http, $resource, $rootScope, annotationUI, auth,
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()
*
......@@ -203,7 +208,7 @@ function session($http, $resource, $rootScope, annotationUI, auth,
}
return {
dismissSidebarTutorial: resource.dismiss_sidebar_tutorial,
dismissSidebarTutorial: dismissSidebarTutorial,
load: resource.load,
login: resource.login,
logout: logout,
......
......@@ -45,6 +45,7 @@ describe('session', function () {
fakeStore = {
profile: {
read: sandbox.stub(),
update: sandbox.stub().returns(Promise.resolve({})),
},
};
fakeSettings = {
......@@ -292,11 +293,21 @@ describe('session', 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 () {
$httpBackend.expectPOST(url).respond({});
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