Skip to content
Snippets Groups Projects
Commit 553d1d6f authored by Lotte Hofstede's avatar Lotte Hofstede
Browse files

130: tests for uuid index reducer

parent 6592d761
Branches
Tags
No related merge requests found
......@@ -35,14 +35,14 @@ describe('requestReducer', () => {
expect(newState).toEqual(testState);
});
it('should start with an empty cache', () => {
it('should start with an empty state', () => {
const action = new NullAction();
const initialState = requestReducer(undefined, action);
expect(initialState).toEqual(Object.create(null));
});
it('should add the new RestRequest and set \'requestPending\' to true, \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to an CONFIGURE action', () => {
it('should add the new RestRequest and set \'requestPending\' to true, \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to a CONFIGURE action', () => {
const state = testState;
const request = new RestRequest(link2);
......@@ -66,7 +66,7 @@ describe('requestReducer', () => {
expect(newState[link1].responsePending).toEqual(true);
expect(newState[link1].completed).toEqual(state[link1].completed);
});
it('should leave \'requestPending\' untouched, set \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to an COMPLETE action', () => {
it('should leave \'requestPending\' untouched, set \'responsePending\' to false and \'completed\' to false for the given RestRequest in the state, in response to a COMPLETE action', () => {
const state = testState;
const action = new RequestCompleteAction(link1);
......@@ -77,70 +77,4 @@ describe('requestReducer', () => {
expect(newState[link1].responsePending).toEqual(false);
expect(newState[link1].completed).toEqual(true);
});
//
// it('should overwrite an object in the cache in response to an ADD action if it already exists', () => {
// const objectToCache = { self: selfLink1, foo: 'baz', somethingElse: true };
// const timeAdded = new Date().getTime();
// const msToLive = 900000;
// const requestHref = 'https://rest.api/endpoint/selfLink1';
// const action = new AddToObjectCacheAction(objectToCache, timeAdded, msToLive, requestHref);
// const newState = requestReducer(testState, action);
//
// /* tslint:disable:no-string-literal */
// expect(newState[selfLink1].data['foo']).toBe('baz');
// expect(newState[selfLink1].data['somethingElse']).toBe(true);
// /* tslint:enable:no-string-literal */
// });
//
// it('should perform the ADD action without affecting the previous state', () => {
// const state = Object.create(null);
// const objectToCache = { self: selfLink1 };
// const timeAdded = new Date().getTime();
// const msToLive = 900000;
// const requestHref = 'https://rest.api/endpoint/selfLink1';
// const action = new AddToObjectCacheAction(objectToCache, timeAdded, msToLive, requestHref);
// deepFreeze(state);
//
// requestReducer(state, action);
// });
//
// it('should remove the specified object from the cache in response to the REMOVE action', () => {
// const action = new RemoveFromObjectCacheAction(selfLink1);
// const newState = requestReducer(testState, action);
//
// expect(testState[selfLink1]).not.toBeUndefined();
// expect(newState[selfLink1]).toBeUndefined();
// });
//
// it("shouldn't do anything in response to the REMOVE action for an object that isn't cached", () => {
// const wrongKey = "this isn't cached";
// const action = new RemoveFromObjectCacheAction(wrongKey);
// const newState = requestReducer(testState, action);
//
// expect(testState[wrongKey]).toBeUndefined();
// expect(newState).toEqual(testState);
// });
//
// it('should perform the REMOVE action without affecting the previous state', () => {
// const action = new RemoveFromObjectCacheAction(selfLink1);
// // testState has already been frozen above
// requestReducer(testState, action);
// });
//
// it('should set the timestamp of all objects in the cache in response to a RESET_TIMESTAMPS action', () => {
// const newTimestamp = new Date().getTime();
// const action = new ResetObjectCacheTimestampsAction(newTimestamp);
// const newState = requestReducer(testState, action);
// Object.keys(newState).forEach((key) => {
// expect(newState[key].timeAdded).toEqual(newTimestamp);
// });
// });
//
// it('should perform the RESET_TIMESTAMPS action without affecting the previous state', () => {
// const action = new ResetObjectCacheTimestampsAction(new Date().getTime());
// // testState has already been frozen above
// requestReducer(testState, action);
// });
});
import * as deepFreeze from 'deep-freeze';
import { uuidIndexReducer, UUIDIndexState } from './uuid-index.reducer';
import { AddToUUIDIndexAction, RemoveHrefFromUUIDIndexAction } from './uuid-index.actions';
class NullAction extends AddToUUIDIndexAction {
type = null;
payload = null;
constructor() {
super(null, null);
}
}
describe('requestReducer', () => {
const link1 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/567a639f-f5ff-4126-807c-b7d0910808c8';
const link2 = 'https://dspace7.4science.it/dspace-spring-rest/api/core/items/1911e8a4-6939-490c-b58b-a5d70f8d91fb';
const uuid1 = '567a639f-f5ff-4126-807c-b7d0910808c8';
const uuid2 = '1911e8a4-6939-490c-b58b-a5d70f8d91fb';
const testState: UUIDIndexState = {
[uuid1]: link1
};
deepFreeze(testState);
it('should return the current state when no valid actions have been made', () => {
const action = new NullAction();
const newState = uuidIndexReducer(testState, action);
expect(newState).toEqual(testState);
});
it('should start with an empty state', () => {
const action = new NullAction();
const initialState = uuidIndexReducer(undefined, action);
expect(initialState).toEqual(Object.create(null));
});
it('should add the \'uuid\' with the corresponding \'href\' to the state, in response to an ADD action', () => {
const state = testState;
const action = new AddToUUIDIndexAction(uuid2, link2);
const newState = uuidIndexReducer(state, action);
expect(newState[uuid2]).toEqual(link2);
});
it('should remove the given \'href\' from it\'s corresponding \'uuid\' in the state, in response to a REMOVE_HREF action', () => {
const state = testState;
const action = new RemoveHrefFromUUIDIndexAction(link1);
const newState = uuidIndexReducer(state, action);
expect(newState[uuid1]).toBeUndefined();
});
});
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