Skip to content

Commit

Permalink
[RND-623] initial matchup to MetaEd api-schema plugin (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbanister authored Nov 6, 2023
1 parent 1a253de commit 9be8824
Show file tree
Hide file tree
Showing 161 changed files with 108,814 additions and 6,740 deletions.
2 changes: 2 additions & 0 deletions Meadowlark-js/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ MONGODB_MAX_NUMBER_OF_RETRIES=1
#### Environment variables for security
OWN_OAUTH_CLIENT_ID_FOR_CLIENT_AUTH=meadowlark_verify-only_key_1
OWN_OAUTH_CLIENT_SECRET_FOR_CLIENT_AUTH=meadowlark_verify-only_secret_1
## URLs may need to be 127.0.0.1 instead of localhost depending on Node version
OAUTH_SERVER_ENDPOINT_FOR_OWN_TOKEN_REQUEST=http://localhost:3000/local/oauth/token
OAUTH_SERVER_ENDPOINT_FOR_TOKEN_VERIFICATION=http://localhost:3000/local/oauth/verify

LOG_PRETTY_PRINT=true


Expand Down
17 changes: 16 additions & 1 deletion Meadowlark-js/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"type": "node",
"request": "launch",
"runtimeArgs": ["--inspect", "--debug-port=9229"],
"env": {"FASTIFY_NUM_THREADS": "1", "OAUTH_HARD_CODED_CREDENTIALS_ENABLED": "true"},
"env": {"FASTIFY_NUM_THREADS": "1", "FASTIFY_PORT": "3000", "OAUTH_HARD_CODED_CREDENTIALS_ENABLED": "true" },
"program": "${workspaceFolder}/services/meadowlark-fastify/dist/index.js",
"port": 9229,
"console": "integratedTerminal",
Expand All @@ -27,6 +27,21 @@
"internalConsoleOptions": "neverOpen",
"port": 9229
},
{
"name": "Jest :: File Linux e2e",
"type": "node",
"request": "launch",
"runtimeArgs": [
"--inspect-brk",
"${workspaceRoot}/node_modules/.bin/jest",
"--runInBand",
"${relativeFile}",
],
"env": {"FASTIFY_PORT": "3000" },
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
},
{
"type": "node",
"request": "launch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,19 @@ import {
AuthorizationStrategy,
TraceId,
ResourceInfo,
MetaEdProjectName,
MetaEdResourceName,
SemVer,
} from '@edfi/meadowlark-core';
import { queryDocuments, indexFromResourceInfo } from '../src/repository/QueryElasticsearch';

const mock = new Mock();

const resourceInfo: ResourceInfo = {
projectName: 'ed-fi',
resourceName: 'student',
projectName: 'ed-fi' as MetaEdProjectName,
resourceName: 'student' as MetaEdResourceName,
isDescriptor: false,
resourceVersion: '3.3.1-b',
resourceVersion: '3.3.1-b' as SemVer,
allowIdentityUpdates: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,14 @@ import {
AuthorizationStrategy,
DeleteRequest,
DeleteResult,
generateDocumentUuid,
DocumentUuid,
MeadowlarkId,
TraceId,
MetaEdProjectName,
MetaEdResourceName,
SemVer,
} from '@edfi/meadowlark-core';
import { DocumentUuid, MeadowlarkId, TraceId } from '@edfi/meadowlark-core/src/model/IdTypes';
import { generateDocumentUuid } from '@edfi/meadowlark-core/src/model/DocumentIdentity';
import { Client } from '@elastic/elasticsearch';
import { queryDocuments } from '../../src/repository/QueryElasticsearch';
import { afterDeleteDocumentById, afterUpsertDocument } from '../../src/repository/UpdateElasticsearch';
Expand All @@ -25,10 +30,10 @@ import { getNewTestClient } from '../setup/ElasticSearchSetupEnvironment';
jest.setTimeout(120_000);

const resourceInfo: ResourceInfo = {
projectName: 'ed-fi',
resourceName: 'student',
projectName: 'ed-fi' as MetaEdProjectName,
resourceName: 'student' as MetaEdResourceName,
isDescriptor: false,
resourceVersion: '3.3.1-b',
resourceVersion: '3.3.1-b' as SemVer,
allowIdentityUpdates: false,
};

Expand Down Expand Up @@ -130,7 +135,7 @@ describe('When querying for documents', () => {
describe('when querying with wrong resource info', () => {
it('should return invalid query', async () => {
const invalidResourceInfo = { ...resourceInfo };
invalidResourceInfo.projectName = 'wrong-project';
invalidResourceInfo.projectName = 'wrong-project' as MetaEdProjectName;
const result = await queryDocuments(setupQueryRequest({}, {}, invalidResourceInfo), client);

expect(result.response).toEqual('QUERY_FAILURE_INDEX_NOT_FOUND');
Expand Down Expand Up @@ -237,10 +242,10 @@ describe('When querying for documents', () => {

describe('when querying for descriptor', () => {
const descriptorResourceInfo: ResourceInfo = {
projectName: 'ed-fi',
resourceName: 'countryDescriptor',
projectName: 'ed-fi' as MetaEdProjectName,
resourceName: 'countryDescriptor' as MetaEdResourceName,
isDescriptor: true,
resourceVersion: '3.3.1-b',
resourceVersion: '3.3.1-b' as SemVer,
allowIdentityUpdates: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ import {
DeleteResult,
DocumentUuid,
MeadowlarkId,
MetaEdProjectName,
MetaEdResourceName,
newSecurity,
NoDocumentInfo,
PaginationParameters,
QueryRequest,
ResourceInfo,
SemVer,
TraceId,
UpdateRequest,
UpdateResult,
Expand All @@ -31,10 +34,10 @@ import { getNewTestClient } from '../setup/ElasticSearchSetupEnvironment';
jest.setTimeout(120_000);

const resourceInfo: ResourceInfo = {
projectName: 'ed-fi',
resourceName: 'student',
projectName: 'ed-fi' as MetaEdProjectName,
resourceName: 'student' as MetaEdResourceName,
isDescriptor: false,
resourceVersion: '3.3.1-b',
resourceVersion: '3.3.1-b' as SemVer,
allowIdentityUpdates: false,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import {
MeadowlarkId,
ResourceInfo,
DocumentUuid,
MetaEdProjectName,
MetaEdResourceName,
SemVer,
} from '@edfi/meadowlark-core';

export interface MeadowlarkDocumentId {
Expand All @@ -36,19 +39,19 @@ export interface MeadowlarkDocument extends MeadowlarkDocumentId {
/**
* The MetaEd project name the API document resource is defined in e.g. "EdFi" for a data standard entity.
*/
projectName: string;
projectName: MetaEdProjectName;

/**
* The name of the resource. Typically, this is the same as the corresponding MetaEd entity name. However,
* there are exceptions, for example descriptors have a "Descriptor" suffix on their resource name.
*/
resourceName: string;
resourceName: MetaEdResourceName;

/**
* The resource version as a string. This is the same as the MetaEd project version
* the entity is defined in e.g. "3.3.1-b" for a 3.3b data standard entity.
*/
resourceVersion: string;
resourceVersion: SemVer;

/**
* The Ed-Fi ODS/API document itself.
Expand Down Expand Up @@ -96,12 +99,12 @@ export interface MeadowlarkDocument extends MeadowlarkDocumentId {
createdBy: string;

/*
* Creation date as as Unix timestamp, or null if this is a document to be updated and we don't know the create time yet
* Creation date as a Unix timestamp, or null if this is a document to be updated and we don't know the create time yet
*/
createdAt: number | null;

/*
* Last modified date as as Unix timestamp.
* Last modified date as a Unix timestamp.
*/
lastModifiedAt: number;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ export const setupConfigForIntegration = async () => {
return;
}

const path = join(process.cwd(), '.env');
// First look for .env file paired with this Config.ts file
let path = join(__dirname, '.env');

if (!existsSync(path)) {
path = join(process.cwd(), '.env');
}

if (!existsSync(path)) {
// eslint-disable-next-line no-console
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import {
MeadowlarkId,
TraceId,
UpsertResult,
MetaEdResourceName,
MetaEdProjectName,
} from '@edfi/meadowlark-core';
import { Collection, MongoClient } from 'mongodb';
import { MeadowlarkDocument } from '../../src/model/MeadowlarkDocument';
Expand Down Expand Up @@ -53,7 +55,7 @@ describe('given the delete of a non-existent document', () => {

const resourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'School',
resourceName: 'School' as MetaEdResourceName,
};

beforeAll(async () => {
Expand Down Expand Up @@ -84,11 +86,11 @@ describe('given the delete of an existing document', () => {

const resourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'School',
resourceName: 'School' as MetaEdResourceName,
};
const documentInfo: DocumentInfo = {
...newDocumentInfo(),
documentIdentity: { natural: 'delete2' },
documentIdentity: [{ natural: 'delete2' }],
};

beforeAll(async () => {
Expand Down Expand Up @@ -135,12 +137,12 @@ describe('given the delete of a document referenced by an existing document with

const referencedResourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'School',
resourceName: 'School' as MetaEdResourceName,
};

const referencedDocumentInfo: DocumentInfo = {
...newDocumentInfo(),
documentIdentity: { natural: 'delete5' },
documentIdentity: [{ natural: 'delete5' }],
};
const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity(
referencedResourceInfo,
Expand All @@ -156,11 +158,11 @@ describe('given the delete of a document referenced by an existing document with

const documentWithReferencesResourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'AcademicWeek',
resourceName: 'AcademicWeek' as MetaEdResourceName,
};
const documentWithReferencesInfo: DocumentInfo = {
...newDocumentInfo(),
documentIdentity: { natural: 'delete6' },
documentIdentity: [{ natural: 'delete6' }],
documentReferences: [validReference],
};
const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity(
Expand Down Expand Up @@ -218,7 +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.natural).toBe('delete5');
expect(result.documentIdentity[0].natural).toBe('delete5');
});
});

Expand All @@ -229,12 +231,12 @@ describe('given an delete of a document with an outbound reference only, with va

const referencedResourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'AcademicWeek',
resourceName: 'AcademicWeek' as MetaEdResourceName,
};

const referencedDocumentInfo: DocumentInfo = {
...newDocumentInfo(),
documentIdentity: { natural: 'delete15' },
documentIdentity: [{ natural: 'delete15' }],
};
const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity(
referencedResourceInfo,
Expand All @@ -250,11 +252,11 @@ describe('given an delete of a document with an outbound reference only, with va

const documentWithReferencesResourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'School',
resourceName: 'School' as MetaEdResourceName,
};
const documentWithReferencesInfo: DocumentInfo = {
...newDocumentInfo(),
documentIdentity: { natural: 'delete16' },
documentIdentity: [{ natural: 'delete16' }],
documentReferences: [validReference],
};
const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity(
Expand Down Expand Up @@ -323,11 +325,11 @@ describe('given the delete of a document referenced by an existing document with

const referencedResourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'School',
resourceName: 'School' as MetaEdResourceName,
};
const referencedDocumentInfo: DocumentInfo = {
...newDocumentInfo(),
documentIdentity: { natural: 'delete5' },
documentIdentity: [{ natural: 'delete5' }],
};
const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity(
referencedResourceInfo,
Expand All @@ -343,11 +345,11 @@ describe('given the delete of a document referenced by an existing document with

const documentWithReferencesResourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'AcademicWeek',
resourceName: 'AcademicWeek' as MetaEdResourceName,
};
const documentWithReferencesInfo: DocumentInfo = {
...newDocumentInfo(),
documentIdentity: { natural: 'delete6' },
documentIdentity: [{ natural: 'delete6' }],
documentReferences: [validReference],
};
const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity(
Expand Down Expand Up @@ -416,20 +418,20 @@ describe('given the delete of a subclass document referenced by an existing docu

const referencedResourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'School',
projectName: 'Ed-Fi',
resourceName: 'School' as MetaEdResourceName,
projectName: 'Ed-Fi' as MetaEdProjectName,
};

const superclassInfo: SuperclassInfo = {
...newSuperclassInfo(),
documentIdentity: { educationOrganizationId: '123' },
resourceName: 'EducationOrganization',
projectName: 'Ed-Fi',
documentIdentity: [{ educationOrganizationId: '123' }],
resourceName: 'EducationOrganization' as MetaEdResourceName,
projectName: 'Ed-Fi' as MetaEdProjectName,
};

const referencedDocumentInfo: DocumentInfo = {
...newDocumentInfo(),
documentIdentity: { schoolId: '123' },
documentIdentity: [{ schoolId: '123' }],
superclassInfo,
};
const referencedMeadowlarkId = meadowlarkIdForDocumentIdentity(
Expand All @@ -446,11 +448,11 @@ describe('given the delete of a subclass document referenced by an existing docu

const documentWithReferenceResourceInfo: ResourceInfo = {
...newResourceInfo(),
resourceName: 'AcademicWeek',
resourceName: 'AcademicWeek' as MetaEdResourceName,
};
const documentWithReferenceDocumentInfo: DocumentInfo = {
...newDocumentInfo(),
documentIdentity: { week: 'delete6' },
documentIdentity: [{ week: 'delete6' }],
documentReferences: [referenceAsSuperclass],
};
const documentWithReferencesMeadowlarkId = meadowlarkIdForDocumentIdentity(
Expand Down Expand Up @@ -508,6 +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.schoolId).toBe('123');
expect(result.documentIdentity[0].schoolId).toBe('123');
});
});
Loading

0 comments on commit 9be8824

Please sign in to comment.