From 705309cbf57216df45df84d4f6f265d7d8035a61 Mon Sep 17 00:00:00 2001 From: Brad Banister Date: Sat, 28 Oct 2023 10:37:36 -0500 Subject: [PATCH] simplify identity structure --- .../test/integration/Delete.test.ts | 27 +++-- .../integration/OwnershipSecurity.test.ts | 5 +- .../test/integration/Read.test.ts | 9 +- .../integration/SecurityMiddleware.test.ts | 5 +- .../test/integration/Update.test.ts | 55 +++++------ .../test/integration/Upsert.test.ts | 85 +++++++--------- .../test/integration/locking/Delete.test.ts | 11 +-- .../test/model/MeadowlarkDocument.test.ts | 16 ++- .../test/integration/Delete.test.ts | 27 +++-- .../integration/OwnershipSecurity.test.ts | 5 +- .../test/integration/Read.test.ts | 5 +- .../integration/SecurityMiddleware.test.ts | 5 +- .../test/integration/Update.test.ts | 59 +++++------ .../test/integration/Upsert.test.ts | 67 ++++++------- .../test/integration/locking/Delete.test.ts | 11 +-- .../extraction/DescriptorValueExtractor.ts | 3 +- .../extraction/DocumentIdentityExtractor.ts | 2 +- .../extraction/DocumentReferenceExtractor.ts | 6 +- .../src/model/DescriptorDocumentInfo.ts | 5 +- .../src/model/DocumentIdentity.ts | 23 +++-- .../SchoolYearEnumerationDocumentInfo.ts | 9 +- .../DescriptorValueExtractor.test.ts | 30 ++---- .../DocumentIdentityExtractor.test.ts | 30 ++---- .../DocumentReferenceExtractor.test.ts | 99 +++++++------------ .../test/handler/FrontendRequest.test.ts | 11 +-- .../validation/DocumentIdValidator.test.ts | 5 +- 26 files changed, 254 insertions(+), 361 deletions(-) diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Delete.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Delete.test.ts index 3ecad54e..74f21e19 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Delete.test.ts @@ -22,7 +22,6 @@ import { TraceId, UpsertResult, MetaEdResourceName, - DocumentObjectKey, MetaEdProjectName, } from '@edfi/meadowlark-core'; import { Collection, MongoClient } from 'mongodb'; @@ -91,7 +90,7 @@ describe('given the delete of an existing document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete2' }], + documentIdentity: [{ natural: 'delete2' }], }; beforeAll(async () => { @@ -143,7 +142,7 @@ describe('given the delete of a document referenced by an existing document with const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete5' }], + documentIdentity: [{ natural: 'delete5' }], }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -163,7 +162,7 @@ describe('given the delete of a document referenced by an existing document with }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete6' }], + documentIdentity: [{ natural: 'delete6' }], documentReferences: [validReference], }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -221,8 +220,7 @@ describe('given the delete of a document referenced by an existing document with it('should still have the referenced document in the db', async () => { const collection: Collection = getDocumentCollection(client); const result: any = await collection.findOne({ _id: referencedMeadowlarkId }); - expect(result.documentIdentity[0].documentKey).toBe('natural'); - expect(result.documentIdentity[0].documentValue).toBe('delete5'); + expect(result.documentIdentity[0].natural).toBe('delete5'); }); }); @@ -238,7 +236,7 @@ describe('given an delete of a document with an outbound reference only, with va const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete15' }], + documentIdentity: [{ natural: 'delete15' }], }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -258,7 +256,7 @@ describe('given an delete of a document with an outbound reference only, with va }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete16' }], + documentIdentity: [{ natural: 'delete16' }], documentReferences: [validReference], }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -331,7 +329,7 @@ describe('given the delete of a document referenced by an existing document with }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete5' }], + documentIdentity: [{ natural: 'delete5' }], }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -351,7 +349,7 @@ describe('given the delete of a document referenced by an existing document with }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete6' }], + documentIdentity: [{ natural: 'delete6' }], documentReferences: [validReference], }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -426,14 +424,14 @@ describe('given the delete of a subclass document referenced by an existing docu const superclassInfo: SuperclassInfo = { ...newSuperclassInfo(), - documentIdentity: [{ documentKey: 'educationOrganizationId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ educationOrganizationId: '123' }], resourceName: 'EducationOrganization' as MetaEdResourceName, projectName: 'Ed-Fi' as MetaEdProjectName, }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], superclassInfo, }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -454,7 +452,7 @@ describe('given the delete of a subclass document referenced by an existing docu }; const documentWithReferenceDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'delete6' }], + documentIdentity: [{ week: 'delete6' }], documentReferences: [referenceAsSuperclass], }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -512,7 +510,6 @@ describe('given the delete of a subclass document referenced by an existing docu it('should still have the referenced document in the db', async () => { const collection: Collection = getDocumentCollection(client); const result: any = await collection.findOne({ _id: referencedMeadowlarkId }); - expect(result.documentIdentity[0].documentKey).toBe('schoolId'); - expect(result.documentIdentity[0].documentValue).toBe('123'); + expect(result.documentIdentity[0].schoolId).toBe('123'); }); }); diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/OwnershipSecurity.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/OwnershipSecurity.test.ts index e24e110e..428279ba 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/OwnershipSecurity.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/OwnershipSecurity.test.ts @@ -20,7 +20,6 @@ import { newFrontendRequestMiddleware, newPathComponents, MetaEdResourceName, - DocumentObjectKey, } from '@edfi/meadowlark-core'; import { MongoClient } from 'mongodb'; import { getDocumentCollection, getNewClient } from '../../src/repository/Db'; @@ -141,7 +140,7 @@ describe('given the getById of a document owned by the requestor', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -201,7 +200,7 @@ describe('given the getById of a document not owned by the requestor', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); const upsertRequest: UpsertRequest = { diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Read.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Read.test.ts index ad9ef04a..6af684ca 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Read.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Read.test.ts @@ -19,7 +19,6 @@ import { DocumentUuid, UpdateRequest, MetaEdResourceName, - DocumentObjectKey, } from '@edfi/meadowlark-core'; import { Collection, MongoClient } from 'mongodb'; import { MeadowlarkDocument } from '../../src/model/MeadowlarkDocument'; @@ -67,7 +66,7 @@ describe('given the get of a non-existent document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get1' }], + documentIdentity: [{ natural: 'get1' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -105,7 +104,7 @@ describe('given the get of an existing document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], requestTimestamp: 1683326572053, }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -157,13 +156,13 @@ describe('given the get of an updated document', () => { }; const documentInfo1: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'getUpdatedDocument' }], + documentIdentity: [{ natural: 'getUpdatedDocument' }], requestTimestamp: 1683326572053, }; const documentInfo2: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'getUpdatedDocument' }], + documentIdentity: [{ natural: 'getUpdatedDocument' }], requestTimestamp: 1683548337342, }; diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/SecurityMiddleware.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/SecurityMiddleware.test.ts index 07ba7e69..42e4eb6b 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/SecurityMiddleware.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/SecurityMiddleware.test.ts @@ -19,7 +19,6 @@ import { UpsertResult, newFrontendRequestMiddleware, newPathComponents, - DocumentObjectKey, MetaEdResourceName, } from '@edfi/meadowlark-core'; import { MongoClient } from 'mongodb'; @@ -106,7 +105,7 @@ describe('given the getById of a document owned by the requestor', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -167,7 +166,7 @@ describe('given the getById of a document not owned by the requestor', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Update.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Update.test.ts index 549f3fbd..81509447 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Update.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Update.test.ts @@ -23,7 +23,6 @@ import { DocumentUuid, UpsertResult, MetaEdResourceName, - DocumentObjectKey, MetaEdProjectName, } from '@edfi/meadowlark-core'; import { ClientSession, Collection, MongoClient } from 'mongodb'; @@ -67,7 +66,7 @@ describe('given the update of a non-existent document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update1' }], + documentIdentity: [{ natural: 'update1' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -117,7 +116,7 @@ describe('given the update of an existing document', () => { }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update2' }], + documentIdentity: [{ natural: 'update2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -163,8 +162,7 @@ describe('given the update of an existing document', () => { expect(result.documentIdentity).toMatchInlineSnapshot(` [ { - "documentKey": "natural", - "documentValue": "update2", + "natural": "update2", }, ] `); @@ -190,7 +188,7 @@ describe('given the attempted update of an existing document with a stale reques }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update2' }], + documentIdentity: [{ natural: 'update2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -236,8 +234,7 @@ describe('given the attempted update of an existing document with a stale reques expect(result.documentIdentity).toMatchInlineSnapshot(` [ { - "documentKey": "natural", - "documentValue": "update2", + "natural": "update2", }, ] `); @@ -264,7 +261,7 @@ describe('given an update of a document that references a non-existent document }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update4' }], + documentIdentity: [{ natural: 'update4' }], requestTimestamp, }; @@ -276,7 +273,7 @@ describe('given an update of a document that references a non-existent document const invalidReference: DocumentReference = { projectName: documentWithReferencesResourceInfo.projectName, resourceName: documentWithReferencesResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not a valid reference' }], + documentIdentity: [{ natural: 'not a valid reference' }], isDescriptor: false, }; @@ -331,8 +328,7 @@ describe('given an update of a document that references a non-existent document expect(result.documentIdentity).toMatchInlineSnapshot(` [ { - "documentKey": "natural", - "documentValue": "update4", + "natural": "update4", }, ] `); @@ -363,7 +359,7 @@ describe('given an update of a document that references an existing document wit }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update5' }], + documentIdentity: [{ natural: 'update5' }], }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -383,7 +379,7 @@ describe('given an update of a document that references an existing document wit }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update6' }], + documentIdentity: [{ natural: 'update6' }], requestTimestamp, }; const documentWithReferencesMeadowlarkId: MeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -452,8 +448,7 @@ describe('given an update of a document that references an existing document wit expect(result.documentIdentity).toMatchInlineSnapshot(` [ { - "documentKey": "natural", - "documentValue": "update6", + "natural": "update6", }, ] `); @@ -484,7 +479,7 @@ describe('given an update of a document with one existing and one non-existent r }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update7' }], + documentIdentity: [{ natural: 'update7' }], requestTimestamp, }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -502,7 +497,7 @@ describe('given an update of a document with one existing and one non-existent r const invalidReference: DocumentReference = { projectName: referencedResourceInfo.projectName, resourceName: referencedResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not valid' }], + documentIdentity: [{ natural: 'not valid' }], isDescriptor: false, }; @@ -512,7 +507,7 @@ describe('given an update of a document with one existing and one non-existent r }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update8' }], + documentIdentity: [{ natural: 'update8' }], requestTimestamp: requestTimestamp + 1, }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -577,8 +572,7 @@ describe('given an update of a document with one existing and one non-existent r { "identity": [ { - "documentKey": "natural", - "documentValue": "not valid", + "natural": "not valid", }, ], "resourceName": "School", @@ -609,14 +603,14 @@ describe('given an update of a subclass document referenced by an existing docum const superclassInfo: SuperclassInfo = { ...newSuperclassInfo(), - documentIdentity: [{ documentKey: 'educationOrganizationId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ educationOrganizationId: '123' }], resourceName: 'EducationOrganization' as MetaEdResourceName, projectName: 'Ed-Fi' as MetaEdProjectName, }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], superclassInfo, requestTimestamp, }; @@ -638,7 +632,7 @@ describe('given an update of a subclass document referenced by an existing docum }; const documentWithReferenceDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'update6' }], + documentIdentity: [{ week: 'update6' }], requestTimestamp: requestTimestamp + 1, }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -730,7 +724,7 @@ describe('given the update of an existing document changing meadowlarkId with al }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update 2' }], + documentIdentity: [{ natural: 'update 2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -747,7 +741,7 @@ describe('given the update of an existing document changing meadowlarkId with al }; const documentInfoUpdated: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'updated identity' }], + documentIdentity: [{ natural: 'updated identity' }], requestTimestamp: requestTimestamp + 1, }; const meadowlarkIdUpdated = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoUpdated.documentIdentity); @@ -791,7 +785,7 @@ describe('given the update of an existing document changing meadowlarkId with al }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'updated identity' }], + documentIdentity: [{ natural: 'updated identity' }], requestTimestamp, }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -814,7 +808,7 @@ describe('given the update of an existing document changing meadowlarkId with al }; const documentInfoUpdated: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update 2' }], + documentIdentity: [{ natural: 'update 2' }], requestTimestamp: requestTimestamp + 1, }; meadowlarkIdUpdated = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoUpdated.documentIdentity); @@ -880,7 +874,7 @@ describe('given the attempted update of an existing document with a stale reques }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update2' }], + documentIdentity: [{ natural: 'update2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -926,8 +920,7 @@ describe('given the attempted update of an existing document with a stale reques expect(result.documentIdentity).toMatchInlineSnapshot(` [ { - "documentKey": "natural", - "documentValue": "update2", + "natural": "update2", }, ] `); diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Upsert.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Upsert.test.ts index 23efb621..34d2c5a4 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Upsert.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/Upsert.test.ts @@ -21,7 +21,6 @@ import { MeadowlarkId, TraceId, UpsertResult, - DocumentObjectKey, MetaEdResourceName, MetaEdProjectName, } from '@edfi/meadowlark-core'; @@ -53,7 +52,7 @@ describe('given the upsert of a new document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert1' }], + documentIdentity: [{ natural: 'upsert1' }], requestTimestamp, }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -115,7 +114,7 @@ describe('given the upsert of an existing document three times', () => { }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key' }], + documentIdentity: [{ natural: 'key' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -212,7 +211,7 @@ describe('given an upsert of an existing non-identity-update supporting document }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert3' }], + documentIdentity: [{ natural: 'upsert3' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -271,7 +270,7 @@ describe('given an upsert of an existing identity-update supporting document, ch }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert3' }], + documentIdentity: [{ natural: 'upsert3' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -332,12 +331,12 @@ describe('given an upsert of an existing non-identity update supporting document }; const documentInfo1: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key1' }], + documentIdentity: [{ natural: 'key1' }], requestTimestamp, }; const documentInfo2: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key2' }], + documentIdentity: [{ natural: 'key2' }], requestTimestamp: requestTimestamp + 1, }; @@ -422,12 +421,12 @@ describe('given an upsert of an existing identity update supporting document, ch }; const documentInfo1: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key1' }], + documentIdentity: [{ natural: 'key1' }], requestTimestamp, }; const documentInfo2: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key2' }], + documentIdentity: [{ natural: 'key2' }], requestTimestamp: requestTimestamp + 1, }; @@ -510,7 +509,7 @@ describe('given an upsert of a new document that references a non-existent docum }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert4' }], + documentIdentity: [{ natural: 'upsert4' }], }; const documentWithReferencesId = meadowlarkIdForDocumentIdentity( @@ -521,7 +520,7 @@ describe('given an upsert of a new document that references a non-existent docum const invalidReference: DocumentReference = { projectName: documentWithReferencesResourceInfo.projectName, resourceName: documentWithReferencesResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not valid' }], + documentIdentity: [{ natural: 'not valid' }], isDescriptor: false, }; documentWithReferencesInfo.documentReferences = [invalidReference]; @@ -556,8 +555,7 @@ describe('given an upsert of a new document that references a non-existent docum it('should have inserted the document with an invalid reference in the db', async () => { const collection: Collection = getDocumentCollection(client); const result: any = await collection.findOne({ _id: documentWithReferencesId }); - expect(result.documentIdentity[0].documentKey).toBe('natural'); - expect(result.documentIdentity[0].documentValue).toBe('upsert4'); + expect(result.documentIdentity[0].natural).toBe('upsert4'); }); }); @@ -571,7 +569,7 @@ describe('given an upsert of a new document that references an existing document }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert5' }], + documentIdentity: [{ natural: 'upsert5' }], }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -591,7 +589,7 @@ describe('given an upsert of a new document that references an existing document }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert6' }], + documentIdentity: [{ natural: 'upsert6' }], documentReferences: [validReference], }; const documentWithReferencesId = meadowlarkIdForDocumentIdentity( @@ -640,8 +638,7 @@ describe('given an upsert of a new document that references an existing document it('should have inserted the document with a valid reference in the db', async () => { const collection: Collection = getDocumentCollection(client); const result: any = await collection.findOne({ _id: documentWithReferencesId }); - expect(result.documentIdentity[0].documentKey).toBe('natural'); - expect(result.documentIdentity[0].documentValue).toBe('upsert6'); + expect(result.documentIdentity[0].natural).toBe('upsert6'); }); }); @@ -655,7 +652,7 @@ describe('given an upsert of a new document with one existing and one non-existe }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert7' }], + documentIdentity: [{ natural: 'upsert7' }], }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -672,7 +669,7 @@ describe('given an upsert of a new document with one existing and one non-existe const invalidReference: DocumentReference = { projectName: referencedResourceInfo.projectName, resourceName: referencedResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not valid' }], + documentIdentity: [{ natural: 'not valid' }], isDescriptor: false, }; @@ -682,7 +679,7 @@ describe('given an upsert of a new document with one existing and one non-existe }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert8' }], + documentIdentity: [{ natural: 'upsert8' }], documentReferences: [validReference, invalidReference], }; const documentWithReferencesId = meadowlarkIdForDocumentIdentity( @@ -733,8 +730,7 @@ describe('given an upsert of a new document with one existing and one non-existe { "identity": [ { - "documentKey": "natural", - "documentValue": "not valid", + "natural": "not valid", }, ], "resourceName": "School", @@ -765,14 +761,14 @@ describe('given an upsert of a subclass document referenced by an existing docum const superclassInfo: SuperclassInfo = { ...newSuperclassInfo(), - documentIdentity: [{ documentKey: 'educationOrganizationId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ educationOrganizationId: '123' }], resourceName: 'EducationOrganization' as MetaEdResourceName, projectName: 'Ed-Fi' as MetaEdProjectName, }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], superclassInfo, }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -793,7 +789,7 @@ describe('given an upsert of a subclass document referenced by an existing docum }; const documentWithReferenceDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'update6' }], + documentIdentity: [{ week: 'update6' }], documentReferences: [referenceAsSuperclass], }; const documentWithReferencesId = meadowlarkIdForDocumentIdentity( @@ -854,9 +850,7 @@ describe('given an upsert of a subclass document when a different subclass has t let client; let upsertResult; - const documentIdentity: DocumentIdentity = [ - { documentKey: 'educationOrganizationId' as DocumentObjectKey, documentValue: '123' }, - ]; + const documentIdentity: DocumentIdentity = [{ educationOrganizationId: '123' }]; const superclassInfo: SuperclassInfo = { ...newSuperclassInfo(), @@ -871,7 +865,7 @@ describe('given an upsert of a subclass document when a different subclass has t }; const existingSubclassDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], superclassInfo, }; @@ -886,7 +880,7 @@ describe('given an upsert of a subclass document when a different subclass has t }; const sameSuperclassIdentityDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'localEducationAgencyId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ localEducationAgencyId: '123' }], superclassInfo, }; const sameSuperclassIdentityId = meadowlarkIdForDocumentIdentity( @@ -954,7 +948,7 @@ describe('given an update of a document that references a non-existent document }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'upsert4' }], + documentIdentity: [{ week: 'upsert4' }], requestTimestamp, }; @@ -966,7 +960,7 @@ describe('given an update of a document that references a non-existent document const invalidReference: DocumentReference = { projectName: documentWithReferencesResourceInfo.projectName, resourceName: documentWithReferencesResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not valid' }], + documentIdentity: [{ natural: 'not valid' }], isDescriptor: false, }; @@ -1013,8 +1007,7 @@ describe('given an update of a document that references a non-existent document it('should have updated the document with an invalid reference in the db', async () => { const collection: Collection = getDocumentCollection(client); const result: any = await collection.findOne({ _id: documentWithReferencesId }); - expect(result.documentIdentity[0].documentKey).toBe('week'); - expect(result.documentIdentity[0].documentValue).toBe('upsert4'); + expect(result.documentIdentity[0].week).toBe('upsert4'); expect(result.outboundRefs).toMatchInlineSnapshot(` [ "QtykK4uDYZK7VOChzZNTfqxhrlznYfnql5kIHg", @@ -1033,7 +1026,7 @@ describe('given an update of a document that references an existing document wit }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'upsert5' }], + documentIdentity: [{ week: 'upsert5' }], requestTimestamp, }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -1054,7 +1047,7 @@ describe('given an update of a document that references an existing document wit }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'upsert6' }], + documentIdentity: [{ week: 'upsert6' }], requestTimestamp: requestTimestamp + 1, }; const documentWithReferencesId = meadowlarkIdForDocumentIdentity( @@ -1116,8 +1109,7 @@ describe('given an update of a document that references an existing document wit it('should have updated the document with a valid reference in the db', async () => { const collection: Collection = getDocumentCollection(client); const result: any = await collection.findOne({ _id: documentWithReferencesId }); - expect(result.documentIdentity[0].documentKey).toBe('week'); - expect(result.documentIdentity[0].documentValue).toBe('upsert6'); + expect(result.documentIdentity[0].week).toBe('upsert6'); expect(result.outboundRefs).toMatchInlineSnapshot(` [ "Qw5FvPdKxAXWnGghJNiT2FU22MBPJwl7FpuNdw", @@ -1136,7 +1128,7 @@ describe('given an update of a document with one existing and one non-existent r }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'upsert7' }], + documentIdentity: [{ week: 'upsert7' }], requestTimestamp, }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -1154,7 +1146,7 @@ describe('given an update of a document with one existing and one non-existent r const invalidReference: DocumentReference = { projectName: referencedResourceInfo.projectName, resourceName: referencedResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not valid' }], + documentIdentity: [{ natural: 'not valid' }], isDescriptor: false, }; @@ -1164,7 +1156,7 @@ describe('given an update of a document with one existing and one non-existent r }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'upsert8' }], + documentIdentity: [{ week: 'upsert8' }], requestTimestamp: requestTimestamp + 1, }; const documentWithReferencesId = meadowlarkIdForDocumentIdentity( @@ -1228,8 +1220,7 @@ describe('given an update of a document with one existing and one non-existent r { "identity": [ { - "documentKey": "natural", - "documentValue": "not valid", + "natural": "not valid", }, ], "resourceName": "School", @@ -1260,14 +1251,14 @@ describe('given an update of a subclass document referenced by an existing docum const superclassInfo: SuperclassInfo = { ...newSuperclassInfo(), - documentIdentity: [{ documentKey: 'educationOrganizationId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ educationOrganizationId: '123' }], resourceName: 'EducationOrganization' as MetaEdResourceName, projectName: 'Ed-Fi' as MetaEdProjectName, }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], superclassInfo, requestTimestamp, }; @@ -1289,7 +1280,7 @@ describe('given an update of a subclass document referenced by an existing docum }; const documentWithReferenceDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'update6' }], + documentIdentity: [{ week: 'update6' }], requestTimestamp: requestTimestamp + 1, }; const documentWithReferencesId = meadowlarkIdForDocumentIdentity( @@ -1370,7 +1361,7 @@ describe('given the upsert of an existing document with a stale request timestam }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key' }], + documentIdentity: [{ natural: 'key' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts index 79ced7aa..6de97f6b 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/integration/locking/Delete.test.ts @@ -18,7 +18,6 @@ import { MeadowlarkId, TraceId, MetaEdResourceName, - DocumentObjectKey, } from '@edfi/meadowlark-core'; import { ClientSession, Collection, MongoClient } from 'mongodb'; import { MeadowlarkDocument, meadowlarkDocumentFrom } from '../../../src/model/MeadowlarkDocument'; @@ -57,7 +56,7 @@ const schoolResourceInfo: ResourceInfo = { const schoolDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], }; const schoolMeadowlarkId = meadowlarkIdForDocumentIdentity(schoolResourceInfo, schoolDocumentInfo.documentIdentity); @@ -74,10 +73,7 @@ const academicWeekResourceInfo: ResourceInfo = { }; const academicWeekDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [ - { documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }, - { documentKey: 'weekIdentifier' as DocumentObjectKey, documentValue: '123456' }, - ], + documentIdentity: [{ schoolId: '123' }, { weekIdentifier: '123456' }], documentReferences: [referenceToSchool], }; const academicWeekMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -196,8 +192,7 @@ describe('given a delete concurrent with an insert referencing the to-be-deleted expect(result.documentIdentity).toMatchInlineSnapshot(` [ { - "documentKey": "schoolId", - "documentValue": "123", + "schoolId": "123", }, ] `); diff --git a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/model/MeadowlarkDocument.test.ts b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/model/MeadowlarkDocument.test.ts index 5d163a74..418c957e 100644 --- a/Meadowlark-js/backends/meadowlark-mongodb-backend/test/model/MeadowlarkDocument.test.ts +++ b/Meadowlark-js/backends/meadowlark-mongodb-backend/test/model/MeadowlarkDocument.test.ts @@ -12,7 +12,6 @@ import { DocumentUuid, MetaEdResourceName, MetaEdProjectName, - DocumentObjectKey, } from '@edfi/meadowlark-core'; import { MeadowlarkDocument, meadowlarkDocumentFrom } from '../../src/model/MeadowlarkDocument'; @@ -25,7 +24,7 @@ describe('given non-superclass document info with no references', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key' }], + documentIdentity: [{ natural: 'key' }], }; const documentUuid = '3018d452-a7b7-4f1c-aa91-26ccc48cf4b8' as DocumentUuid; @@ -61,8 +60,7 @@ describe('given non-superclass document info with no references', () => { "createdBy": "createdBy", "documentIdentity": [ { - "documentKey": "natural", - "documentValue": "key", + "natural": "key", }, ], "documentUuid": "3018d452-a7b7-4f1c-aa91-26ccc48cf4b8", @@ -90,10 +88,10 @@ describe('given non-superclass document info with references', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key' }], + documentIdentity: [{ natural: 'key' }], documentReferences: [ { - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key2' }], + documentIdentity: [{ natural: 'key2' }], isDescriptor: false, projectName: 'projectName' as MetaEdProjectName, resourceName: 'resourceName' as MetaEdResourceName, @@ -101,7 +99,7 @@ describe('given non-superclass document info with references', () => { ], descriptorReferences: [ { - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key3' }], + documentIdentity: [{ natural: 'key3' }], isDescriptor: true, projectName: 'projectName' as MetaEdProjectName, resourceName: 'resourceName2' as MetaEdResourceName, @@ -149,9 +147,9 @@ describe('given superclass document info', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key' }], + documentIdentity: [{ natural: 'key' }], superclassInfo: { - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'key2' }], + documentIdentity: [{ natural: 'key2' }], projectName: 'projectName' as MetaEdProjectName, resourceName: 'resourceName' as MetaEdResourceName, }, diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Delete.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Delete.test.ts index bbc37ef2..d2f510c4 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Delete.test.ts @@ -24,7 +24,6 @@ import { generateDocumentUuid, UpsertResult, MetaEdResourceName, - DocumentObjectKey, MetaEdProjectName, } from '@edfi/meadowlark-core'; import type { PoolClient } from 'pg'; @@ -99,7 +98,7 @@ describe('given the delete of an existing document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete2' }], + documentIdentity: [{ natural: 'delete2' }], }; const documentUuid = generateDocumentUuid(); const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -149,7 +148,7 @@ describe('given an delete of a document referenced by an existing document with const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete5' }], + documentIdentity: [{ natural: 'delete5' }], }; const referencedDocumentId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -169,7 +168,7 @@ describe('given an delete of a document referenced by an existing document with }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete6' }], + documentIdentity: [{ natural: 'delete6' }], documentReferences: [validReference], }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -221,8 +220,7 @@ describe('given an delete of a document referenced by an existing document with it('should still have the referenced document in the db', async () => { const docResult: MeadowlarkDocument = await findDocumentByMeadowlarkId(client, referencedDocumentId); - expect(docResult.document_identity[0].documentKey).toBe('natural'); - expect(docResult.document_identity[0].documentValue).toBe('delete5'); + expect(docResult.document_identity[0].natural).toBe('delete5'); }); }); @@ -237,7 +235,7 @@ describe('given an delete of a document with an outbound reference only, with va const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete15' }], + documentIdentity: [{ natural: 'delete15' }], }; const referencedDocumentId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -257,7 +255,7 @@ describe('given an delete of a document with an outbound reference only, with va }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete16' }], + documentIdentity: [{ natural: 'delete16' }], documentReferences: [validReference], }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -340,7 +338,7 @@ describe('given an delete of a document referenced by an existing document with }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete5' }], + documentIdentity: [{ natural: 'delete5' }], }; const referencedDocumentId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -360,7 +358,7 @@ describe('given an delete of a document referenced by an existing document with }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'delete6' }], + documentIdentity: [{ natural: 'delete6' }], documentReferences: [validReference], }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -435,14 +433,14 @@ describe('given the delete of a subclass document referenced by an existing docu const superclassInfo: SuperclassInfo = { ...newSuperclassInfo(), - documentIdentity: [{ documentKey: 'educationOrganizationId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ educationOrganizationId: '123' }], resourceName: 'EducationOrganization' as MetaEdResourceName, projectName: 'Ed-Fi' as MetaEdProjectName, }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], superclassInfo, }; const referencedDocumentId = meadowlarkIdForDocumentIdentity( @@ -463,7 +461,7 @@ describe('given the delete of a subclass document referenced by an existing docu }; const documentWithReferenceDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'delete6' }], + documentIdentity: [{ week: 'delete6' }], documentReferences: [referenceAsSuperclass], }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -518,7 +516,6 @@ describe('given the delete of a subclass document referenced by an existing docu it('should still have the referenced document in the db', async () => { const result: MeadowlarkDocument = await findDocumentByMeadowlarkId(client, referencedDocumentId); - expect(result.document_identity[0].documentKey).toBe('schoolId'); - expect(result.document_identity[0].documentValue).toBe('123'); + expect(result.document_identity[0].schoolId).toBe('123'); }); }); diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/OwnershipSecurity.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/OwnershipSecurity.test.ts index d250b577..d9557873 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/OwnershipSecurity.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/OwnershipSecurity.test.ts @@ -18,7 +18,6 @@ import { TraceId, newFrontendRequestMiddleware, newPathComponents, - DocumentObjectKey, MetaEdResourceName, } from '@edfi/meadowlark-core'; import type { PoolClient } from 'pg'; @@ -103,7 +102,7 @@ describe('given the getById of a document owned by the requestor', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -162,7 +161,7 @@ describe('given the getById of a document not owned by the requestor', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Read.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Read.test.ts index ac0aaf10..10a0f54d 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Read.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Read.test.ts @@ -18,7 +18,6 @@ import { DocumentUuid, TraceId, MeadowlarkId, - DocumentObjectKey, MetaEdResourceName, } from '@edfi/meadowlark-core'; import type { PoolClient } from 'pg'; @@ -56,7 +55,7 @@ describe('given the get of a non-existent document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get1' }], + documentIdentity: [{ natural: 'get1' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); const documentUuid = 'ffb6ea15-fa93-4389-89a8-1428fb617490' as DocumentUuid; @@ -94,7 +93,7 @@ describe('given the get of an existing document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], requestTimestamp: 1000, }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/SecurityMiddleware.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/SecurityMiddleware.test.ts index 005670d0..d01f405e 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/SecurityMiddleware.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/SecurityMiddleware.test.ts @@ -19,7 +19,6 @@ import { TraceId, newFrontendRequestMiddleware, newPathComponents, - DocumentObjectKey, MetaEdResourceName, } from '@edfi/meadowlark-core'; import type { PoolClient } from 'pg'; @@ -103,7 +102,7 @@ describe('given the getById of a document owned by the requestor', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -161,7 +160,7 @@ describe('given the getById of a document not owned by the requestor', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'get2' }], + documentIdentity: [{ natural: 'get2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Update.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Update.test.ts index 58b941f2..0e2be266 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Update.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Update.test.ts @@ -23,7 +23,6 @@ import { TraceId, UpsertRequest, UpsertResult, - DocumentObjectKey, MetaEdResourceName, MetaEdProjectName, } from '@edfi/meadowlark-core'; @@ -83,7 +82,7 @@ describe('given the update of a non-existent document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update1' }], + documentIdentity: [{ natural: 'update1' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -131,7 +130,7 @@ describe('given the update of an existing document', () => { }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update2' }], + documentIdentity: [{ natural: 'update2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -180,8 +179,7 @@ describe('given the update of an existing document', () => { it('should have updated the document in the db', async () => { const result: MeadowlarkDocument = await findDocumentByDocumentUuid(client, resultDocumentUuid); - expect(result.document_identity[0].documentKey).toBe('natural'); - expect(result.document_identity[0].documentValue).toBe('update2'); + expect(result.document_identity[0].natural).toBe('update2'); expect(result.edfi_doc.changeToDoc).toBe(true); }); @@ -202,7 +200,7 @@ describe('given the attempted update of an existing document with a stale reques }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update2' }], + documentIdentity: [{ natural: 'update2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -251,8 +249,7 @@ describe('given the attempted update of an existing document with a stale reques it('should not have updated the document in the db', async () => { const result: MeadowlarkDocument = await findDocumentByDocumentUuid(client, resultDocumentUuid); - expect(result.document_identity[0].documentKey).toBe('natural'); - expect(result.document_identity[0].documentValue).toBe('update2'); + expect(result.document_identity[0].natural).toBe('update2'); expect(result.edfi_doc.changeToDoc).toBeUndefined(); }); @@ -273,7 +270,7 @@ describe('given an update of a document that references a non-existent document }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update4' }], + documentIdentity: [{ natural: 'update4' }], requestTimestamp, }; @@ -285,7 +282,7 @@ describe('given an update of a document that references a non-existent document const invalidReference: DocumentReference = { projectName: documentWithReferencesResourceInfo.projectName, resourceName: documentWithReferencesResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not a valid reference' }], + documentIdentity: [{ natural: 'not a valid reference' }], isDescriptor: false, }; @@ -336,8 +333,7 @@ describe('given an update of a document that references a non-existent document const docResult: MeadowlarkDocument = await findDocumentByMeadowlarkId(client, documentWithReferencesId); const refsResult: any = await client.query(retrieveReferencesByMeadowlarkIdSql(documentWithReferencesId)); const outboundRefs = refsResult.rows.map((ref) => ref.referenced_meadowlark_id); - expect(docResult.document_identity[0].documentKey).toBe('natural'); - expect(docResult.document_identity[0].documentValue).toBe('update4'); + expect(docResult.document_identity[0].natural).toBe('update4'); expect(outboundRefs).toMatchInlineSnapshot(` [ "QtykK4uDYZK7VOChNxRsMDtOcAu6a0oe9ozl2Q", @@ -362,7 +358,7 @@ describe('given an update of a document that references an existing document wit }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update5' }], + documentIdentity: [{ natural: 'update5' }], }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -382,7 +378,7 @@ describe('given an update of a document that references an existing document wit }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update6' }], + documentIdentity: [{ natural: 'update6' }], requestTimestamp, }; const documentWithReferencesId = meadowlarkIdForDocumentIdentity( @@ -450,8 +446,7 @@ describe('given an update of a document that references an existing document wit const refsResult: any = await client.query(retrieveReferencesByMeadowlarkIdSql(documentWithReferencesId)); const outboundRefs = refsResult.rows.map((ref) => ref.referenced_meadowlark_id); - expect(docResult.document_identity[0].documentKey).toBe('natural'); - expect(docResult.document_identity[0].documentValue).toBe('update6'); + expect(docResult.document_identity[0].natural).toBe('update6'); expect(outboundRefs).toMatchInlineSnapshot(` [ "Qw5FvPdKxAXWnGghsMh3I61yLFfls4Q949Fk2w", @@ -476,7 +471,7 @@ describe('given an update of a document with one existing and one non-existent r }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update7' }], + documentIdentity: [{ natural: 'update7' }], requestTimestamp, }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -494,7 +489,7 @@ describe('given an update of a document with one existing and one non-existent r const invalidReference: DocumentReference = { projectName: referencedResourceInfo.projectName, resourceName: referencedResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not a valid reference' }], + documentIdentity: [{ natural: 'not a valid reference' }], isDescriptor: false, }; @@ -504,7 +499,7 @@ describe('given an update of a document with one existing and one non-existent r }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update8' }], + documentIdentity: [{ natural: 'update8' }], requestTimestamp: requestTimestamp + 1, }; const documentWithReferencesId = meadowlarkIdForDocumentIdentity( @@ -569,8 +564,7 @@ describe('given an update of a document with one existing and one non-existent r { "identity": [ { - "documentKey": "natural", - "documentValue": "not a valid reference", + "natural": "not a valid reference", }, ], "resourceName": "School", @@ -602,14 +596,14 @@ describe('given an update of a subclass document referenced by an existing docum const superclassInfo: SuperclassInfo = { ...newSuperclassInfo(), - documentIdentity: [{ documentKey: 'educationOrganizationId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ educationOrganizationId: '123' }], resourceName: 'EducationOrganization' as MetaEdResourceName, projectName: 'Ed-Fi' as MetaEdProjectName, }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], superclassInfo, requestTimestamp, }; @@ -631,7 +625,7 @@ describe('given an update of a subclass document referenced by an existing docum }; const documentWithReferenceDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'update6' }], + documentIdentity: [{ week: 'update6' }], requestTimestamp: requestTimestamp + 1, }; @@ -720,7 +714,7 @@ describe('given the update of an existing document changing meadowlarkId with al }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update 2' }], + documentIdentity: [{ natural: 'update 2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -735,7 +729,7 @@ describe('given the update of an existing document changing meadowlarkId with al }; const documentInfoUpdated: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'updated identity' }], + documentIdentity: [{ natural: 'updated identity' }], requestTimestamp: requestTimestamp + 1, }; @@ -779,7 +773,7 @@ describe('given the update of an existing document changing meadowlarkId with al }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update5' }], + documentIdentity: [{ natural: 'update5' }], }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -800,9 +794,7 @@ describe('given the update of an existing document changing meadowlarkId with al }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [ - { documentKey: 'natural' as DocumentObjectKey, documentValue: 'updated identity allow identity updates' }, - ], + documentIdentity: [{ natural: 'updated identity allow identity updates' }], documentReferences: [validReference], requestTimestamp, @@ -810,7 +802,7 @@ describe('given the update of an existing document changing meadowlarkId with al const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); const documentInfoUpdated: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update 2' }], + documentIdentity: [{ natural: 'update 2' }], documentReferences: [validReference], requestTimestamp: requestTimestamp + 1, @@ -903,7 +895,7 @@ describe('given the attempted update of an existing document with a stale reques }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'update2' }], + documentIdentity: [{ natural: 'update2' }], requestTimestamp, }; @@ -956,8 +948,7 @@ describe('given the attempted update of an existing document with a stale reques it('should not have updated the document in the db', async () => { const result: MeadowlarkDocument = await findDocumentByMeadowlarkId(client, meadowlarkId); - expect(result.document_identity[0].documentKey).toBe('natural'); - expect(result.document_identity[0].documentValue).toBe('update2'); + expect(result.document_identity[0].natural).toBe('update2'); expect(result.edfi_doc.natural).toBe('key'); }); diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Upsert.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Upsert.test.ts index 0ab792f4..76a70373 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Upsert.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/Upsert.test.ts @@ -21,7 +21,6 @@ import { TraceId, MetaEdResourceName, MetaEdProjectName, - DocumentObjectKey, } from '@edfi/meadowlark-core'; import type { PoolClient } from 'pg'; import { getSharedClient, resetSharedClient } from '../../src/repository/Db'; @@ -52,7 +51,7 @@ describe('given the upsert of a new document', () => { }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert1' }], + documentIdentity: [{ natural: 'upsert1' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -101,7 +100,7 @@ describe('given the upsert of an existing document three times', () => { }; const documentInfoBase: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert2' }], + documentIdentity: [{ natural: 'upsert2' }], }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfoBase.documentIdentity); @@ -169,7 +168,7 @@ describe('given an upsert of an existing document that changes the edfiDoc', () }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert3' }], + documentIdentity: [{ natural: 'upsert3' }], requestTimestamp, }; @@ -219,7 +218,7 @@ describe('given an attempted upsert of an existing document with a stale request }; const documentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert3' }], + documentIdentity: [{ natural: 'upsert3' }], requestTimestamp, }; const meadowlarkId = meadowlarkIdForDocumentIdentity(resourceInfo, documentInfo.documentIdentity); @@ -271,7 +270,7 @@ describe('given an upsert of a new document that references a non-existent docum }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert4' }], + documentIdentity: [{ natural: 'upsert4' }], }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -282,7 +281,7 @@ describe('given an upsert of a new document that references a non-existent docum const invalidReference: DocumentReference = { projectName: documentWithReferencesResourceInfo.projectName, resourceName: documentWithReferencesResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not a valid reference' }], + documentIdentity: [{ natural: 'not a valid reference' }], isDescriptor: false, }; @@ -316,8 +315,7 @@ describe('given an upsert of a new document that references a non-existent docum it('should have inserted the document with an invalid reference in the db', async () => { const result: MeadowlarkDocument = await findDocumentByMeadowlarkId(client, documentWithReferencesMeadowlarkId); - expect(result.document_identity[0].documentKey).toBe('natural'); - expect(result.document_identity[0].documentValue).toBe('upsert4'); + expect(result.document_identity[0].natural).toBe('upsert4'); }); }); @@ -331,7 +329,7 @@ describe('given an upsert of a new document that references an existing document }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert5' }], + documentIdentity: [{ natural: 'upsert5' }], }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( referencedResourceInfo, @@ -351,7 +349,7 @@ describe('given an upsert of a new document that references an existing document }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert6' }], + documentIdentity: [{ natural: 'upsert6' }], documentReferences: [validReference], }; @@ -399,8 +397,7 @@ describe('given an upsert of a new document that references an existing document it('should have inserted the document with a valid reference in the db', async () => { const result: MeadowlarkDocument = await findDocumentByMeadowlarkId(client, documentWithReferencesMeadowlarkId); - expect(result.document_identity[0].documentKey).toBe('natural'); - expect(result.document_identity[0].documentValue).toBe('upsert6'); + expect(result.document_identity[0].natural).toBe('upsert6'); }); }); @@ -414,7 +411,7 @@ describe('given an upsert of a new document with one existing and one non-existe }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert7' }], + documentIdentity: [{ natural: 'upsert7' }], requestTimestamp, }; @@ -433,7 +430,7 @@ describe('given an upsert of a new document with one existing and one non-existe const invalidReference: DocumentReference = { projectName: referencedResourceInfo.projectName, resourceName: referencedResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not a valid reference' }], + documentIdentity: [{ natural: 'not a valid reference' }], isDescriptor: false, }; @@ -444,7 +441,7 @@ describe('given an upsert of a new document with one existing and one non-existe }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert8' }], + documentIdentity: [{ natural: 'upsert8' }], documentReferences: [validReference, invalidReference], requestTimestamp: requestTimestamp + 1, }; @@ -495,8 +492,7 @@ describe('given an upsert of a new document with one existing and one non-existe { "identity": [ { - "documentKey": "natural", - "documentValue": "not a valid reference", + "natural": "not a valid reference", }, ], "resourceName": "School", @@ -520,7 +516,7 @@ describe('given an upsert of a subclass document when a different subclass has t const superclassInfo: SuperclassInfo = { ...newSuperclassInfo(), - documentIdentity: [{ documentKey: 'educationOrganizationId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ educationOrganizationId: '123' }], resourceName: 'EducationOrganization' as MetaEdResourceName, projectName: 'Ed-Fi' as MetaEdProjectName, }; @@ -531,7 +527,7 @@ describe('given an upsert of a subclass document when a different subclass has t }; const existingSubclassDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], superclassInfo, }; const existingSubclassMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -545,7 +541,7 @@ describe('given an upsert of a subclass document when a different subclass has t }; const sameSuperclassIdentityDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'localEducationAgencyId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ localEducationAgencyId: '123' }], superclassInfo, }; const sameSuperclassIdentityMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -611,7 +607,7 @@ describe('given an update of a document that references a non-existent document }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert4' }], + documentIdentity: [{ natural: 'upsert4' }], requestTimestamp, }; @@ -623,7 +619,7 @@ describe('given an update of a document that references a non-existent document const invalidReference: DocumentReference = { projectName: documentWithReferencesResourceInfo.projectName, resourceName: documentWithReferencesResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not a valid reference' }], + documentIdentity: [{ natural: 'not a valid reference' }], isDescriptor: false, }; @@ -672,8 +668,7 @@ describe('given an update of a document that references a non-existent document const refsResult: any = await client.query(retrieveReferencesByMeadowlarkIdSql(documentWithReferencesMeadowlarkId)); const outboundRefs = refsResult.rows.map((ref) => ref.referenced_meadowlark_id); - expect(docResult.document_identity[0].documentKey).toBe('natural'); - expect(docResult.document_identity[0].documentValue).toBe('upsert4'); + expect(docResult.document_identity[0].natural).toBe('upsert4'); expect(outboundRefs).toMatchInlineSnapshot(` [ "QtykK4uDYZK7VOChNxRsMDtOcAu6a0oe9ozl2Q", @@ -692,7 +687,7 @@ describe('given an update of a document that references an existing document wit }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert5' }], + documentIdentity: [{ natural: 'upsert5' }], requestTimestamp, }; @@ -714,7 +709,7 @@ describe('given an update of a document that references an existing document wit }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert6' }], + documentIdentity: [{ natural: 'upsert6' }], requestTimestamp: requestTimestamp + 1, }; @@ -779,8 +774,7 @@ describe('given an update of a document that references an existing document wit const outboundRefs = refsResult.rows.map((ref) => ref.referenced_meadowlark_id); - expect(docResult.document_identity[0].documentKey).toBe('natural'); - expect(docResult.document_identity[0].documentValue).toBe('upsert6'); + expect(docResult.document_identity[0].natural).toBe('upsert6'); expect(outboundRefs).toMatchInlineSnapshot(` [ "Qw5FvPdKxAXWnGghUWv5LKuA2cXaJPWJGJRDBQ", @@ -799,7 +793,7 @@ describe('given an update of a document with one existing and one non-existent r }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert7' }], + documentIdentity: [{ natural: 'upsert7' }], requestTimestamp, }; const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -817,7 +811,7 @@ describe('given an update of a document with one existing and one non-existent r const invalidReference: DocumentReference = { projectName: referencedResourceInfo.projectName, resourceName: referencedResourceInfo.resourceName, - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'not a valid reference' }], + documentIdentity: [{ natural: 'not a valid reference' }], isDescriptor: false, }; @@ -828,7 +822,7 @@ describe('given an update of a document with one existing and one non-existent r }; const documentWithReferencesInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'natural' as DocumentObjectKey, documentValue: 'upsert8' }], + documentIdentity: [{ natural: 'upsert8' }], requestTimestamp: requestTimestamp + 1, }; const documentWithReferencesMeadowlarkId: MeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -891,8 +885,7 @@ describe('given an update of a document with one existing and one non-existent r { "identity": [ { - "documentKey": "natural", - "documentValue": "not a valid reference", + "natural": "not a valid reference", }, ], "resourceName": "School", @@ -930,14 +923,14 @@ describe('given an update of a subclass document referenced by an existing docum const superclassInfo: SuperclassInfo = { ...newSuperclassInfo(), - documentIdentity: [{ documentKey: 'educationOrganizationId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ educationOrganizationId: '123' }], resourceName: 'EducationOrganization' as MetaEdResourceName, projectName: 'Ed-Fi' as MetaEdProjectName, }; const referencedDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], superclassInfo, requestTimestamp, }; @@ -959,7 +952,7 @@ describe('given an update of a subclass document referenced by an existing docum }; const documentWithReferenceDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'week' as DocumentObjectKey, documentValue: 'update6' }], + documentIdentity: [{ week: 'update6' }], requestTimestamp: requestTimestamp + 1, }; const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity( diff --git a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/locking/Delete.test.ts b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/locking/Delete.test.ts index ee916b82..ad322423 100644 --- a/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/locking/Delete.test.ts +++ b/Meadowlark-js/backends/meadowlark-postgresql-backend/test/integration/locking/Delete.test.ts @@ -22,7 +22,6 @@ import { MeadowlarkId, TraceId, DocumentUuid, - DocumentObjectKey, MetaEdResourceName, } from '@edfi/meadowlark-core'; import { PoolClient } from 'pg'; @@ -60,7 +59,7 @@ const schoolResourceInfo: ResourceInfo = { const schoolDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [{ documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }], + documentIdentity: [{ schoolId: '123' }], }; const schoolMeadowlarkId = meadowlarkIdForDocumentIdentity(schoolResourceInfo, schoolDocumentInfo.documentIdentity); @@ -77,10 +76,7 @@ const academicWeekResourceInfo: ResourceInfo = { }; const academicWeekDocumentInfo: DocumentInfo = { ...newDocumentInfo(), - documentIdentity: [ - { documentKey: 'schoolId' as DocumentObjectKey, documentValue: '123' }, - { documentKey: 'weekIdentifier' as DocumentObjectKey, documentValue: '123456' }, - ], + documentIdentity: [{ schoolId: '123' }, { weekIdentifier: '123456' }], documentReferences: [referenceToSchool], }; const academicWeekMeadowlarkId = meadowlarkIdForDocumentIdentity( @@ -194,8 +190,7 @@ describe('given a delete concurrent with an insert referencing the to-be-deleted it('should have still have the School document in the db - a success', async () => { const docResult: MeadowlarkDocument = await findDocumentByMeadowlarkId(insertClient, schoolMeadowlarkId); - expect(docResult.document_identity[0].documentKey).toBe('schoolId'); - expect(docResult.document_identity[0].documentValue).toBe('123'); + expect(docResult.document_identity[0].schoolId).toBe('123'); }); }); diff --git a/Meadowlark-js/packages/meadowlark-core/src/extraction/DescriptorValueExtractor.ts b/Meadowlark-js/packages/meadowlark-core/src/extraction/DescriptorValueExtractor.ts index ddd0a3d4..5738211c 100644 --- a/Meadowlark-js/packages/meadowlark-core/src/extraction/DescriptorValueExtractor.ts +++ b/Meadowlark-js/packages/meadowlark-core/src/extraction/DescriptorValueExtractor.ts @@ -43,8 +43,7 @@ export function extractDescriptorValues(resourceSchema: ResourceSchema, document if (descriptorValues.length === 0) return; const documentIdentity: DocumentIdentity = descriptorValues.map((descriptorValue) => ({ - documentKey: 'descriptor' as DocumentObjectKey, - documentValue: descriptorValue, + descriptor: descriptorValue, })); result.push({ diff --git a/Meadowlark-js/packages/meadowlark-core/src/extraction/DocumentIdentityExtractor.ts b/Meadowlark-js/packages/meadowlark-core/src/extraction/DocumentIdentityExtractor.ts index b37e3117..5ca5118d 100644 --- a/Meadowlark-js/packages/meadowlark-core/src/extraction/DocumentIdentityExtractor.ts +++ b/Meadowlark-js/packages/meadowlark-core/src/extraction/DocumentIdentityExtractor.ts @@ -60,7 +60,7 @@ export function extractDocumentIdentity(resourceSchema: ResourceSchema, document ); invariant(documentValue != null, `Identity for path ${documentJsonPath} was not found in the document`); - documentIdentity.push({ documentKey, documentValue }); + documentIdentity.push({ [documentKey]: documentValue }); }); invariant( diff --git a/Meadowlark-js/packages/meadowlark-core/src/extraction/DocumentReferenceExtractor.ts b/Meadowlark-js/packages/meadowlark-core/src/extraction/DocumentReferenceExtractor.ts index b3c05452..0b218069 100644 --- a/Meadowlark-js/packages/meadowlark-core/src/extraction/DocumentReferenceExtractor.ts +++ b/Meadowlark-js/packages/meadowlark-core/src/extraction/DocumentReferenceExtractor.ts @@ -148,11 +148,9 @@ export function extractDocumentReferences( const documentIdentity: DocumentIdentity = []; + // Put the unsorted documentIdentity fields into an ordered DocumentIdentity referenceResourceSchema.identityPathOrder.forEach((documentKey: DocumentObjectKey) => { - documentIdentity.push({ - documentKey, - documentValue: unsortedDocumentIdentity[documentKey], - }); + documentIdentity.push({ [documentKey]: unsortedDocumentIdentity[documentKey] }); }); result.push({ diff --git a/Meadowlark-js/packages/meadowlark-core/src/model/DescriptorDocumentInfo.ts b/Meadowlark-js/packages/meadowlark-core/src/model/DescriptorDocumentInfo.ts index 4d2590e8..a62ec330 100644 --- a/Meadowlark-js/packages/meadowlark-core/src/model/DescriptorDocumentInfo.ts +++ b/Meadowlark-js/packages/meadowlark-core/src/model/DescriptorDocumentInfo.ts @@ -8,14 +8,15 @@ import { DocumentIdentity } from './DocumentIdentity'; import { DocumentInfo, newDocumentInfo } from './DocumentInfo'; import { DocumentObjectKey } from './api-schema/DocumentObjectKey'; +const descriptorKey = 'descriptor' as DocumentObjectKey; + /** * Creates a new DocumentIdentity from the given DescriptorDocument */ export function descriptorDocumentIdentityFrom(descriptorDocument: DescriptorDocument): DocumentIdentity { return [ { - documentKey: 'descriptor' as DocumentObjectKey, - documentValue: `${descriptorDocument.namespace}#${descriptorDocument.codeValue}`, + [descriptorKey]: `${descriptorDocument.namespace}#${descriptorDocument.codeValue}`, }, ]; } diff --git a/Meadowlark-js/packages/meadowlark-core/src/model/DocumentIdentity.ts b/Meadowlark-js/packages/meadowlark-core/src/model/DocumentIdentity.ts index 255df481..57569184 100644 --- a/Meadowlark-js/packages/meadowlark-core/src/model/DocumentIdentity.ts +++ b/Meadowlark-js/packages/meadowlark-core/src/model/DocumentIdentity.ts @@ -4,14 +4,14 @@ // See the LICENSE and NOTICES files in the project root for more information. import crypto from 'node:crypto'; +import invariant from 'ts-invariant'; import { DocumentUuid, MeadowlarkId } from './IdTypes'; import type { BaseResourceInfo } from './ResourceInfo'; -import { DocumentObjectKey } from './api-schema/DocumentObjectKey'; /** - * A simple tuple containing the key and corresponding document value that makes up part of a document identity. + * A simple tuple containing the DocumentObjectKey and corresponding document value that makes up part of a document identity. */ -export type DocumentIdentityElement = { documentKey: DocumentObjectKey; documentValue: any }; +export type DocumentIdentityElement = { [documentObjectKey: string]: any }; /** * A DocumentIdentity is an array of key-value pairs that represents the complete identity of an Ed-Fi document. @@ -41,7 +41,7 @@ function toBase64Url(base64: string): string { } /** - * Hashes a string with the SHAKE256, returning a Base64Url hash with the specified length given in bytes + * Hashes a string with SHAKE256, returning a Base64Url hash with the specified length given in bytes */ function toHash(data: string, lengthInBytes: number): string { return toBase64Url(crypto.createHash('shake256', { outputLength: lengthInBytes }).update(data).digest('base64')); @@ -58,9 +58,20 @@ export function resourceInfoHashFrom({ projectName, resourceName }: BaseResource * Returns the 16 byte SHAKE256 Base64Url encoded hash form of a DocumentIdentity. */ function documentIdentityHashFrom(documentIdentity: DocumentIdentity): string { - const documentIdentityString = documentIdentity - .map((element: DocumentIdentityElement) => `${element.documentKey}=${element.documentValue}`) + const documentIdentityString: string = documentIdentity + .map((element: DocumentIdentityElement) => { + const documentIdentityElementEntries: [string, any][] = Object.entries(element); + + invariant( + documentIdentityElementEntries.length === 1, + `DocumentIdentityElement for ${JSON.stringify(documentIdentity)} is invalid, must only have a single entry`, + ); + + const [documentKey, documentValue] = documentIdentityElementEntries[0]; + return `${documentKey}=${documentValue}`; + }) .join('#'); + return toHash(documentIdentityString, 16); } diff --git a/Meadowlark-js/packages/meadowlark-core/src/model/SchoolYearEnumerationDocumentInfo.ts b/Meadowlark-js/packages/meadowlark-core/src/model/SchoolYearEnumerationDocumentInfo.ts index 8435c8df..9c485d5a 100644 --- a/Meadowlark-js/packages/meadowlark-core/src/model/SchoolYearEnumerationDocumentInfo.ts +++ b/Meadowlark-js/packages/meadowlark-core/src/model/SchoolYearEnumerationDocumentInfo.ts @@ -8,18 +8,15 @@ import { DocumentIdentity } from './DocumentIdentity'; import { DocumentInfo, newDocumentInfo } from './DocumentInfo'; import { DocumentObjectKey } from './api-schema/DocumentObjectKey'; +const schoolYearKey = 'schoolYear' as DocumentObjectKey; + /** * Creates a new DocumentIdentity from the given SchoolYearEnumerationDocument */ export function schoolYearEnumerationDocumentIdentityFrom( schoolYearEnumerationDocument: SchoolYearEnumerationDocument, ): DocumentIdentity { - return [ - { - documentKey: 'schoolYear' as DocumentObjectKey, - documentValue: schoolYearEnumerationDocument.schoolYear.toString(), - }, - ]; + return [{ [schoolYearKey]: schoolYearEnumerationDocument.schoolYear.toString() }]; } /** diff --git a/Meadowlark-js/packages/meadowlark-core/test/extraction/DescriptorValueExtractor.test.ts b/Meadowlark-js/packages/meadowlark-core/test/extraction/DescriptorValueExtractor.test.ts index 13c8d16a..59f04150 100644 --- a/Meadowlark-js/packages/meadowlark-core/test/extraction/DescriptorValueExtractor.test.ts +++ b/Meadowlark-js/packages/meadowlark-core/test/extraction/DescriptorValueExtractor.test.ts @@ -68,8 +68,7 @@ describe('when extracting single descriptor value from domain entity', () => { { "documentIdentity": [ { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/grade", + "descriptor": "uri://ed-fi.org/grade", }, ], "isDescriptor": true, @@ -130,8 +129,7 @@ describe('when extracting single descriptor value from common with role name', ( { "documentIdentity": [ { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/grade", + "descriptor": "uri://ed-fi.org/grade", }, ], "isDescriptor": true, @@ -185,8 +183,7 @@ describe('when extracting descriptor values from domain entity with the same nam { "documentIdentity": [ { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/grade", + "descriptor": "uri://ed-fi.org/grade", }, ], "isDescriptor": true, @@ -249,16 +246,13 @@ describe('when extracting array of descriptor values from domain entity', () => { "documentIdentity": [ { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/grade1", + "descriptor": "uri://ed-fi.org/grade1", }, { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/grade2", + "descriptor": "uri://ed-fi.org/grade2", }, { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/grade3", + "descriptor": "uri://ed-fi.org/grade3", }, ], "isDescriptor": true, @@ -330,8 +324,7 @@ describe('when extracting collection from domain entity subclass with naming col { "documentIdentity": [ { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/schoolValue", + "descriptor": "uri://ed-fi.org/schoolValue", }, ], "isDescriptor": true, @@ -341,8 +334,7 @@ describe('when extracting collection from domain entity subclass with naming col { "documentIdentity": [ { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/edOrgValue", + "descriptor": "uri://ed-fi.org/edOrgValue", }, ], "isDescriptor": true, @@ -410,8 +402,7 @@ describe('when extracting collection from domain entity subclass with no naming { "documentIdentity": [ { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/schoolValue", + "descriptor": "uri://ed-fi.org/schoolValue", }, ], "isDescriptor": true, @@ -421,8 +412,7 @@ describe('when extracting collection from domain entity subclass with no naming { "documentIdentity": [ { - "documentKey": "descriptor", - "documentValue": "uri://ed-fi.org/edOrgValue", + "descriptor": "uri://ed-fi.org/edOrgValue", }, ], "isDescriptor": true, diff --git a/Meadowlark-js/packages/meadowlark-core/test/extraction/DocumentIdentityExtractor.test.ts b/Meadowlark-js/packages/meadowlark-core/test/extraction/DocumentIdentityExtractor.test.ts index c4ff614e..ebf013ee 100644 --- a/Meadowlark-js/packages/meadowlark-core/test/extraction/DocumentIdentityExtractor.test.ts +++ b/Meadowlark-js/packages/meadowlark-core/test/extraction/DocumentIdentityExtractor.test.ts @@ -80,20 +80,16 @@ describe('when extracting natural key from domain entity referencing another ref expect(result).toMatchInlineSnapshot(` [ { - "documentKey": "classPeriodName", - "documentValue": "z", + "classPeriodName": "z", }, { - "documentKey": "localCourseCode", - "documentValue": "abc", + "localCourseCode": "abc", }, { - "documentKey": "schoolId", - "documentValue": "23", + "schoolId": "23", }, { - "documentKey": "sectionIdentifier", - "documentValue": "Bob", + "sectionIdentifier": "Bob", }, ] `); @@ -140,12 +136,10 @@ describe('when extracting natural key from domain entity with school year in ide expect(result).toMatchInlineSnapshot(` [ { - "documentKey": "schoolYear", - "documentValue": 2022, + "schoolYear": 2022, }, { - "documentKey": "sessionName", - "documentValue": "s", + "sessionName": "s", }, ] `); @@ -190,8 +184,7 @@ describe('when extracting natural key from domain entity with school year that h expect(result).toMatchInlineSnapshot(` [ { - "documentKey": "schoolYear", - "documentValue": 2022, + "schoolYear": 2022, }, ] `); @@ -250,16 +243,13 @@ describe('when extracting document identity with two levels of identities', () = expect(result).toMatchInlineSnapshot(` [ { - "documentKey": "classPeriodName", - "documentValue": "c1", + "classPeriodName": "c1", }, { - "documentKey": "schoolId", - "documentValue": "23", + "schoolId": "23", }, { - "documentKey": "sessionName", - "documentValue": "s1", + "sessionName": "s1", }, ] `); diff --git a/Meadowlark-js/packages/meadowlark-core/test/extraction/DocumentReferenceExtractor.test.ts b/Meadowlark-js/packages/meadowlark-core/test/extraction/DocumentReferenceExtractor.test.ts index b90d5009..487b8d92 100644 --- a/Meadowlark-js/packages/meadowlark-core/test/extraction/DocumentReferenceExtractor.test.ts +++ b/Meadowlark-js/packages/meadowlark-core/test/extraction/DocumentReferenceExtractor.test.ts @@ -93,12 +93,10 @@ describe('when extracting document references from domain entity referencing one { "documentIdentity": [ { - "documentKey": "localCourseCode", - "documentValue": "abc", + "localCourseCode": "abc", }, { - "documentKey": "schoolId", - "documentValue": "23", + "schoolId": "23", }, ], "isDescriptor": false, @@ -108,12 +106,10 @@ describe('when extracting document references from domain entity referencing one { "documentIdentity": [ { - "documentKey": "classPeriodName", - "documentValue": "z1", + "classPeriodName": "z1", }, { - "documentKey": "schoolId", - "documentValue": "24", + "schoolId": "24", }, ], "isDescriptor": false, @@ -123,12 +119,10 @@ describe('when extracting document references from domain entity referencing one { "documentIdentity": [ { - "documentKey": "classPeriodName", - "documentValue": "z2", + "classPeriodName": "z2", }, { - "documentKey": "schoolId", - "documentValue": "25", + "schoolId": "25", }, ], "isDescriptor": false, @@ -183,8 +177,7 @@ describe('when extracting with optional reference in body', () => { { "documentIdentity": [ { - "documentKey": "localCourseCode", - "documentValue": "abc", + "localCourseCode": "abc", }, ], "isDescriptor": false, @@ -285,8 +278,7 @@ describe('when extracting with one optional reference in body and one not', () = { "documentIdentity": [ { - "documentKey": "localCourseCode", - "documentValue": "abc", + "localCourseCode": "abc", }, ], "isDescriptor": false, @@ -349,8 +341,7 @@ describe('when extracting optional collection in body', () => { { "documentIdentity": [ { - "documentKey": "classPeriodName", - "documentValue": "z1", + "classPeriodName": "z1", }, ], "isDescriptor": false, @@ -360,8 +351,7 @@ describe('when extracting optional collection in body', () => { { "documentIdentity": [ { - "documentKey": "classPeriodName", - "documentValue": "z2", + "classPeriodName": "z2", }, ], "isDescriptor": false, @@ -483,16 +473,13 @@ describe('when extracting document references with two levels of identities on a { "documentIdentity": [ { - "documentKey": "classPeriodName", - "documentValue": "c1", + "classPeriodName": "c1", }, { - "documentKey": "schoolId", - "documentValue": "24", + "schoolId": "24", }, { - "documentKey": "sessionName", - "documentValue": "s1", + "sessionName": "s1", }, ], "isDescriptor": false, @@ -502,16 +489,13 @@ describe('when extracting document references with two levels of identities on a { "documentIdentity": [ { - "documentKey": "classPeriodName", - "documentValue": "c2", + "classPeriodName": "c2", }, { - "documentKey": "schoolId", - "documentValue": "25", + "schoolId": "25", }, { - "documentKey": "sessionName", - "documentValue": "s2", + "sessionName": "s2", }, ], "isDescriptor": false, @@ -606,24 +590,19 @@ describe('when extracting document references with three levels of identities on { "documentIdentity": [ { - "documentKey": "classPeriodName", - "documentValue": "c1", + "classPeriodName": "c1", }, { - "documentKey": "schoolId", - "documentValue": "24", + "schoolId": "24", }, { - "documentKey": "secondLevelName", - "documentValue": "e1", + "secondLevelName": "e1", }, { - "documentKey": "sessionName", - "documentValue": "s1", + "sessionName": "s1", }, { - "documentKey": "thirdLevelName", - "documentValue": "t1", + "thirdLevelName": "t1", }, ], "isDescriptor": false, @@ -633,24 +612,19 @@ describe('when extracting document references with three levels of identities on { "documentIdentity": [ { - "documentKey": "classPeriodName", - "documentValue": "c2", + "classPeriodName": "c2", }, { - "documentKey": "schoolId", - "documentValue": "25", + "schoolId": "25", }, { - "documentKey": "secondLevelName", - "documentValue": "e2", + "secondLevelName": "e2", }, { - "documentKey": "sessionName", - "documentValue": "s2", + "sessionName": "s2", }, { - "documentKey": "thirdLevelName", - "documentValue": "t2", + "thirdLevelName": "t2", }, ], "isDescriptor": false, @@ -715,12 +689,10 @@ describe('when extracting with school year reference in body', () => { { "documentIdentity": [ { - "documentKey": "schoolYear", - "documentValue": 2022, + "schoolYear": 2022, }, { - "documentKey": "sessionName", - "documentValue": "def", + "sessionName": "def", }, ], "isDescriptor": false, @@ -821,8 +793,7 @@ describe('when extracting with school year reference in body', () => { // { // "documentIdentity": [ // { -// "documentKey": "studentUniqueId", -// "documentValue": "s0zf6d1123d3e", +// "natural": "s0zf6d1123d3e", // }, // ], // "isDescriptor": false, @@ -832,8 +803,7 @@ describe('when extracting with school year reference in body', () => { // { // "documentIdentity": [ // { -// "documentKey": "schoolId", -// "documentValue": 123, +// "schoolId": 123, // }, // ], // "isDescriptor": false, @@ -843,16 +813,13 @@ describe('when extracting with school year reference in body', () => { // { // "documentIdentity": [ // { -// "documentKey": "educationOrganizationId", -// "documentValue": 123, +// "educationOrganizationId": 123, // }, // { -// "documentKey": "graduationPlanTypeDescriptor", -// "documentValue": "uri://ed-fi.org/GraduationPlanTypeDescriptor#Minimum", +// "graduationPlanTypeDescriptor": "uri://ed-fi.org/GraduationPlanTypeDescriptor#Minimum", // }, // { -// "documentKey": "graduationSchoolYear", -// "documentValue": 2024, +// "graduationSchoolYear": 2024, // }, // ], // "isDescriptor": false, diff --git a/Meadowlark-js/packages/meadowlark-core/test/handler/FrontendRequest.test.ts b/Meadowlark-js/packages/meadowlark-core/test/handler/FrontendRequest.test.ts index 360bf152..b0c22361 100644 --- a/Meadowlark-js/packages/meadowlark-core/test/handler/FrontendRequest.test.ts +++ b/Meadowlark-js/packages/meadowlark-core/test/handler/FrontendRequest.test.ts @@ -9,7 +9,6 @@ import { newFrontendRequestMiddleware, removeReferencesDocumentIdentity, } from '../../src/handler/FrontendRequest'; -import { DocumentObjectKey } from '../../src/model/api-schema/DocumentObjectKey'; import { MetaEdProjectName } from '../../src/model/api-schema/MetaEdProjectName'; import { MetaEdResourceName } from '../../src/model/api-schema/MetaEdResourceName'; @@ -18,12 +17,10 @@ const frontendRequest: FrontendRequest = { middleware: { ...newFrontendRequestMiddleware(), documentInfo: { - documentIdentity: [{ documentKey: 'rootIdentity' as DocumentObjectKey, documentValue: 'keyRoot' }], + documentIdentity: [{ rootIdentity: 'keyRoot' }], documentReferences: [ { - documentIdentity: [ - { documentKey: 'documentReference' as DocumentObjectKey, documentValue: 'keySensitiveToBeRemoved' }, - ], + documentIdentity: [{ documentReference: 'keySensitiveToBeRemoved' }], isDescriptor: false, projectName: 'projectName' as MetaEdProjectName, resourceName: 'resourceName' as MetaEdResourceName, @@ -31,14 +28,14 @@ const frontendRequest: FrontendRequest = { ], descriptorReferences: [ { - documentIdentity: [{ documentKey: 'descriptorReference' as DocumentObjectKey, documentValue: 'keyDescriptor' }], + documentIdentity: [{ descriptorReference: 'keyDescriptor' }], isDescriptor: true, projectName: 'projectName' as MetaEdProjectName, resourceName: 'resourceName2' as MetaEdResourceName, }, ], superclassInfo: { - documentIdentity: [{ documentKey: 'superclassInfo' as DocumentObjectKey, documentValue: 'keySuperclassInfo' }], + documentIdentity: [{ superclassInfo: 'keySuperclassInfo' }], projectName: 'Test' as MetaEdProjectName, resourceName: 'resource' as MetaEdResourceName, }, diff --git a/Meadowlark-js/packages/meadowlark-core/test/validation/DocumentIdValidator.test.ts b/Meadowlark-js/packages/meadowlark-core/test/validation/DocumentIdValidator.test.ts index 0deb95a8..da062906 100644 --- a/Meadowlark-js/packages/meadowlark-core/test/validation/DocumentIdValidator.test.ts +++ b/Meadowlark-js/packages/meadowlark-core/test/validation/DocumentIdValidator.test.ts @@ -6,7 +6,6 @@ import { MeadowlarkId } from '../../src/model/IdTypes'; import { DocumentIdentity, meadowlarkIdForDocumentIdentity, resourceInfoHashFrom } from '../../src/model/DocumentIdentity'; import { BaseResourceInfo } from '../../src/model/ResourceInfo'; -import { DocumentObjectKey } from '../../src/model/api-schema/DocumentObjectKey'; import { MetaEdProjectName } from '../../src/model/api-schema/MetaEdProjectName'; import { MetaEdResourceName } from '../../src/model/api-schema/MetaEdResourceName'; @@ -36,7 +35,7 @@ describe('given a valid id', () => { resourceName: 'ResourceName' as MetaEdResourceName, }; - const validDocumentIdentity: DocumentIdentity = [{ documentKey: 'key' as DocumentObjectKey, documentValue: 'value' }]; + const validDocumentIdentity: DocumentIdentity = [{ key: 'value' }]; // Act id = meadowlarkIdForDocumentIdentity(validResourceInfo, validDocumentIdentity); @@ -68,7 +67,7 @@ describe('given a valid id with a mismatched resource info', () => { resourceName: 'MismatchedResourceName' as MetaEdResourceName, }; - const validDocumentIdentity: DocumentIdentity = [{ documentKey: 'key' as DocumentObjectKey, documentValue: 'value' }]; + const validDocumentIdentity: DocumentIdentity = [{ key: 'value' }]; // Act id = meadowlarkIdForDocumentIdentity(validResourceInfo, validDocumentIdentity);