Skip to content

Commit

Permalink
[RND-623] test fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbanister committed Oct 18, 2023
1 parent 654abfa commit 634a8f3
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 338 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { buildBaseUrlFromRequest } from './UrlBuilder';
import { FrontendRequest } from './FrontendRequest';
import { FrontendResponse } from './FrontendResponse';
import { writeDebugStatusToLog, writeErrorToLog, writeRequestToLog } from '../Logger';
import { projectShortVersion33b } from '../api-schema/ApiSchemaLoader';

// TODO: this can be removed when we drop short version from URL
const projectShortVersion33b = 'v3.3b';

interface ExternalResource {
body: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,43 @@
import { writeDebugStatusToLog, writeRequestToLog } from '../Logger';
import { MiddlewareModel } from './MiddlewareModel';
import { DocumentInfo, NoDocumentInfo } from '../model/DocumentInfo';
import { extractDocumentInfo } from '../extraction/DocumentInfoExtractor';
import { extractDescriptorValues } from '../extraction/DescriptorValueExtractor';
import { extractDocumentIdentity } from '../extraction/DocumentIdentityExtractor';
import { extractDocumentReferences } from '../extraction/DocumentReferenceExtractor';
import { deriveSuperclassInfoFrom } from '../extraction/SuperclassInfoExtractor';
import { DocumentIdentity } from '../model/DocumentIdentity';
import { SuperclassInfo } from '../model/SuperclassInfo';
import { ApiSchema } from '../model/api-schema/ApiSchema';
import { ResourceSchema } from '../model/api-schema/ResourceSchema';

const moduleName = 'core.middleware.ExtractDocumentInfoMiddleware';

/**
* Builds a DocumentInfo using the various extractors
*/
function buildDocumentInfo(
apiSchema: ApiSchema,
resourceSchema: ResourceSchema,
body: object,
requestTimestamp: number,
): DocumentInfo {
const documentIdentity: DocumentIdentity = extractDocumentIdentity(resourceSchema, body);

let superclassInfo: SuperclassInfo | null = null;
if (!resourceSchema.isDescriptor) {
// We need to do this even if we have no body, for deletes
superclassInfo = deriveSuperclassInfoFrom(resourceSchema, documentIdentity);
}

return {
documentReferences: extractDocumentReferences(apiSchema, resourceSchema, body),
descriptorReferences: extractDescriptorValues(resourceSchema, body),
documentIdentity,
superclassInfo,
requestTimestamp,
};
}

/**
* Extracts identity and reference information from a valid JSON document
*/
Expand All @@ -21,8 +54,8 @@ export async function documentInfoExtraction({
if (frontendResponse != null) return { frontendRequest, frontendResponse };
writeRequestToLog(moduleName, frontendRequest, 'documentInfoExtraction');

const documentInfo: DocumentInfo = await extractDocumentInfo(
frontendRequest.middleware.
const documentInfo: DocumentInfo = buildDocumentInfo(
frontendRequest.middleware.apiSchema,
frontendRequest.middleware.resourceSchema,
frontendRequest.middleware.parsedBody,
frontendRequest.middleware.timestamp,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export async function endpointValidation({ frontendRequest, frontendResponse }:
writeRequestToLog(moduleName, frontendRequest, 'resourceValidation');

const { resourceSchema, resourceInfo, errorBody, headerMetadata } = await validateEndpoint(
frontendRequest.middleware.apiSchema,
frontendRequest.middleware.pathComponents,
frontendRequest.traceId,
);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

import * as DocumentInfoExtractor from '../../src/extraction/DocumentInfoExtractor';
import { documentInfoExtraction } from '../../src/middleware/ExtractDocumentInfoMiddleware';
import { FrontendResponse, newFrontendResponse } from '../../src/handler/FrontendResponse';
import { FrontendRequest, newFrontendRequest } from '../../src/handler/FrontendRequest';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('given a valid response from documentValidation for Insert', () => {
let mockDocumentValidator: any;

beforeAll(async () => {
mockDocumentValidator = jest.spyOn(DocumentValidator, 'validateDocument').mockReturnValue(Promise.resolve(null));
mockDocumentValidator = jest.spyOn(DocumentValidator, 'validateDocument').mockReturnValue(null);

// Act
resultChain = await documentValidation({ frontendRequest, frontendResponse: null });
Expand Down
Loading

0 comments on commit 634a8f3

Please sign in to comment.