refactor: deduplicate uploadClient test helpers and extract error code constant#91
Conversation
…e constant Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Confidence Score: 5/5Safe to merge — this is a straightforward refactoring with no changes to production logic or test coverage. The only production-code change is exporting a string constant that was already present verbatim in two places; both usages in client.ts are a direct substitution with no surrounding logic altered. The test changes mechanically extract repeated setup into helpers and reorder two StorageError tests (chunk → commit), which is strictly cosmetic. Each helper is narrow and correct: mockImageFetch isolates CDN fetch setup, callUploadFile fixes the argument list in one place, and makeChunkUploadClient bundles the three stubs every chunk-path test needs. No new behaviour is introduced and no existing assertions are dropped. No files require special attention. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[Test: StorageError chunk] -->|makeChunkUploadClient| B[new MediaWikiClient]
B --> C[mock getCsrfToken]
C --> D[mock findDuplicates → empty]
D --> E[mockImageFetch → 200 OK]
E --> F[makeRedisMock]
F --> G[return client, redis]
G -->|override apiUploadChunk| H[mock: always returns error]
H --> I[callUploadFile client, redis]
I --> J{expects StorageError}
A2[Test: StorageError commit] -->|makeChunkUploadClient| B
G2[return client, redis] -->|override apiUploadChunk| K[mock: call1=Continue, call2=error]
K --> I2[callUploadFile client, redis]
I2 --> J2{expects StorageError}
subgraph UPLOAD_CHUNK_FILE_EXCEPTION
CONST["internal_api_error_MediaWiki\\Upload\\Exception\\UploadChunkFileException"]
CONST -->|client.ts line 254| ERR1[chunk upload error handler]
CONST -->|client.ts line 285| ERR2[commit error handler]
CONST --> T1[chunk StorageError test]
CONST --> T2[commit StorageError test]
end
Reviews (1): Last reviewed commit: "refactor: deduplicate uploadClient test ..." | Re-trigger Greptile |
UPLOAD_CHUNK_FILE_EXCEPTIONconstant fromclient.ts(was an inline string literal duplicated across both error handlers and both tests)mockImageFetch(),callUploadFile(), andmakeChunkUploadClient()test helpers to eliminate repeated boilerplate across theuploadFile error pathsdescribe blockmakeChunkUploadClient()and the shared constant instead of repeating 4-line setup each— Claude Sonnet 4.6