Skip to content

Commit

Permalink
chore(@aws-amplify/datastore): add tests for issue 7888
Browse files Browse the repository at this point in the history
  • Loading branch information
iartemiev committed Mar 14, 2021
1 parent 82206ec commit c201772
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions packages/datastore/__tests__/outbox.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,39 @@ describe('Outbox tests', () => {
expect(head).toBeFalsy();
});
});
// https://github.com/aws-amplify/amplify-js/issues/7888
it('Should retain the fields from the create mutation in the queue when it gets merged with an enqueued update mutation', async () => {
const field1 = 'Some value';
const currentTimestamp = new Date().toISOString();
const optionalField1 = 'Optional value';

const newModel = new Model({
field1,
dateCreated: currentTimestamp,
});

const mutationEvent = await createMutationEvent(newModel);
({ modelId } = mutationEvent);

await outbox.enqueue(Storage, mutationEvent);

const updatedModel = Model.copyOf(newModel, updated => {
updated.optionalField1 = optionalField1;
});

const updateMutationEvent = await createMutationEvent(updatedModel);

await outbox.enqueue(Storage, updateMutationEvent);

await Storage.runExclusive(async s => {
const head = await outbox.peek(s);
const headData = JSON.parse(head.data);

expect(headData.field1).toEqual(field1);
expect(headData.dateCreated).toEqual(currentTimestamp);
expect(headData.optionalField1).toEqual(optionalField1);
});
});
});

// performs all the required dependency injection
Expand Down

0 comments on commit c201772

Please sign in to comment.