Create the test entityCacheMetaReducer, injected in tests
( collectionCreator: EntityCollectionCreator )
| 221 | |
| 222 | /** Create the test entityCacheMetaReducer, injected in tests */ |
| 223 | function entityCacheMetaReducerFactory( |
| 224 | collectionCreator: EntityCollectionCreator |
| 225 | ) { |
| 226 | return (reducer: ActionReducer<EntityCache, Action>) => { |
| 227 | return (state: EntityCache, action: { type: string; payload?: any }) => { |
| 228 | switch (action.type) { |
| 229 | case TEST_ACTION: { |
| 230 | const mergeState = { |
| 231 | Hero: createCollection<Hero>('Hero', action.payload['Hero'] || []), |
| 232 | Villain: createCollection<Villain>( |
| 233 | 'Villain', |
| 234 | action.payload['Villain'] || [] |
| 235 | ), |
| 236 | }; |
| 237 | return { ...state, ...mergeState }; |
| 238 | } |
| 239 | } |
| 240 | return reducer(state, action); |
| 241 | }; |
| 242 | }; |
| 243 | |
| 244 | function createCollection<T extends { id: any }>( |
| 245 | entityName: string, |
| 246 | data: T[] |
| 247 | ) { |
| 248 | return { |
| 249 | ...collectionCreator.create<T>(entityName), |
| 250 | ids: data.map((e) => e.id), |
| 251 | entities: data.reduce((acc, e) => { |
| 252 | acc[e.id] = e; |
| 253 | return acc; |
| 254 | }, {} as any), |
| 255 | } as EntityCollection<T>; |
| 256 | } |
| 257 | } |
| 258 | // #endregion |
nothing calls this directly
no test coverage detected