Commit f55b5ae9 authored by Hannah Stepanek's avatar Hannah Stepanek

Use token instead of store to calc isLoggedIn

parent 39d3406b
......@@ -27,6 +27,7 @@ function groups(
serviceUrl,
session,
settings,
auth,
features
) {
const svc = serviceConfig(settings);
......@@ -158,17 +159,23 @@ function groups(
};
const profileGroupsApi = api.profile.groups.read(profileParams);
const listGroupsApi = api.groups.list(params);
return Promise.all([profileGroupsApi, listGroupsApi]).then(
([myGroups, featuredGroups]) =>
combineGroups(myGroups, featuredGroups)
);
return Promise.all([
profileGroupsApi,
listGroupsApi,
auth.tokenGetter(),
]).then(([myGroups, featuredGroups, token]) => [
combineGroups(myGroups, featuredGroups),
token,
]);
} else {
// Fetch groups from the API.
return api.groups.list(params);
return api.groups
.list(params, null, { includeMetadata: true })
.then(({ data, token }) => [data, token]);
}
})
.then(groups => {
const isLoggedIn = store.profile().userid !== null;
.then(([groups, token]) => {
const isLoggedIn = token !== null;
const directLinkedAnnotation = settings.annotations;
return filterGroups(groups, isLoggedIn, directLinkedAnnotation);
})
......
......@@ -36,6 +36,7 @@ const dummyGroups = [
];
describe('groups', function() {
let fakeAuth;
let fakeFeatures;
let fakeStore;
let fakeIsSidebar;
......@@ -48,6 +49,9 @@ describe('groups', function() {
let sandbox;
beforeEach(function() {
fakeAuth = {
tokenGetter: sinon.stub().returns('1234'),
};
fakeFeatures = {
flagEnabled: sinon.stub().returns(false),
};
......@@ -58,7 +62,6 @@ describe('groups', function() {
searchUris: ['http://example.org'],
focusedGroup: null,
groups: [],
profile: sinon.stub().returns({ userid: 'userid' }),
},
{
focusGroup: sinon.stub(),
......@@ -79,9 +82,6 @@ describe('groups', function() {
},
}
);
fakeStore.profile = () => {
return { userid: 'userid' };
};
fakeSession = sessionWithThreeGroups();
fakeIsSidebar = true;
fakeLocalStorage = {
......@@ -114,7 +114,12 @@ describe('groups', function() {
},
},
groups: {
list: sandbox.stub().returns(Promise.resolve(dummyGroups)),
list: sandbox.stub().returns(
Promise.resolve({
data: dummyGroups,
token: '1234',
})
),
},
profile: {
groups: {
......@@ -140,6 +145,7 @@ describe('groups', function() {
fakeServiceUrl,
fakeSession,
fakeSettings,
fakeAuth,
fakeFeatures
);
}
......@@ -189,6 +195,9 @@ describe('groups', function() {
it('sends `expand` parameter when community-groups feature flag is enabled', function() {
const svc = service();
fakeApi.groups.list.returns(
Promise.resolve([{ id: 'groupa', name: 'GroupA' }])
);
fakeFeatures.flagEnabled.withArgs('community_groups').returns(true);
return svc.load().then(() => {
......@@ -268,7 +277,12 @@ describe('groups', function() {
it('injects a defalt organization if group is missing an organization', function() {
const svc = service();
const groups = [{ id: '39r39f', name: 'Ding Dong!' }];
fakeApi.groups.list.returns(Promise.resolve(groups));
fakeApi.groups.list.returns(
Promise.resolve({
token: '1234',
data: groups,
})
);
return svc.load().then(groups => {
assert.isObject(groups[0].organization);
assert.hasAllKeys(groups[0].organization, ['id', 'logo']);
......@@ -303,10 +317,12 @@ describe('groups', function() {
groups.push({ name: 'BioPub', id: 'biopub' });
}
fakeStore.profile = () => {
return { userid: loggedIn ? 'userid' : null };
};
fakeApi.groups.list.returns(Promise.resolve(groups));
fakeApi.groups.list.returns(
Promise.resolve({
token: loggedIn ? '1234' : null,
data: groups,
})
);
return svc.load().then(groups => {
const publicGroupShown = groups.some(g => g.id === '__world__');
......@@ -359,7 +375,12 @@ describe('groups', function() {
{ name: 'DEF', id: 'def456', groupid: null },
];
fakeApi.groups.list.returns(Promise.resolve(groups));
fakeApi.groups.list.returns(
Promise.resolve({
token: '1234',
data: groups,
})
);
return svc.load().then(groups => {
let displayedGroups = groups.map(g => g.id);
......
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