-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(join): new joinGroup and leaveGroup methods
AFFECTS PACKAGES: @esri/arcgis-rest-groups
- Loading branch information
Showing
4 changed files
with
137 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* Copyright (c) 2017-2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { request, getPortalUrl } from "@esri/arcgis-rest-request"; | ||
|
||
import { IGroupIdRequestOptions } from "./helpers"; | ||
|
||
/** | ||
* ```js | ||
* import { joinGroup } from '@esri/arcgis-rest-groups'; | ||
* // | ||
* joinGroup({ | ||
* id: groupId, | ||
* authentication | ||
* }) | ||
* .then(response) | ||
* ``` | ||
* Join a Group. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/join-group.htm) for more information. | ||
* | ||
* @param requestOptions - Options for the request | ||
* @returns A Promise that will resolve with the success/failure status of the request | ||
*/ | ||
export function joinGroup( | ||
requestOptions: IGroupIdRequestOptions | ||
): Promise<{ success: boolean; groupId: string }> { | ||
const url = `${getPortalUrl(requestOptions)}/community/groups/${ | ||
requestOptions.id | ||
}/join`; | ||
const options: IGroupIdRequestOptions = { | ||
...requestOptions | ||
}; | ||
return request(url, options); | ||
} | ||
|
||
/** | ||
* ```js | ||
* import { joinGroup } from '@esri/arcgis-rest-groups'; | ||
* // | ||
* joinGroup({ | ||
* id: groupId, | ||
* authentication | ||
* }) | ||
* .then(response) | ||
* ``` | ||
* Leave a Group. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/leave-group.htm) for more information. | ||
* | ||
* @param requestOptions - Options for the request | ||
* @returns A Promise that will resolve with the success/failure status of the request | ||
*/ | ||
export function leaveGroup( | ||
requestOptions: IGroupIdRequestOptions | ||
): Promise<{ success: boolean; groupId: string }> { | ||
const url = `${getPortalUrl(requestOptions)}/community/groups/${ | ||
requestOptions.id | ||
}/leave`; | ||
const options: IGroupIdRequestOptions = { | ||
...requestOptions | ||
}; | ||
return request(url, options); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc. | ||
* Apache-2.0 */ | ||
|
||
import { joinGroup, leaveGroup } from "../src/join"; | ||
|
||
import { GroupEditResponse } from "./mocks/responses"; | ||
|
||
import { encodeParam } from "@esri/arcgis-rest-request"; | ||
import * as fetchMock from "fetch-mock"; | ||
|
||
describe("groups", () => { | ||
afterEach(fetchMock.restore); | ||
|
||
describe("authenticted methods", () => { | ||
const MOCK_AUTH = { | ||
getToken() { | ||
return Promise.resolve("fake-token"); | ||
}, | ||
portal: "https://myorg.maps.arcgis.com/sharing/rest" | ||
}; | ||
const MOCK_REQOPTS = { | ||
authentication: MOCK_AUTH | ||
}; | ||
|
||
it("should help a user join a group", done => { | ||
fetchMock.once("*", GroupEditResponse); | ||
|
||
joinGroup({ id: "5bc", ...MOCK_REQOPTS }) | ||
.then(() => { | ||
expect(fetchMock.called()).toEqual(true); | ||
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); | ||
expect(url).toEqual( | ||
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/5bc/join" | ||
); | ||
expect(options.method).toBe("POST"); | ||
expect(options.body).toContain(encodeParam("f", "json")); | ||
expect(options.body).toContain(encodeParam("token", "fake-token")); | ||
done(); | ||
}) | ||
.catch(e => { | ||
fail(e); | ||
}); | ||
}); | ||
it("should help a user leave a group", done => { | ||
fetchMock.once("*", GroupEditResponse); | ||
|
||
leaveGroup({ id: "5bc", ...MOCK_REQOPTS }) | ||
.then(() => { | ||
expect(fetchMock.called()).toEqual(true); | ||
const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); | ||
expect(url).toEqual( | ||
"https://myorg.maps.arcgis.com/sharing/rest/community/groups/5bc/leave" | ||
); | ||
expect(options.method).toBe("POST"); | ||
expect(options.body).toContain(encodeParam("f", "json")); | ||
expect(options.body).toContain(encodeParam("token", "fake-token")); | ||
done(); | ||
}) | ||
.catch(e => { | ||
fail(e); | ||
}); | ||
}); | ||
}); | ||
}); |