Skip to content

Commit

Permalink
Merge pull request #102 from hudl/SK24-SkippedCanceledEvents
Browse files Browse the repository at this point in the history
Filter out canceled events from updates
  • Loading branch information
vstehlik authored Oct 25, 2024
2 parents 7936b0f + a32d03e commit a02bdad
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 45 deletions.
90 changes: 45 additions & 45 deletions src/__tests__/updateOne.tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ describe('updateOne', () => {
test('skips updates for snoozed users', () => {
updateOne({ ...baseUserSettings, snoozed: true });

expect(setUserStatusMock).not.toBeCalled();
expect(setUserPresenceMock).not.toBeCalled();
expect(upsertCurrentEventMock).not.toBeCalled();
expect(postMessageMock).not.toBeCalled();
expect(setUserStatusMock).not.toHaveBeenCalled();
expect(setUserPresenceMock).not.toHaveBeenCalled();
expect(upsertCurrentEventMock).not.toHaveBeenCalled();
expect(postMessageMock).not.toHaveBeenCalled();
});

describe('updating Slack status', () => {
Expand All @@ -82,25 +82,25 @@ describe('updateOne', () => {
test('does not update Slack status', async () => {
await updateOne(baseUserSettings);

expect(setUserStatusMock).not.toBeCalled();
expect(setUserPresenceMock).not.toBeCalled();
expect(setUserStatusMock).not.toHaveBeenCalled();
expect(setUserPresenceMock).not.toHaveBeenCalled();
});
test('does not update DynamoDB', async () => {
await updateOne(baseUserSettings);

expect(upsertCurrentEventMock).not.toBeCalled();
expect(removeCurrentEventMock).not.toBeCalled();
expect(upsertCurrentEventMock).not.toHaveBeenCalled();
expect(removeCurrentEventMock).not.toHaveBeenCalled();
});
});
describe('and a current event', () => {
test('clears Slack status', async () => {
await updateOne(userWithCurrentEvent);

expect(setUserStatusMock).toBeCalledWith(userWithCurrentEvent.email, userWithCurrentEvent.slackToken, {
expect(setUserStatusMock).toHaveBeenCalledWith(userWithCurrentEvent.email, userWithCurrentEvent.slackToken, {
text: '',
emoji: '',
});
expect(setUserPresenceMock).toBeCalledWith(
expect(setUserPresenceMock).toHaveBeenCalledWith(
userWithCurrentEvent.email,
userWithCurrentEvent.slackToken,
'auto',
Expand All @@ -109,7 +109,7 @@ describe('updateOne', () => {
test('removes event in DynamoDB', async () => {
await updateOne(userWithCurrentEvent);

expect(removeCurrentEventMock).toBeCalledWith(userWithCurrentEvent.email);
expect(removeCurrentEventMock).toHaveBeenCalledWith(userWithCurrentEvent.email);
});
});
});
Expand All @@ -122,14 +122,14 @@ describe('updateOne', () => {
test('does not update Slack status', async () => {
await updateOne(userWithCurrentEvent);

expect(setUserStatusMock).not.toBeCalled();
expect(setUserPresenceMock).not.toBeCalled();
expect(setUserStatusMock).not.toHaveBeenCalled();
expect(setUserPresenceMock).not.toHaveBeenCalled();
});
test('does not update DynamoDB', async () => {
await updateOne(userWithCurrentEvent);

expect(upsertCurrentEventMock).not.toBeCalled();
expect(removeCurrentEventMock).not.toBeCalled();
expect(upsertCurrentEventMock).not.toHaveBeenCalled();
expect(removeCurrentEventMock).not.toHaveBeenCalled();
});
});
describe('that does not match the current event', () => {
Expand All @@ -140,11 +140,11 @@ describe('updateOne', () => {
test('updates Slack status to OOO', async () => {
await updateOne(userWithCurrentEvent);

expect(setUserStatusMock).toBeCalledWith(userWithCurrentEvent.email, userWithCurrentEvent.slackToken, {
expect(setUserStatusMock).toHaveBeenCalledWith(userWithCurrentEvent.email, userWithCurrentEvent.slackToken, {
text: 'OOO until Saturday, January 4',
emoji: ':ooo:',
});
expect(setUserPresenceMock).toBeCalledWith(
expect(setUserPresenceMock).toHaveBeenCalledWith(
userWithCurrentEvent.email,
userWithCurrentEvent.slackToken,
'away',
Expand All @@ -153,7 +153,7 @@ describe('updateOne', () => {
test('sets the current event to the new event DynamoDB', async () => {
await updateOne(userWithCurrentEvent);

expect(upsertCurrentEventMock).toBeCalledWith(userWithCurrentEvent.email, oooEvent);
expect(upsertCurrentEventMock).toHaveBeenCalledWith(userWithCurrentEvent.email, oooEvent);
});
});
});
Expand All @@ -176,14 +176,14 @@ describe('updateOne', () => {
test('does not update Slack status', async () => {
await updateOne(userWithCurrentEvent);

expect(setUserStatusMock).not.toBeCalled();
expect(setUserPresenceMock).not.toBeCalled();
expect(setUserStatusMock).not.toHaveBeenCalled();
expect(setUserPresenceMock).not.toHaveBeenCalled();
});
test('does not update DynamoDB', async () => {
await updateOne(userWithCurrentEvent);

expect(upsertCurrentEventMock).not.toBeCalled();
expect(removeCurrentEventMock).not.toBeCalled();
expect(upsertCurrentEventMock).not.toHaveBeenCalled();
expect(removeCurrentEventMock).not.toHaveBeenCalled();
});
});

Expand All @@ -195,11 +195,11 @@ describe('updateOne', () => {
test('updates Slack status to event with highest-priority ShowAs', async () => {
await updateOne(userWithCurrentEvent);

expect(setUserStatusMock).toBeCalledWith(userWithCurrentEvent.email, userWithCurrentEvent.slackToken, {
expect(setUserStatusMock).toHaveBeenCalledWith(userWithCurrentEvent.email, userWithCurrentEvent.slackToken, {
text: 'OOO until Saturday, January 4',
emoji: ':ooo:',
});
expect(setUserPresenceMock).toBeCalledWith(
expect(setUserPresenceMock).toHaveBeenCalledWith(
userWithCurrentEvent.email,
userWithCurrentEvent.slackToken,
'away',
Expand All @@ -208,7 +208,7 @@ describe('updateOne', () => {
test('sets the current event to event with highest-priority ShowAs in DynamoDB', async () => {
await updateOne(userWithCurrentEvent);

expect(upsertCurrentEventMock).toBeCalledWith(userWithCurrentEvent.email, oooEvent);
expect(upsertCurrentEventMock).toHaveBeenCalledWith(userWithCurrentEvent.email, oooEvent);
});
});

Expand All @@ -228,11 +228,11 @@ describe('updateOne', () => {
test('updates Slack status to event with latest start time', async () => {
await updateOne(userWithCurrentEvent);

expect(setUserStatusMock).toBeCalledWith(userWithCurrentEvent.email, userWithCurrentEvent.slackToken, {
expect(setUserStatusMock).toHaveBeenCalledWith(userWithCurrentEvent.email, userWithCurrentEvent.slackToken, {
text: 'Away',
emoji: ':spiral_calendar_pad:',
});
expect(setUserPresenceMock).toBeCalledWith(
expect(setUserPresenceMock).toHaveBeenCalledWith(
userWithCurrentEvent.email,
userWithCurrentEvent.slackToken,
'away',
Expand All @@ -241,7 +241,7 @@ describe('updateOne', () => {
test('sets the current event to event with latest start time in DynamoDB', async () => {
await updateOne(userWithCurrentEvent);

expect(upsertCurrentEventMock).toBeCalledWith(userWithCurrentEvent.email, busyEvent);
expect(upsertCurrentEventMock).toHaveBeenCalledWith(userWithCurrentEvent.email, busyEvent);
});
});
});
Expand All @@ -256,27 +256,27 @@ describe('updateOne', () => {
test('sends a Slack reminder', async () => {
await updateOne(userWithCurrentEvent);

expect(postMessageMock).toBeCalledWith(botToken, {
expect(postMessageMock).toHaveBeenCalledWith(botToken, {
text: 'You have an upcoming meeting: *meetings* at https://my.test.url',
channel: slackUser.id,
});
});
test('updates the last reminder event ID in DynamoDB', async () => {
await updateOne(userWithCurrentEvent);

expect(setLastReminderEventIdMock).toBeCalledWith(userWithCurrentEvent.email, oooEvent.id);
expect(setLastReminderEventIdMock).toHaveBeenCalledWith(userWithCurrentEvent.email, oooEvent.id);
});
});
describe('and the user has been sent a reminder', () => {
test('does not send a Slack reminder', async () => {
await updateOne({ ...userWithCurrentEvent, lastReminderEventId: oooEvent.id });

expect(postMessageMock).not.toBeCalled();
expect(postMessageMock).not.toHaveBeenCalled();
});
test('does not update the last reminder event ID in DynamoDB', async () => {
await updateOne({ ...userWithCurrentEvent, lastReminderEventId: oooEvent.id });

expect(setLastReminderEventIdMock).not.toBeCalled();
expect(setLastReminderEventIdMock).not.toHaveBeenCalled();
});
});
});
Expand All @@ -287,12 +287,12 @@ describe('updateOne', () => {
test('does not send a Slack reminder', async () => {
await updateOne(userWithCurrentEvent);

expect(postMessageMock).not.toBeCalled();
expect(postMessageMock).not.toHaveBeenCalled();
});
test('does not update the last reminder event ID in DynamoDB', async () => {
await updateOne(userWithCurrentEvent);

expect(setLastReminderEventIdMock).not.toBeCalled();
expect(setLastReminderEventIdMock).not.toHaveBeenCalled();
});
});
describe('and no upcoming meeting', () => {
Expand All @@ -302,12 +302,12 @@ describe('updateOne', () => {
test('does not send a Slack reminder', async () => {
await updateOne(userWithCurrentEvent);

expect(postMessageMock).not.toBeCalled();
expect(postMessageMock).not.toHaveBeenCalled();
});
test('does not update the last reminder event ID in DynamoDB', async () => {
await updateOne(userWithCurrentEvent);

expect(setLastReminderEventIdMock).not.toBeCalled();
expect(setLastReminderEventIdMock).not.toHaveBeenCalled();
});
});
});
Expand All @@ -322,27 +322,27 @@ describe('updateOne', () => {
test('sends a Slack reminder', async () => {
await updateOne(overrideUser);

expect(postMessageMock).toBeCalledWith(botToken, {
expect(postMessageMock).toHaveBeenCalledWith(botToken, {
text: 'You have an upcoming meeting: *anotha one* at https://my.test.url/2',
channel: slackUser.id,
});
});
test('updates the last reminder event ID in DynamoDB', async () => {
await updateOne(overrideUser);

expect(setLastReminderEventIdMock).toBeCalledWith(userWithCurrentEvent.email, busyEvent.id);
expect(setLastReminderEventIdMock).toHaveBeenCalledWith(userWithCurrentEvent.email, busyEvent.id);
});
});
describe('and the user has been sent a reminder', () => {
test('does not send a Slack reminder', async () => {
await updateOne({ ...overrideUser, lastReminderEventId: busyEvent.id });

expect(postMessageMock).not.toBeCalled();
expect(postMessageMock).not.toHaveBeenCalled();
});
test('does not update the last reminder event ID in DynamoDB', async () => {
await updateOne({ ...overrideUser, lastReminderEventId: busyEvent.id });

expect(setLastReminderEventIdMock).not.toBeCalled();
expect(setLastReminderEventIdMock).not.toHaveBeenCalled();
});
});
});
Expand All @@ -354,12 +354,12 @@ describe('updateOne', () => {
test('does not send a Slack reminder', async () => {
await updateOne(overrideUser);

expect(postMessageMock).not.toBeCalled();
expect(postMessageMock).not.toHaveBeenCalled();
});
test('does not update the last reminder event ID in DynamoDB', async () => {
await updateOne(overrideUser);

expect(setLastReminderEventIdMock).not.toBeCalled();
expect(setLastReminderEventIdMock).not.toHaveBeenCalled();
});
});
describe('and no upcoming meeting', () => {
Expand All @@ -370,12 +370,12 @@ describe('updateOne', () => {
test('does not send a Slack reminder', async () => {
await updateOne(overrideUser);

expect(postMessageMock).not.toBeCalled();
expect(postMessageMock).not.toHaveBeenCalled();
});
test('does not update the last reminder event ID in DynamoDB', async () => {
await updateOne(overrideUser);

expect(setLastReminderEventIdMock).not.toBeCalled();
expect(setLastReminderEventIdMock).not.toHaveBeenCalled();
});
});
});
Expand All @@ -384,7 +384,7 @@ describe('updateOne', () => {
getEventsForUserMock.mockResolvedValueOnce([oooEvent]);
await updateOne({ ...userWithCurrentEvent, meetingReminderTimingOverride: 1 });

expect(getEventsForUserMock).toBeCalledTimes(1);
expect(getEventsForUserMock).toHaveBeenCalledTimes(1);
});
});
});
Expand Down
1 change: 1 addition & 0 deletions src/services/calendar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const getEventsForUser = async (
const outlookEvents = await getAuthenticatedClient(email, storedToken)
.api(`/users/${email}/calendarView?startDateTime=${startTime.toISOString()}&endDateTime=${endTime.toISOString()}`)
.select('start,end,subject,body,showAs,location,sensitivity')
.filter('isCancelled eq false')
.get();

return outlookEvents.value.map((e: any) => {
Expand Down

0 comments on commit a02bdad

Please sign in to comment.