From 89b62b0ff7caf309301cf75d05ef4628a8b7eabf Mon Sep 17 00:00:00 2001 From: Cailyn Sinclair Date: Fri, 9 Oct 2026 14:56:04 -0700 Subject: [PATCH] Fix WCIF v2.2 save payloads --- src/lib/api/wcaAPI.test.ts | 9 +++++---- src/lib/api/wcaAPI.ts | 12 ++++++++---- src/store/actions.ts | 7 +++++-- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/lib/api/wcaAPI.test.ts b/src/lib/api/wcaAPI.test.ts index 3351f62..6486c2d 100644 --- a/src/lib/api/wcaAPI.test.ts +++ b/src/lib/api/wcaAPI.test.ts @@ -118,6 +118,7 @@ describe('wcaAPI', () => { body: JSON.stringify({ formatVersion: '2.1.1', persons: [{ registrantId: 1 }], + id: 'Comp', }), }) ); @@ -158,7 +159,7 @@ describe('wcaAPI', () => { 'https://wca.test/api/v0/competitions/Comp/wcif', expect.objectContaining({ method: 'PATCH', - body: JSON.stringify({ formatVersion: '2.0', name: 'New' }), + body: JSON.stringify({ formatVersion: '2.0', name: 'New', id: 'Comp' }), }) ); }); @@ -195,16 +196,16 @@ describe('wcaAPI', () => { ); }); - it('patches WCIF to the unchanged update endpoint', async () => { + it('patches WCIF with the required id and fetched format version', async () => { mockFetch({ json: vi.fn().mockResolvedValue({ id: 'Comp' }) }); - await patchWcif('Comp', { formatVersion: '2.0', name: 'Updated' } as any); + await patchWcif('Comp', { formatVersion: '2.2', name: 'Updated' }); expect(globalThis.fetch).toHaveBeenCalledWith( 'https://wca.test/api/v0/competitions/Comp/wcif', expect.objectContaining({ method: 'PATCH', - body: JSON.stringify({ formatVersion: '2.0', name: 'Updated' }), + body: JSON.stringify({ formatVersion: '2.2', name: 'Updated', id: 'Comp' }), }) ); }); diff --git a/src/lib/api/wcaAPI.ts b/src/lib/api/wcaAPI.ts index f86187e..fdd7bb4 100644 --- a/src/lib/api/wcaAPI.ts +++ b/src/lib/api/wcaAPI.ts @@ -68,11 +68,11 @@ export const getWcif = (competitionId: string): Promise => export const patchWcif = ( competitionId: string, - wcif: Partial + wcif: Partial & Pick ): Promise => wcaApiFetch(wcifPath(competitionId), { method: 'PATCH', - body: JSON.stringify(withoutV2PersonalBests(wcif)), + body: JSON.stringify(withoutV2PersonalBests({ ...wcif, id: competitionId })), }); export const checkWcif = (wcif: Competition): Promise => @@ -93,8 +93,12 @@ export const saveWcifChanges = ( (key) => previousWcif[key as keyof Competition] !== newWcif[key as keyof Competition] ); if (keysDiff.length === 0) return Promise.resolve(); - const keysForPatch = ['formatVersion', ...keysDiff]; - return patchWcif(newWcif.id, pick(newWcif, keysForPatch)); + const changedWcifKeys = keysDiff.filter((key) => key !== 'formatVersion'); + const changes = { + formatVersion: newWcif.formatVersion, + ...pick(newWcif, changedWcifKeys), + }; + return patchWcif(newWcif.id, changes); }; export const searchPersons = (query: string): Promise => diff --git a/src/store/actions.ts b/src/store/actions.ts index fef6ee0..d3f1307 100644 --- a/src/store/actions.ts +++ b/src/store/actions.ts @@ -159,8 +159,11 @@ export const uploadCurrentWCIFChanges = return; } - const keysForPatch = ['formatVersion', ...Array.from(changedKeys)]; - const changes = pick(wcif, keysForPatch); + const changedWcifKeys = Array.from(changedKeys).filter((key) => key !== 'formatVersion'); + const changes = { + formatVersion: wcif.formatVersion, + ...pick(wcif, changedWcifKeys), + }; dispatch(updateUploading(true)); checkWcif(wcif)