Skip to content

Commit

Permalink
Merge pull request #682 from Esri/f/getGroupCategorySchema
Browse files Browse the repository at this point in the history
Added getGroupCategorySchema
  • Loading branch information
tomwayson authored Apr 6, 2020
2 parents ef4e404 + ed7c3d5 commit 66ce599
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 0 deletions.
34 changes: 34 additions & 0 deletions packages/arcgis-rest-portal/src/groups/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,16 @@ import {
import { IPagingParams, IGroup, IItem, IUser } from "@esri/arcgis-rest-types";
import { getPortalUrl } from "../util/get-portal-url";

export interface IGroupCategorySchema {
categorySchema: IGroupCategory[];
}

export interface IGroupCategory {
title: string;
description?: string;
categories?: IGroupCategory[];
}

export interface IGetGroupContentOptions extends IRequestOptions {
paging: IPagingParams;
}
Expand Down Expand Up @@ -53,6 +63,30 @@ export function getGroup(
return request(url, options);
}

/**
* Gets the category schema set on a group
*
* @param id - Group Id
* @param requestOptions - Options for the request
* @returns A promise that will resolve with JSON of group's category schema
* @see https://developers.arcgis.com/rest/users-groups-and-items/group-category-schema.htm
*/
export function getGroupCategorySchema(
id: string,
requestOptions?: IRequestOptions
): Promise<IGroupCategorySchema> {
const url = `${getPortalUrl(
requestOptions
)}/community/groups/${id}/categorySchema`;

// default to a GET request
const options: IRequestOptions = {
...{ httpMethod: "GET" },
...requestOptions
};
return request(url, options);
}

/**
* Returns the content of a Group. Since the group may contain 1000s of items
* the requestParams allow for paging.
Expand Down
21 changes: 21 additions & 0 deletions packages/arcgis-rest-portal/test/groups/get.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@

import {
getGroup,
getGroupCategorySchema,
getGroupContent,
getGroupUsers,
searchGroupUsers
} from "../../src/groups/get";

import {
GroupResponse,
GroupCategorySchemaResponse,
GroupContentResponse,
GroupUsersResponse,
SearchGroupUsersResponse
Expand Down Expand Up @@ -39,6 +41,25 @@ describe("groups", () => {
});
});

describe("getGroupCategorySchema", () => {
it("should return group's category schema", done => {
fetchMock.once("*", GroupCategorySchemaResponse);
getGroupCategorySchema("3ef")
.then(response => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
"https://www.arcgis.com/sharing/rest/community/groups/3ef/categorySchema?f=json"
);
expect(options.method).toBe("GET");
done();
})
.catch(e => {
fail(e);
});
});
});

describe("getGroupContent", () => {
it("should return group content", done => {
fetchMock.once("*", GroupContentResponse);
Expand Down
36 changes: 36 additions & 0 deletions packages/arcgis-rest-portal/test/mocks/groups/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import { ISearchResult } from "../../../src/util/search";
import {
IGroupCategorySchema,
IGroupContentResult,
IGroupUsersResult,
ISearchGroupUsersResult
Expand Down Expand Up @@ -90,6 +91,41 @@ export const GroupResponse: IGroup = {
notificationsEnabled: false
};

// JSON Response Example from https://developers.arcgis.com/rest/users-groups-and-items/group-category-schema.htm
export const GroupCategorySchemaResponse: IGroupCategorySchema = {
categorySchema: [
{
title: "Categories",
categories: [
{
title: "Basemaps",
categories: [
{ title: "Partner Basemap" },
{
title: "Esri Basemaps",
categories: [
{ title: "Esri Raster Basemap" },
{ title: "Esri Vector Basemap" }
]
}
]
},
{
title: "Imagery",
categories: [
{ title: "Multispectral Imagery" },
{ title: "Temporal Imagery" }
]
}
]
},
{
title: "Region",
categories: [{ title: "US" }, { title: "World" }]
}
]
};

export const GroupContentResponse: IGroupContentResult = {
total: 36,
start: 1,
Expand Down

0 comments on commit 66ce599

Please sign in to comment.