130: tests for uuid index reducer

This commit is contained in:
Lotte Hofstede
2017-11-28 15:00:28 +01:00
parent 6592d76154
commit 553d1d6ffd
2 changed files with 59 additions and 69 deletions

View File

@@ -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);
// });
});