Skip to content

Commit

Permalink
Merge pull request #380 from Esri/fix/group-access
Browse files Browse the repository at this point in the history
fix: access is required when creating a new group
  • Loading branch information
jgravois authored Nov 2, 2018
2 parents 55a6dca + 72ffd35 commit 029e648
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion packages/arcgis-rest-common-types/src/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export type GroupMembership = "owner" | "admin" | "member" | "nonmember";
*/
export interface IGroupAdd {
title: string;
access: "private" | "org" | "public";
owner?: string;
tags?: string[];
description?: string;
access?: "private" | "org" | "public";
phone?: string;
sortField?:
| "title"
Expand Down
3 changes: 2 additions & 1 deletion packages/arcgis-rest-groups/src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function serializeGroup(group: IGroupAdd | IItemUpdate | IGroup): any {
// create a clone so we're not messing with the original
const clone = JSON.parse(JSON.stringify(group));
// join and tags...
clone.tags = clone.tags.join(", ");
const { tags = [] } = group;
clone.tags = tags.join(", ");
return clone;
}
34 changes: 32 additions & 2 deletions packages/arcgis-rest-groups/test/crud.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { removeGroup } from "../src/remove";
import { GroupEditResponse } from "./mocks/responses";

import { encodeParam } from "@esri/arcgis-rest-request";
import { IGroupAdd } from "@esri/arcgis-rest-common-types";
import * as fetchMock from "fetch-mock";

describe("groups", () => {
Expand All @@ -30,8 +31,9 @@ describe("groups", () => {
title: "fake group",
owner: "fakeUser",
tags: ["foo", "bar"],
description: "my fake group"
};
description: "my fake group",
access: "public"
} as IGroupAdd;
createGroup({ group: fakeGroup, ...MOCK_REQOPTS })
.then(response => {
expect(fetchMock.called()).toEqual(true);
Expand All @@ -45,6 +47,34 @@ describe("groups", () => {
expect(options.body).toContain(encodeParam("owner", "fakeUser"));
// ensure the array props are serialized into strings
expect(options.body).toContain(encodeParam("tags", "foo, bar"));
expect(options.body).toContain(encodeParam("access", "public"));
done();
})
.catch(e => {
fail(e);
});
});

it("should create a group without an owner or tags", done => {
fetchMock.once("*", GroupEditResponse);
const fakeGroup = {
title: "bone stock fake group",
access: "org"
} as IGroupAdd;
createGroup({ group: fakeGroup, ...MOCK_REQOPTS })
.then(response => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*");
expect(url).toEqual(
"https://myorg.maps.arcgis.com/sharing/rest/community/createGroup"
);
expect(options.method).toBe("POST");
expect(options.body).toContain(encodeParam("f", "json"));
expect(options.body).toContain(encodeParam("token", "fake-token"));
expect(options.body).toContain(
encodeParam("title", "bone stock fake group")
);
expect(options.body).toContain(encodeParam("access", "org"));
done();
})
.catch(e => {
Expand Down
2 changes: 1 addition & 1 deletion packages/arcgis-rest-items/test/create.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ describe("search", () => {
const fakeItem = {
title: "my fake item",
description: "yep its fake",
snipped: "so very fake",
snippet: "so very fake",
type: "Web Mapping Application",
properties: {
key: "somevalue"
Expand Down

0 comments on commit 029e648

Please sign in to comment.