Commit 4c04077d authored by Robert Knight's avatar Robert Knight

Clear features cache only when logged in user changes

Clear the features cache only when the logged-in user changes,
rather than on any change to session data.
parent 7299b4d8
......@@ -33,10 +33,7 @@ function features ($document, $http, $log, $rootScope) {
var featuresUrl = new URL('/app/features', $document.prop('baseURI')).href;
var fetchOperation;
// FIXME - This should be changed to clear the feature flag cache
// only in response to the USER_CHANGED event once
// https://github.com/hypothesis/h/pull/2674 lands
$rootScope.$on(events.SESSION_CHANGED, function () {
$rootScope.$on(events.USER_CHANGED, function () {
cache = null;
});
......
"use strict";
'use strict';
var mock = angular.mock;
var events = require('../events');
describe('h:features', function () {
var $httpBackend;
var $rootScope;
var features;
var sandbox;
......@@ -26,6 +29,7 @@ describe('h:features', function () {
beforeEach(mock.inject(function ($injector) {
$httpBackend = $injector.get('$httpBackend');
$rootScope = $injector.get('$rootScope');
features = $injector.get('features');
}));
......@@ -122,5 +126,20 @@ describe('h:features', function () {
features.flagEnabled('foo');
$httpBackend.flush();
});
it('should clear the features data when the user changes', function () {
// fetch features and check that the flag is set
defaultHandler();
features.fetch();
$httpBackend.flush();
assert.isTrue(features.flagEnabled('foo'));
// simulate a change of logged-in user which should clear
// the features cache
$rootScope.$broadcast(events.USER_CHANGED, {});
defaultHandler();
assert.isFalse(features.flagEnabled('foo'));
$httpBackend.flush();
});
});
});
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