Skip to content

Commit

Permalink
fix: getIncludesAndReferencesQuery accounts for no association group (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannemarik committed Jul 1, 2024
1 parent ad0dd5b commit 7f1d64c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ export const getIncludesAndReferencesQuery = async (
context: IArcGISContext
): Promise<IQuery> => {
if (isParent) {
/**
* 0. exit early if the parent's association group
* hasn't been created yet - there can be no associations
*/
if (!getProp(entity, "associations")) {
return null;
}

/**
* 1. build query that returns child entities WITH a
* typeKeyword reference to the parent
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
import { cloneObject } from "../../../src";
import { HubEntity, cloneObject } from "../../../src";
import { IArcGISContext } from "../../../src/ArcGISContext";
import { getIncludesAndReferencesQuery } from "../../../src/associations/internal/getIncludesAndReferencesQuery";
import { MOCK_PARENT_ENTITY, MOCK_CHILD_ENTITY } from "../fixtures";
import * as ItemsModule from "@esri/arcgis-rest-portal";

describe("getIncludesAndReferencesQuery:", () => {
describe("from the parent entity perspective", () => {
it("returns null if the parent's association group hasn't been created yet", async () => {
const query = await getIncludesAndReferencesQuery(
{} as HubEntity,
"project",
true,
{} as IArcGISContext
);

expect(query).toBeNull();
});
it("returns a valid IQuery to fetch child entities", async () => {
const query = await getIncludesAndReferencesQuery(
MOCK_PARENT_ENTITY,
Expand Down

0 comments on commit 7f1d64c

Please sign in to comment.