Skip to content

Commit

Permalink
fix(core): subsequent preadds don't update entity after initial preadd (
Browse files Browse the repository at this point in the history
  • Loading branch information
griest024 committed Dec 7, 2023
1 parent 6ff51a6 commit 92e06bb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions libs/core/state/src/operation/entity/adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,25 @@ describe('@daffodil/core/state | daffCreateOperationEntityStateAdapter', () => {
expect(result.entities[placeholderId].daffState).toEqual(DaffState.Adding);
expect(result.entities[placeholderId].daffTemp).toBeTrue();
});

describe('when the operation fails and another preadd is initiated', () => {
let errors: DaffStateError[];

beforeEach(() => {
errors = [
{ code: 'code', message: 'message' },
];
result = adapter.preadd(entity, adapter.operationFailed(placeholderId, errors, result), placeholderId);
});

it('should reset errors', () => {
expect(result.entities[placeholderId].daffErrors).toEqual([]);
});

it('should change state to adding', () => {
expect(result.entities[placeholderId].daffState).toEqual(DaffState.Adding);
});
});
});

describe('add', () => {
Expand Down
2 changes: 1 addition & 1 deletion libs/core/state/src/operation/entity/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ export function daffCreateOperationEntityStateAdapter<T extends DaffIdentifiable
}, state),
preadd: (entity, state, placeholderId) =>
placeholderId
? adapter.addOne({
? adapter.upsertOne({
...entity,
// TODO: allow for non identifiable entities?
id: placeholderId,
Expand Down

0 comments on commit 92e06bb

Please sign in to comment.