diff --git a/__tests__/src/sagas/auth.test.js b/__tests__/src/sagas/auth.test.js index f4979f7bfce8b1cb54bab63ea5e9a0ef40202c73..5eebb7227e67b6cce104adeb2e09e5b634e6158a 100644 --- a/__tests__/src/sagas/auth.test.js +++ b/__tests__/src/sagas/auth.test.js @@ -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'; diff --git a/__tests__/src/sagas/iiif.test.js b/__tests__/src/sagas/iiif.test.js index c1dea0d21865d0a0f725bded7a001dc63045557d..6ca83b90a8991dc313e9b465b21566b4bcda0d08 100644 --- a/__tests__/src/sagas/iiif.test.js +++ b/__tests__/src/sagas/iiif.test.js @@ -1,11 +1,10 @@ -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' })); diff --git a/src/state/sagas/auth.js b/src/state/sagas/auth.js index 23fafe71772889f7297d48f64e0385c509c620ae..10f9c7fdace3194c55208e6d8700c5ad5b192b15 100644 --- a/src/state/sagas/auth.js +++ b/src/state/sagas/auth.js @@ -1,5 +1,5 @@ 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), ]); }