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

feat(hub-common): add createRegistration #1558

Merged
merged 10 commits into from
Jul 5, 2024
30 changes: 28 additions & 2 deletions packages/common/src/events/edit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,19 @@ import {
createEvent as createEventApi,
updateEvent as updateEventApi,
} from "./api/events";
import { deleteRegistration } from "./api";
import {
createRegistration,
deleteRegistration,
EventAttendanceType,
IRegistration,
RegistrationRole,
} from "./api";

export interface IHubCreateEventRegistration {
eventId: string;
role: RegistrationRole;
type: EventAttendanceType;
}

/**
* @private
Expand Down Expand Up @@ -118,14 +130,28 @@ export async function updateHubEvent(
return mapper.storeToEntity(model, {}) as IHubEvent;
}

/**
* @private
* Create an Event registration
* @param data
* @param requestOptions
* @returns Promise<void>
*/
export async function createHubEventRegistration(
data: IHubCreateEventRegistration,
requestOptions: IHubRequestOptions
): Promise<IRegistration> {
return await createRegistration({ data, ...requestOptions });
}

/**
* @private
* Remove an Event Attendee
* @param id event attendee id
* @param requestOptions
* @returns Promise<void>
*/
export async function deleteHubEventAttendee(
export async function deleteHubEventRegistration(
id: number,
requestOptions: IHubRequestOptions
): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ export function processAttendeeFilters(
const useElseJoin = (value: string, defaults: string[]): string =>
value?.length ? value : defaults.map((val) => val.toLowerCase()).join(",");

const userId = getOptionalPredicateStringsByKey(query.filters, "userId");
if (userId?.length) {
processedFilters.userId = userId;
}

const term = getPredicateValuesByKey(query.filters, "term");
if (term.length) {
// TODO: remove ts-ignore once GetEventsParams supports filtering by username, firstName, lastName https://devtopia.esri.com/dc/hub/issues/10153
Expand Down
47 changes: 44 additions & 3 deletions packages/common/test/events/edit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ import {
} from "../../src/events/api/types";
import {
createHubEvent,
deleteHubEventAttendee,
createHubEventRegistration,
deleteHubEventRegistration,
IHubCreateEventRegistration,
updateHubEvent,
} from "../../src/events/edit";
import { IHubEvent } from "../../src/core/types/IHubEvent";
Expand Down Expand Up @@ -342,7 +344,43 @@ describe("HubEvents edit module", () => {
});
});

describe("deleteHubEventAttendee", () => {
describe("createHubEventRegistration", () => {
it("calls createRegistration", async () => {
const authdCtxMgr = await ArcGISContextManager.create({
authentication: MOCK_AUTH,
currentUser: {
username: "casey",
} as unknown as PortalModule.IUser,
portal: {
name: "DC R&D Center",
id: "BRXFAKE",
urlKey: "fake-org",
} as unknown as PortalModule.IPortal,
portalUrl: "https://myserver.com",
});
const createRegistrationSpy = spyOn(
registrationModule,
"createRegistration"
).and.callFake(() => {
return Promise.resolve();
});
const data: IHubCreateEventRegistration = {
eventId: "0o1",
role: registrationModule.RegistrationRole.ATTENDEE,
type: registrationModule.EventAttendanceType.IN_PERSON,
};
await createHubEventRegistration(
data,
authdCtxMgr.context.hubRequestOptions
);
expect(createRegistrationSpy).toHaveBeenCalledWith({
data,
...authdCtxMgr.context.hubRequestOptions,
});
});
});

describe("deleteHubEventRegistration", () => {
it("calls deleteRegistration", async () => {
const authdCtxMgr = await ArcGISContextManager.create({
authentication: MOCK_AUTH,
Expand All @@ -362,7 +400,10 @@ describe("HubEvents edit module", () => {
).and.callFake(() => {
return Promise.resolve();
});
await deleteHubEventAttendee(0o1, authdCtxMgr.context.hubRequestOptions);
await deleteHubEventRegistration(
0o1,
authdCtxMgr.context.hubRequestOptions
);
expect(deleteRegistrationSpy).toHaveBeenCalledWith({
registrationId: 0o1,
...authdCtxMgr.context.hubRequestOptions,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ const FILTERS: IFilter[] = [
},
],
},
{
predicates: [
{
userId: "user1",
},
],
},
{
operation: "OR",
predicates: [
Expand Down Expand Up @@ -75,6 +82,7 @@ describe("processAttendeeFilters", () => {
});
expect(results).toEqual({
eventId: "an event id",
userId: "user1",
// @ts-ignore
name: "abc",
role: "owner,organizer,attendee",
Expand Down
Loading