Skip to content

Commit

Permalink
Merge 1da656e into 40bc5c1
Browse files Browse the repository at this point in the history
  • Loading branch information
mjuniper committed Sep 10, 2018
2 parents 40bc5c1 + 1da656e commit 9760e01
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 2 deletions.
39 changes: 39 additions & 0 deletions packages/arcgis-rest-groups/src/groups.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ export interface IGroupIdRequestOptions extends IRequestOptions {
id: string;
}

export interface IGroupNotificationRequestOptions
extends IGroupIdRequestOptions {
subject?: string;
message: string | object;
users?: string[];
notificationChannelType: string;
clientId?: string;
silentNotification?: boolean;
}

export interface IGroupAddRequestOptions extends IRequestOptions {
group: IGroupAdd;
}
Expand Down Expand Up @@ -270,3 +280,32 @@ function serializeGroup(group: IGroupAdd | IItemUpdate | IGroup): any {
clone.tags = clone.tags.join(", ");
return clone;
}

/**
* Create a group notification.
* @param requestOptions - Options for the request
* @returns A Promise that will resolve with the success/failure status of the request
*/
// see http://mediawikidev.esri.com/index.php/ArcGIS.com/User_Notifications
export function createGroupNotification(
requestOptions: IGroupNotificationRequestOptions
): Promise<any> {
const url = `${getPortalUrl(requestOptions)}/community/groups/${
requestOptions.id
}/createNotification`;

const options: IGroupNotificationRequestOptions = {
params: {
subject: requestOptions.subject,
message: requestOptions.message,
users: requestOptions.users,
notificationChannelType: requestOptions.notificationChannelType,
clientId: requestOptions.clientId,
silentNotification: requestOptions.silentNotification,
notifyAll: !requestOptions.users || requestOptions.users.length === 0,
...requestOptions.params
},
...requestOptions
};
return request(url, options);
}
45 changes: 43 additions & 2 deletions packages/arcgis-rest-groups/test/groups.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,19 @@ import {
updateGroup,
removeGroup,
protectGroup,
unprotectGroup
unprotectGroup,
createGroupNotification
} from "../src/index";

import {
GroupSearchResponse,
GroupEditResponse,
GroupResponse,
GroupContentResponse,
GroupUsersResponse
GroupUsersResponse,
GroupNotificationResponse
} from "./mocks/responses";

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

Expand Down Expand Up @@ -278,6 +281,44 @@ describe("groups", () => {
fail(e);
});
});
it("should create a group notification", done => {
fetchMock.once("*", GroupNotificationResponse);

const opts = {
id: "3ef",
subject: "this is the subject",
message: "this is the message",
notificationChannelType: "email",
...MOCK_REQOPTS
};

createGroupNotification(opts)
.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/groups/3ef/createNotification"
);
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("subject", "this is the subject")
);
expect(options.body).toContain(
encodeParam("message", "this is the message")
);
expect(options.body).toContain(
encodeParam("notificationChannelType", "email")
);
expect(options.body).toContain(encodeParam("notifyAll", true));
expect(response.success).toEqual(true);
done();
})
.catch(e => {
fail(e);
});
});
// it('should make authenticated call to get the group content', done => {})
});
});
4 changes: 4 additions & 0 deletions packages/arcgis-rest-groups/test/mocks/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,7 @@ export const GroupContentResponse: IGroupContentResult = {
}
]
};

export const GroupNotificationResponse: any = {
success: true
};

0 comments on commit 9760e01

Please sign in to comment.