Skip to content

Commit

Permalink
[RND-623] fix superclass info extractor bug
Browse files Browse the repository at this point in the history
  • Loading branch information
bradbanister committed Oct 30, 2023
1 parent 23d3354 commit dfbc541
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 7 deletions.
15 changes: 15 additions & 0 deletions Meadowlark-js/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -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", "ADMIN_KEY": "9970b045-f6fe-45b3-bda6-8bcef95695c8", "ADMIN_SECRET": "bf083bde5435ee3318cd741b1dbee86c610b6c7cdee04d5a364a3f2b98a4ad66" },
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"port": 9229
},
{
"type": "node",
"request": "launch",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
// 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 { DocumentIdentity } from '../model/DocumentIdentity';
import invariant from 'ts-invariant';
import { DocumentIdentity, DocumentIdentityElement } from '../model/DocumentIdentity';
import { SuperclassInfo } from '../model/SuperclassInfo';
import type { ResourceSchema } from '../model/api-schema/ResourceSchema';

Expand Down Expand Up @@ -33,11 +34,31 @@ export function deriveSuperclassInfoFrom(
}

// Copy the DocumentIdentity so the original is not affected
const superclassIdentity: DocumentIdentity = { ...documentIdentity };
const superclassIdentity: DocumentIdentity = [...documentIdentity];

// Replace subclassIdentityFullname with superclassIdentityFullname
delete superclassIdentity[resourceSchema.subclassIdentityFullname];
superclassIdentity[resourceSchema.superclassIdentityFullname] = documentIdentity[resourceSchema.subclassIdentityFullname];
// Find location of element for rename
const indexForRename = superclassIdentity.findIndex(
(element: DocumentIdentityElement) => element[resourceSchema.subclassIdentityDocumentKey] != null,
);
invariant(
indexForRename !== -1,
`deriveSuperclassInfoFrom found no identity element with name ${resourceSchema.subclassIdentityDocumentKey}`,
);

// Get value for renamed element
const valueForRename: any = superclassIdentity[indexForRename][resourceSchema.subclassIdentityDocumentKey];
invariant(
valueForRename != null,
`deriveSuperclassInfoFrom found no value for ${resourceSchema.subclassIdentityDocumentKey}`,
);

// Create renamed element
const renamedIdentityElement: DocumentIdentityElement = {
[resourceSchema.superclassIdentityDocumentKey]: valueForRename,
};

// Overwrite renamed element (array was cloned, so this is ok)
superclassIdentity[indexForRename] = renamedIdentityElement;

return {
resourceName: resourceSchema.superclassResourceName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ export type DomainEntitySubclassResourceSchema = AssociationSubclassResourceSche
* This is found in MetaEd as an "identity rename". MetaEd only allows the super/subclass
* relationship of Domain Entities to have a single common identity field.
*/
superclassIdentityFullname: MetaEdPropertyFullName;
subclassIdentityFullname: MetaEdPropertyFullName;
superclassIdentityDocumentKey: DocumentObjectKey;
subclassIdentityDocumentKey: DocumentObjectKey;
};

/**
Expand Down

0 comments on commit dfbc541

Please sign in to comment.