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 705309c
Show file tree
Hide file tree
Showing 26 changed files with 254 additions and 361 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
Loading

0 comments on commit 705309c

Please sign in to comment.