Skip to content

Commit

Permalink
simplify identity structure
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbanister committed Oct 28, 2023
1 parent fb82828 commit 7b37aaf
Show file tree
Hide file tree
Showing 26 changed files with 221 additions and 295 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
TraceId,
UpsertResult,
MetaEdResourceName,
DocumentObjectKey,
MetaEdProjectName,
} from '@edfi/meadowlark-core';
import { Collection, MongoClient } from 'mongodb';
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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<MeadowlarkDocument> = 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');
});
});

Expand All @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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,
Expand All @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand Down Expand Up @@ -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<MeadowlarkDocument> = 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');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
newFrontendRequestMiddleware,
newPathComponents,
MetaEdResourceName,
DocumentObjectKey,
} from '@edfi/meadowlark-core';
import { MongoClient } from 'mongodb';
import { getDocumentCollection, getNewClient } from '../../src/repository/Db';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
DocumentUuid,
UpdateRequest,
MetaEdResourceName,
DocumentObjectKey,
} from '@edfi/meadowlark-core';
import { Collection, MongoClient } from 'mongodb';
import { MeadowlarkDocument } from '../../src/model/MeadowlarkDocument';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
UpsertResult,
newFrontendRequestMiddleware,
newPathComponents,
DocumentObjectKey,
MetaEdResourceName,
} from '@edfi/meadowlark-core';
import { MongoClient } from 'mongodb';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import {
DocumentUuid,
UpsertResult,
MetaEdResourceName,
DocumentObjectKey,
MetaEdProjectName,
} from '@edfi/meadowlark-core';
import { ClientSession, Collection, MongoClient } from 'mongodb';
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -190,7 +189,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);

Expand Down Expand Up @@ -264,7 +263,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,
};

Expand All @@ -276,7 +275,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,
};

Expand Down Expand Up @@ -363,7 +362,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,
Expand All @@ -383,7 +382,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(
Expand Down Expand Up @@ -484,7 +483,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(
Expand All @@ -502,7 +501,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,
};

Expand All @@ -512,7 +511,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(
Expand Down Expand Up @@ -609,14 +608,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,
};
Expand All @@ -638,7 +637,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(
Expand Down Expand Up @@ -730,7 +729,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);

Expand All @@ -747,7 +746,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);
Expand Down Expand Up @@ -791,7 +790,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);
Expand All @@ -814,7 +813,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);
Expand Down Expand Up @@ -880,7 +879,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);

Expand Down
Loading

0 comments on commit 7b37aaf

Please sign in to comment.