From c20177243eed22b58bf5b547ee08f15592d2fd33 Mon Sep 17 00:00:00 2001 From: Ivan Artemiev <29709626+iartemiev@users.noreply.github.com> Date: Sun, 14 Mar 2021 09:46:09 -0500 Subject: [PATCH] chore(@aws-amplify/datastore): add tests for issue 7888 --- packages/datastore/__tests__/outbox.test.ts | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/packages/datastore/__tests__/outbox.test.ts b/packages/datastore/__tests__/outbox.test.ts index 06f21f7f1f5..ab973cd90da 100644 --- a/packages/datastore/__tests__/outbox.test.ts +++ b/packages/datastore/__tests__/outbox.test.ts @@ -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