Skip to content

Commit

Permalink
fix(core): undefined operation entity from operationFailed (#2897)
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 authored Jul 5, 2024
1 parent 265d54a commit db8afb6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
10 changes: 10 additions & 0 deletions libs/core/state/src/operation/entity/adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,16 @@ describe('@daffodil/core/state | daffCreateOperationEntityStateAdapter', () => {
result = adapter.operationFailed(entity.id, errors, adapter.list(entities, state));
});

describe('when the entity does not exist in state', () => {
beforeEach(() => {
result = adapter.operationFailed(`not ${entity.id}`, errors, adapter.list(entities, state));
});

it('should not touch state', () => {
expect(result.entities[`not ${entity.id}`]).toBeUndefined();
});
});

it('should indicate that the entity is in an error state', () => {
expect(result.entities[entity.id].daffState).toEqual(DaffState.Error);
});
Expand Down
4 changes: 2 additions & 2 deletions libs/core/state/src/operation/entity/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,11 @@ export class DaffOperationEntityStateAdapter<T extends DaffIdentifiable = DaffId
}

operationFailed<S extends DaffOperationEntityState<T> = DaffOperationEntityState<T>>(key: string, errors: DaffStateError[], state: S): S {
return this.adapter.upsertOne({
return state.entities[key] ? this.adapter.upsertOne({
...state.entities[key],
daffState: DaffState.Error,
daffErrors: errors,
}, state);
}, state) : state;
}

resetState<S extends DaffOperationEntityState<T> = DaffOperationEntityState<T>>(key: string, state: S): S {
Expand Down

0 comments on commit db8afb6

Please sign in to comment.