-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add reducers and actions for auth2 probe responses
- correct a spec name in accessTokens.test.js - stop refetching accessTokens if state has an ok true/false attribute - #3789
- Loading branch information
Showing
10 changed files
with
365 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { JSONLDResource } from 'manifesto.js'; | ||
import * as actions from '../../../src/state/actions'; | ||
import ActionTypes from '../../../src/state/actions/action-types'; | ||
|
||
describe('probeResponse actions', () => { | ||
describe('requestProbeResponse', () => { | ||
it('requests a probeResponse from given a url', () => { | ||
const id = 'abc123'; | ||
const expectedAction = { | ||
probeId: id, | ||
type: ActionTypes.REQUEST_PROBE_RESPONSE, | ||
}; | ||
expect(actions.requestProbeResponse(id)).toEqual(expectedAction); | ||
}); | ||
}); | ||
describe('receiveProbeResponse', () => { | ||
it('receives a probeResponse', () => { | ||
const id = 'abc123'; | ||
const json = { | ||
content: 'probe service request', | ||
id, | ||
}; | ||
const expectedAction = { | ||
probeId: id, | ||
probeJson: json, | ||
type: ActionTypes.RECEIVE_PROBE_RESPONSE, | ||
}; | ||
expect(actions.receiveProbeResponse(id, json)).toEqual(expectedAction); | ||
}); | ||
}); | ||
describe('fetchProbeResponse', () => { | ||
describe('success response', () => { | ||
it('dispatches the REQUEST_PROBE_RESPONSE action', () => { | ||
const resource = new JSONLDResource({ services: [{ id: 'someUrl', type: 'AuthProbeService2' }] }); | ||
expect(actions.fetchProbeResponse({ resource })).toEqual({ | ||
probeId: 'someUrl', | ||
resource, | ||
type: 'mirador/REQUEST_PROBE_RESPONSE', | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe('removeProbeResponse', () => { | ||
it('removes an existing probeResponse', () => { | ||
const expectedAction = { | ||
probeId: 'foo', | ||
type: ActionTypes.REMOVE_PROBE_RESPONSE, | ||
}; | ||
expect(actions.removeProbeResponse('foo')).toEqual(expectedAction); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { probeResponsesReducer } from '../../../src/state/reducers/probeResponses'; | ||
import ActionTypes from '../../../src/state/actions/action-types'; | ||
|
||
describe('probe response reducer', () => { | ||
it('should handle REQUEST_PROBE_RESPONSE', () => { | ||
expect(probeResponsesReducer({}, { | ||
probeId: 'abc123', | ||
type: ActionTypes.REQUEST_PROBE_RESPONSE, | ||
})).toEqual({ | ||
abc123: { | ||
id: 'abc123', | ||
isFetching: true, | ||
}, | ||
}); | ||
}); | ||
it('should handle RECEIVE_PROBE_RESPONSE', () => { | ||
expect(probeResponsesReducer( | ||
{ | ||
abc123: { | ||
id: 'abc123', | ||
isFetching: true, | ||
}, | ||
}, | ||
{ | ||
probeId: 'abc123', | ||
probeJson: { | ||
'@type': 'sc:Manifest', | ||
content: 'lots of canvases and metadata and such', | ||
id: 'abc123', | ||
}, | ||
tokenServiceId: 'efg456', | ||
type: ActionTypes.RECEIVE_PROBE_RESPONSE, | ||
}, | ||
)).toMatchObject({ | ||
abc123: { | ||
id: 'abc123', | ||
isFetching: false, | ||
json: {}, | ||
tokenServiceId: 'efg456', | ||
}, | ||
}); | ||
}); | ||
it('should handle RECEIVE_PROBE_RESPONSE_FAILURE', () => { | ||
expect(probeResponsesReducer( | ||
{ | ||
abc123: { | ||
id: 'abc123', | ||
isFetching: true, | ||
}, | ||
}, | ||
{ | ||
error: "This institution didn't enable CORS.", | ||
probeId: 'abc123', | ||
tokenServiceId: 'efg456', | ||
type: ActionTypes.RECEIVE_PROBE_RESPONSE_FAILURE, | ||
}, | ||
)).toEqual({ | ||
abc123: { | ||
error: "This institution didn't enable CORS.", | ||
id: 'abc123', | ||
isFetching: false, | ||
tokenServiceId: 'efg456', | ||
}, | ||
}); | ||
}); | ||
it('should handle REMOVE_PROBE_RESPONSE', () => { | ||
expect(probeResponsesReducer( | ||
{ | ||
abc123: { | ||
id: 'abc123', | ||
stuff: 'foo', | ||
}, | ||
def456: { | ||
id: 'def456', | ||
stuff: 'foo', | ||
}, | ||
}, | ||
{ | ||
probeId: 'abc123', | ||
type: ActionTypes.REMOVE_PROBE_RESPONSE, | ||
}, | ||
)).toEqual({ | ||
def456: { | ||
id: 'def456', | ||
stuff: 'foo', | ||
}, | ||
}); | ||
}); | ||
it('should handle IMPORT_MIRADOR_STATE setting to clean state', () => { | ||
expect(probeResponsesReducer({}, { | ||
state: { probeResponses: { new: 'stuff' } }, | ||
type: ActionTypes.IMPORT_MIRADOR_STATE, | ||
})).toEqual({}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import ActionTypes from './action-types'; | ||
import { getProbeService } from '../../lib/getServices'; | ||
|
||
/** | ||
* requestProbeResponse - action creator | ||
* | ||
* @param {String} infoId | ||
* @memberof ActionCreators | ||
*/ | ||
export function requestProbeResponse(probeId, resource, windowId) { | ||
return { | ||
probeId, | ||
resource, | ||
type: ActionTypes.REQUEST_PROBE_RESPONSE, | ||
windowId, | ||
}; | ||
} | ||
|
||
/** | ||
* receiveProbeResponse - action creator | ||
* | ||
* @param {String} infoId | ||
* @param {Object} manifestJson | ||
* @memberof ActionCreators | ||
*/ | ||
export function receiveProbeResponse(probeId, probeJson, ok, tokenServiceId) { | ||
return { | ||
ok, | ||
probeId, | ||
probeJson, | ||
tokenServiceId, | ||
type: ActionTypes.RECEIVE_PROBE_RESPONSE, | ||
}; | ||
} | ||
|
||
/** | ||
* receiveDegradedProbeResponse - action creator | ||
* | ||
* @param {String} infoId | ||
* @param {Object} manifestJson | ||
* @memberof ActionCreators | ||
*/ | ||
export function receiveDegradedProbeResponse(probeId, probeJson, ok, tokenServiceId, windowId) { | ||
return { | ||
ok, | ||
probeId, | ||
probeJson, | ||
tokenServiceId, | ||
type: ActionTypes.RECEIVE_DEGRADED_PROBE_RESPONSE, | ||
windowId, | ||
}; | ||
} | ||
|
||
/** | ||
* receiveProbeResponseFailure - action creator | ||
* | ||
* @param {String} infoId | ||
* @param {String} error | ||
* @memberof ActionCreators | ||
*/ | ||
export function receiveProbeResponseFailure(probeId, error, tokenServiceId) { | ||
return { | ||
error, | ||
probeId, | ||
tokenServiceId, | ||
type: ActionTypes.RECEIVE_PROBE_RESPONSE_FAILURE, | ||
}; | ||
} | ||
|
||
/** | ||
* fetchProbeResponse - action creator | ||
* | ||
* @param {String} infoId | ||
* @memberof ActionCreators | ||
*/ | ||
export function fetchProbeResponse({ resource, resourceId, windowId }) { | ||
const probeService = resource && getProbeService(resource); | ||
const probeId = (resourceId || probeService.id); | ||
return requestProbeResponse(probeId, resource, windowId); | ||
} | ||
|
||
/** | ||
* removeProbeResponse - action creator | ||
* | ||
* @param {String} probeId | ||
* @memberof ActionCreators | ||
*/ | ||
export function removeProbeResponse(probeId) { | ||
return { probeId, type: ActionTypes.REMOVE_PROBE_RESPONSE }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.