-
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.
Merge pull request #494 from Esri/feat/joinGroup
feat: new joinGroup and leaveGroup methods
- Loading branch information
Showing
8 changed files
with
193 additions
and
32 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
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,56 @@ | ||
/* 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) | ||
* ``` | ||
* Make a request as the authenticated user to 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 and the groupId. | ||
*/ | ||
export function joinGroup( | ||
requestOptions: IGroupIdRequestOptions | ||
): Promise<{ success: boolean; groupId: string }> { | ||
const url = `${getPortalUrl(requestOptions)}/community/groups/${ | ||
requestOptions.id | ||
}/join`; | ||
|
||
return request(url, requestOptions); | ||
} | ||
|
||
/** | ||
* ```js | ||
* import { leaveGroup } from '@esri/arcgis-rest-groups'; | ||
* // | ||
* leaveGroup({ | ||
* id: groupId, | ||
* authentication | ||
* }) | ||
* .then(response) | ||
* ``` | ||
* Make a request as the authenticated user to 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 and the groupId. | ||
*/ | ||
export function leaveGroup( | ||
requestOptions: IGroupIdRequestOptions | ||
): Promise<{ success: boolean; groupId: string }> { | ||
const url = `${getPortalUrl(requestOptions)}/community/groups/${ | ||
requestOptions.id | ||
}/leave`; | ||
|
||
return request(url, requestOptions); | ||
} |
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
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,72 @@ | ||
/* 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 { UserSession } from "@esri/arcgis-rest-auth"; | ||
import { TOMORROW } from "@esri/arcgis-rest-auth/test/utils"; | ||
|
||
import * as fetchMock from "fetch-mock"; | ||
|
||
describe("groups", () => { | ||
afterEach(fetchMock.restore); | ||
|
||
describe("authenticted methods", () => { | ||
const MOCK_REQOPTS = { | ||
authentication: new UserSession({ | ||
clientId: "clientId", | ||
redirectUri: "https://example-app.com/redirect-uri", | ||
token: "fake-token", | ||
tokenExpires: TOMORROW, | ||
refreshToken: "refreshToken", | ||
refreshTokenExpires: TOMORROW, | ||
refreshTokenTTL: 1440, | ||
username: "casey", | ||
password: "123456", | ||
portal: "https://myorg.maps.arcgis.com/sharing/rest" | ||
}) | ||
}; | ||
|
||
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); | ||
}); | ||
}); | ||
}); | ||
}); |
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