Skip to content

Commit

Permalink
feat(hub-common): introduces tested discussion post search
Browse files Browse the repository at this point in the history
affects: @esri/hub-common
  • Loading branch information
drspacemanphd committed Feb 29, 2024
1 parent c1a3336 commit 71ed6c2
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 0 deletions.
66 changes: 66 additions & 0 deletions packages/common/test/search/_internal/hubSearchItems.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
IHubSearchOptions,
IHubSearchResponse,
IHubSearchResult,
IPost,
IPredicate,
IQuery,
} from "../../../src";
Expand All @@ -25,12 +26,14 @@ import { getOgcAggregationQueryParams } from "../../../src/search/_internal/hubS
import { getQQueryParam } from "../../../src/search/_internal/hubSearchItemsHelpers/getQQueryParam";
import { IOgcItem } from "../../../src/search/_internal/hubSearchItemsHelpers/interfaces";
import * as ogcItemToSearchResultModule from "../../../src/search/_internal/hubSearchItemsHelpers/ogcItemToSearchResult";
import * as ogcItemToDiscussionPostModule from "../../../src/search/_internal/hubSearchItemsHelpers/ogcItemToDiscussionPostResult";
import { formatOgcItemsResponse } from "../../../src/search/_internal/hubSearchItemsHelpers/formatOgcItemsResponse";
import { formatOgcAggregationsResponse } from "../../../src/search/_internal/hubSearchItemsHelpers/formatOgcAggregationsResponse";
import * as searchOgcItemsModule from "../../../src/search/_internal/hubSearchItemsHelpers/searchOgcItems";
import * as portalSearchItemsModule from "../../../src/search/_internal/portalSearchItems";
import * as fetchMock from "fetch-mock";
import {
ogcDiscussionPostResponseWithNext,
ogcItemsResponse,
ogcItemsResponseWithNext,
} from "./mocks/ogcItemsResponse";
Expand Down Expand Up @@ -75,6 +78,22 @@ describe("hubSearchItems Module |", () => {
"https://my-hub.com/api/search/v1/collections/dataset"
);
});
it("points to the V2 Discussion post collection if the targetEntity is discussionPost", () => {
const query: IQuery = {
targetEntity: "discussionPost",
filters: [],
};
const options: IHubSearchOptions = {
api: {
type: "arcgis-hub",
url: "https://my-hub.com/api/search/v2",
},
};
const result = getOgcCollectionUrl(query, options);
expect(result).toBe(
"https://my-hub.com/api/search/v2/collections/discussion-post"
);
});
});

describe("formatPredicate |", () => {
Expand Down Expand Up @@ -830,6 +849,41 @@ describe("hubSearchItems Module |", () => {
});
});

describe("ogcItemToDiscussionPostResult |", () => {
const { ogcItemToDiscussionPostResult } = ogcItemToDiscussionPostModule;

const ogcItemProperties: IPost = {
id: "12345",
title: "title",
body: "body",
status: "PENDING" as any,
appInfo: null,
discussion: null,
geometry: null,
featureGeometry: null,
postType: "Discussion" as any,
createdAt: new Date("2021-01-01"),
updatedAt: new Date("2021-01-01"),
};

it("simply returns the Post as properties", async () => {
const ogcItem: IOgcItem = {
id: "9001",
type: "Feature",
geometry: null, // for simplicity
time: null, // for simplicity
links: [], // for simplicity
properties: cloneObject(ogcItemProperties),
};
const includes: string[] = [];
const requestOptions: IHubRequestOptions = {};

const result = await ogcItemToDiscussionPostResult(ogcItem);

expect(result).toEqual(ogcItem.properties as IPost);
});
});

describe("getNextOgcCallback", () => {
const { getNextOgcCallback } = getNextOgcCallbackModule;
const query: IQuery = {
Expand Down Expand Up @@ -915,6 +969,18 @@ describe("hubSearchItems Module |", () => {
expect(formattedResponse.total).toEqual(2);
expect(formattedResponse.hasNext).toEqual(true); // Verify that hasNext is true this time
});

it("correctly handles discussion posts", async () => {
const formattedResponse = await formatOgcItemsResponse(
ogcDiscussionPostResponseWithNext,
{ targetEntity: "discussionPost", filters: [] },
requestOptions
);

expect(formattedResponse).toBeDefined();
expect(formattedResponse.total).toEqual(2);
expect(formattedResponse.hasNext).toEqual(true); // Verify that hasNext is true this time
});
});

describe("formatOgcAggregationsResponse |", () => {
Expand Down
73 changes: 73 additions & 0 deletions packages/common/test/search/_internal/mocks/ogcItemsResponse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,3 +179,76 @@ export const ogcItemsResponseWithNext: IOgcItemsResponse = {
},
],
};

export const ogcDiscussionPostResponseWithNext: IOgcItemsResponse = {
type: "FeatureCollection",
features: [
{
id: "f4bcc",
type: "Feature",
geometry: {
type: "Polygon",
coordinates: [
[
[-121.11799999999793, 39.37030746927015],
[-119.00899999999801, 39.37030746927015],
[-119.00899999999801, 38.67499450446548],
[-121.11799999999793, 38.67499450446548],
[-121.11799999999793, 39.37030746927015],
],
],
},
properties: {
id: "12345",
title: "title",
body: "body",
status: "PENDING" as any,
appInfo: null,
discussion: null,
geometry: null,
featureGeometry: null,
postType: "Discussion" as any,
createdAt: new Date("2021-01-01"),
updatedAt: new Date("2021-01-01"),
},
time: null,
links: [
{
rel: "self",
type: "application/geo+json",
title: "This document as GeoJSON",
href: "https://foo-bar.com/api/search/v2/collections/discussion-post/items/12345",
},
{
rel: "collection",
type: "application/json",
title: "discussion-post",
href: "https://foo-bar.com/api/search/v2/collections/discussion-post",
},
],
},
],
timestamp: "2023-01-23T18:53:40.715Z",
numberMatched: 2,
numberReturned: 1,
links: [
{
rel: "self",
type: "application/geo+json",
title: "This document as GeoJSON",
href: "https://foo-bar.com/api/search/v1/collections/all/items",
},
{
rel: "collection",
type: "application/json",
title: "All",
href: "https://foo-bar.com/api/search/v1/collections/all",
},
{
rel: "next",
type: "application/geo+json",
title: "items (next)",
href: "https://foo-bar.com/api/search/v1/collections/all/items?limit=1&startindex=2",
},
],
};

0 comments on commit 71ed6c2

Please sign in to comment.