Skip to content
Snippets Groups Projects
Commit 1c238425 authored by Chris Beer's avatar Chris Beer
Browse files

Re-fetch info.json documents after logging out

parent ae4c0baa
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@ import serviceFixture from '../../fixtures/version-2/canvasService.json';
import ActionTypes from '../../../src/state/actions/action-types';
import {
refetchInfoResponses,
refetchInfoResponsesOnLogout,
} from '../../../src/state/sagas/auth';
import {
fetchInfoResponse,
......@@ -17,6 +18,21 @@ import {
} from '../../../src/state/selectors';
describe('IIIF Authentication sagas', () => {
describe('refetchInfoResponsesOnLogout', () => {
it('delays and then refetches info responses', () => {
const tokenServiceId = 'whatever';
/** stub out delay... ugh. */
const provideDelay = ({ fn }, next) => ((fn.name === 'delayP') ? null : next());
return expectSaga(refetchInfoResponsesOnLogout, { tokenServiceId })
.provide([
{ call: provideDelay },
[call(refetchInfoResponses, { serviceId: tokenServiceId }), {}],
])
.call(refetchInfoResponses, { serviceId: tokenServiceId })
.run();
});
});
describe('refetchInfoResponses', () => {
it('discards info responses that could hvae used the new access token', () => {
const serviceId = 'https://authentication.example.org/token';
......
import { call, select } from 'redux-saga/effects';
import { expectSaga, testSaga } from 'redux-saga-test-plan';
import { select } from 'redux-saga/effects';
import { expectSaga } from 'redux-saga-test-plan';
import {
fetchAnnotation,
fetchManifest,
fetchSearchResponse,
fetchInfoResponse,
refetchInfoResponses,
fetchResourceManifest,
} from '../../../src/state/sagas/iiif';
import {
......@@ -217,24 +216,6 @@ describe('IIIF sagas', () => {
});
});
describe('refetchInfoResponses', () => {
it('refetches info responses when a new access token is available', () => {
const serviceId = 'serviceId';
const tokenService = { id: serviceId, infoIds: ['x', 'y'] };
testSaga(refetchInfoResponses, { serviceId })
.next()
.select(getAccessTokens)
.next({ serviceId: tokenService })
.all([
call(fetchInfoResponse, { infoId: 'x', tokenService }),
call(fetchInfoResponse, { infoId: 'y', tokenService }),
])
.next()
.put({ serviceId, type: 'mirador/CLEAR_ACCESS_TOKEN_QUEUE' });
});
});
describe('fetchSearchResponse', () => {
it('fetches a IIIF search', () => {
fetch.mockResponseOnce(JSON.stringify({ data: '12345' }));
......
import {
all, call, put, select, takeEvery,
all, call, put, select, takeEvery, delay,
} from 'redux-saga/effects';
import { Utils } from 'manifesto.js/dist-esmodule/Utils';
import flatten from 'lodash/flatten';
......@@ -12,6 +12,15 @@ import {
} from '../selectors';
import { fetchInfoResponse } from './iiif';
/** */
export function* refetchInfoResponsesOnLogout({ tokenServiceId }) {
// delay logout actions to give the cookie service a chance to invalidate our cookies
// before we reinitialize openseadragon and rerequest images.
yield delay(2000);
yield call(refetchInfoResponses, { serviceId: tokenServiceId });
}
/**
* Figure out what info responses could have used the access token service and:
* - refetch, if they are currently visible
......@@ -55,5 +64,6 @@ export function* refetchInfoResponses({ serviceId }) {
export default function* authSaga() {
yield all([
takeEvery(ActionTypes.RECEIVE_ACCESS_TOKEN, refetchInfoResponses),
takeEvery(ActionTypes.RESET_AUTHENTICATION_STATE, refetchInfoResponsesOnLogout),
]);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment