Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

Commit

Permalink
fix: return the newly create meta field from bundle processer (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
rsmayda committed Apr 14, 2021
1 parent ef12af7 commit a2b5206
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 41 deletions.
24 changes: 19 additions & 5 deletions src/dataServices/dynamoDbBundleService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ describe('atomicallyReadWriteResources', () => {
Update: {
TableName: '',
Key: {
id: { S: 'bce8411e-c15e-448c-95dd-69155a837405' },
id: { S: id },
vid: { N: '1' },
},
UpdateExpression: 'set documentStatus = :newStatus, lockEndTs = :futureEndTs',
Expand All @@ -235,17 +235,24 @@ describe('atomicallyReadWriteResources', () => {
},
],
});

expect(actualResponse).toStrictEqual({
message: 'Successfully committed requests to DB',
batchReadWriteResponses: [
{
id: 'bce8411e-c15e-448c-95dd-69155a837405',
id,
vid: '1',
operation: 'create',
lastModified: expect.stringMatching(utcTimeRegExp),
resourceType: 'Patient',
resource: {},
resource: {
...resource,
id,
meta: {
lastUpdated: expect.stringMatching(utcTimeRegExp),
versionId: '1',
security: 'gondor',
},
},
},
],
success: true,
Expand Down Expand Up @@ -421,7 +428,14 @@ describe('atomicallyReadWriteResources', () => {
operation: 'update',
lastModified: expect.stringMatching(utcTimeRegExp),
resourceType,
resource: {},
resource: {
...newResource,
meta: {
versionId: newVid.toString(),
lastUpdated: expect.stringMatching(utcTimeRegExp),
security: 'skynet',
},
},
},
],
success: true,
Expand Down
47 changes: 18 additions & 29 deletions src/dataServices/dynamoDbBundleServiceHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ export default class DynamoDbBundleServiceHelper {
Item: DynamoDBConverter.marshall(Item),
},
});
const { stagingResponse, itemLocked } = this.addStagingResponseAndItemsLocked(
const { stagingResponse, itemLocked } = this.addStagingResponseAndItemsLocked(request.operation, {
...request.resource,
meta: { ...Item.meta },
id,
vid,
request.resourceType,
request.operation,
Item.meta.lastUpdated,
);
});
newBundleEntryResponses = newBundleEntryResponses.concat(stagingResponse);
newLocks = newLocks.concat(itemLocked);
break;
Expand All @@ -75,13 +73,10 @@ export default class DynamoDbBundleServiceHelper {
},
});

const { stagingResponse, itemLocked } = this.addStagingResponseAndItemsLocked(
id,
vid,
request.resourceType,
request.operation,
Item.meta.lastUpdated,
);
const { stagingResponse, itemLocked } = this.addStagingResponseAndItemsLocked(request.operation, {
...request.resource,
meta: { ...Item.meta },
});
newBundleEntryResponses = newBundleEntryResponses.concat(stagingResponse);
newLocks = newLocks.concat(itemLocked);
break;
Expand Down Expand Up @@ -216,25 +211,19 @@ export default class DynamoDbBundleServiceHelper {
return updatedStagingResponses;
}

private static addStagingResponseAndItemsLocked(
id: string,
vid: number,
resourceType: string,
operation: TypeOperation,
lastModified: string,
) {
const stagingResponse = {
id,
vid: vid.toString(),
private static addStagingResponseAndItemsLocked(operation: TypeOperation, resource: any) {
const stagingResponse: BatchReadWriteResponse = {
id: resource.id,
vid: resource.meta.versionId,
operation,
lastModified,
resourceType,
resource: {},
lastModified: resource.meta.lastUpdated,
resourceType: resource.resourceType,
resource,
};
const itemLocked: ItemRequest = {
id,
vid,
resourceType,
id: resource.id,
vid: parseInt(resource.meta.versionId, 10),
resourceType: resource.resourceType,
operation,
};
if (operation === 'update') {
Expand Down
28 changes: 21 additions & 7 deletions testUtilities/GenerateStagingRequestsFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ export default class GenerateStagingRequestsFactory {
vid: '1',
operation: 'create',
resourceType: 'Patient',
resource: {},
resource: {
...createResource,
id: expect.stringMatching(uuidRegExp),
meta: { versionId: '1', lastUpdated: expect.stringMatching(utcTimeRegExp) },
},
lastModified: expect.stringMatching(utcTimeRegExp),
};
return {
Expand Down Expand Up @@ -124,6 +128,9 @@ export default class GenerateStagingRequestsFactory {

static getUpdate(): RequestResult {
const id = '8cafa46d-08b4-4ee4-b51b-803e20ae8126';
const vid = 1;
const nextVid = 2;
const existingMeta = { security: [{ code: 'test' }], versionId: vid.toString() };
const resource = {
resourceType: 'Patient',
id,
Expand All @@ -134,6 +141,7 @@ export default class GenerateStagingRequestsFactory {
},
],
gender: 'male',
meta: existingMeta,
};
const request: BatchReadWriteRequest = {
operation: 'update',
Expand All @@ -142,9 +150,8 @@ export default class GenerateStagingRequestsFactory {
resource,
fullUrl: `urn:uuid:${id}`,
};
const vid = 1;
const nextVid = 2;
const expectedUpdateItem: any = { ...resource };

const expectedUpdateItem: any = { ...resource, meta: { ...existingMeta, versionId: nextVid.toString() } };
expectedUpdateItem[DOCUMENT_STATUS_FIELD] = DOCUMENT_STATUS.PENDING;
expectedUpdateItem.id = id;
expectedUpdateItem.vid = nextVid;
Expand All @@ -157,19 +164,26 @@ export default class GenerateStagingRequestsFactory {
};

const expectedLock: ItemRequest = {
id: expect.stringMatching(uuidRegExp),
id,
vid: nextVid,
resourceType: 'Patient',
operation: 'update',
isOriginalUpdateItem: false,
};

const expectedStagingResponse: BatchReadWriteResponse = {
id: expect.stringMatching(uuidRegExp),
id,
vid: nextVid.toString(),
operation: 'update',
resourceType: 'Patient',
resource: {},
resource: {
...resource,
meta: {
...existingMeta,
versionId: nextVid.toString(),
lastUpdated: expect.stringMatching(utcTimeRegExp),
},
},
lastModified: expect.stringMatching(utcTimeRegExp),
};

Expand Down

0 comments on commit a2b5206

Please sign in to comment.