Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: access is required when creating a new group #380

Merged
merged 3 commits into from
Nov 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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