Skip to content

Commit ee464bf

Browse files
authored
Merge pull request #76 from coder13/copilot/fix-payload-extraneous-keys
Fix extraneous `room` key in WCIF PATCH payload
2 parents 8f83239 + a7dfbc8 commit ee464bf

5 files changed

Lines changed: 28 additions & 6 deletions

File tree

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup Node.js
2020
uses: actions/setup-node@v4
2121
with:
22-
node-version: '18'
22+
node-version-file: '.nvmrc'
2323
cache: 'yarn'
2424

2525
- name: Install dependencies

.github/workflows/type-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup Node.js
2020
uses: actions/setup-node@v4
2121
with:
22-
node-version: '18'
22+
node-version-file: '.nvmrc'
2323
cache: 'yarn'
2424

2525
- name: Install dependencies

src/store/actions.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ describe('store actions', () => {
320320
type: ActionType.UPLOADING_WCIF,
321321
uploading: true,
322322
});
323-
expect(patchWcifMock).toHaveBeenCalledWith('Comp1', { events: wcif.events });
323+
expect(patchWcifMock).toHaveBeenCalledWith('Comp1', { events: wcif.events, formatVersion: wcif.formatVersion });
324324
expect(dispatch.mock.calls[1][0]).toEqual({
325325
type: ActionType.UPLOADING_WCIF,
326326
uploading: false,

src/store/reducers/_tests_/roundActivities.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,23 @@ describe('roundActivities reducers', () => {
2323
expect(nextState.needToSave).toBe(true);
2424
expect(nextState.changedKeys.has('schedule')).toBe(true);
2525
expect(nextActivities[0]).toBe(activityOne);
26-
expect(nextActivities[1]).toBe(updatedActivityTwo);
26+
// The updated activity is returned as a new object (extraneous props are stripped), so use toEqual
27+
expect(nextActivities[1]).not.toBe(updatedActivityTwo);
28+
expect(nextActivities[1]).toEqual(updatedActivityTwo);
29+
});
30+
31+
it('updateRoundActivities strips extraneous properties (e.g. room) from stored activities', () => {
32+
const activityOne = buildActivity({ id: 1, name: 'Round 1', activityCode: '333-r1' });
33+
const room = { id: 10, name: 'Room A', color: '#000', extensions: [], activities: [activityOne] };
34+
// Simulate ActivityWithRoom: an activity with an extra `room` reference attached internally
35+
const activityWithRoom = { ...activityOne, name: 'Round 1 Updated', room };
36+
const state = buildState(buildWcif([activityOne]));
37+
38+
const nextState = updateRoundActivities(state, { activities: [activityWithRoom] });
39+
40+
const nextActivity = nextState.wcif?.schedule.venues[0].rooms[0].activities[0];
41+
expect(nextActivity).not.toHaveProperty('room');
42+
expect(nextActivity).toEqual(expect.objectContaining({ id: 1, name: 'Round 1 Updated' }));
2743
});
2844

2945
it('updateRoundChildActivities updates child activities and keeps other assignments intact', () => {

src/store/reducers/roundActivities.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mapIn } from '../../lib/utils';
22
import type { UpdateRoundActivitiesPayload, UpdateRoundChildActivitiesPayload } from '../actions';
33
import type { AppState } from '../initialState';
4-
import type { Assignment, Person } from '@wca/helpers';
4+
import type { Activity, Assignment, Person } from '@wca/helpers';
55

66
/**
77
* Updates the child activities of a round activity and also updates the assignments of the persons accordingly
@@ -83,7 +83,13 @@ export const updateRoundActivities = (
8383
...room,
8484
activities: room.activities.map((activity) => {
8585
const updatedActivity = action.activities.find((a) => a.id === activity.id);
86-
return updatedActivity || activity;
86+
if (!updatedActivity) return activity;
87+
// Strip extraneous properties (e.g. `room`) that may be present from internal use
88+
// but are not valid WCIF schema properties
89+
const { room: _room, ...wcifActivity } = updatedActivity as Activity & {
90+
room?: unknown;
91+
};
92+
return wcifActivity as Activity;
8793
}),
8894
})),
8995
})),

0 commit comments

Comments
 (0)