Skip to content

refactor: deduplicate uploadClient test helpers and extract error code constant#91

Merged
DaxServer merged 1 commit into
mainfrom
refactor/upload-client-test-cleanup
Jun 7, 2026
Merged

refactor: deduplicate uploadClient test helpers and extract error code constant#91
DaxServer merged 1 commit into
mainfrom
refactor/upload-client-test-cleanup

Conversation

@DaxServer

Copy link
Copy Markdown
Owner
  • Export UPLOAD_CHUNK_FILE_EXCEPTION constant from client.ts (was an inline string literal duplicated across both error handlers and both tests)
  • Extract mockImageFetch(), callUploadFile(), and makeChunkUploadClient() test helpers to eliminate repeated boilerplate across the uploadFile error paths describe block
  • The two new StorageError tests from PR fix: map UploadChunkFileException to StorageError for retry #90 now use makeChunkUploadClient() and the shared constant instead of repeating 4-line setup each

— Claude Sonnet 4.6

…e constant

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@greptile-apps

greptile-apps Bot commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5

Safe 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

Filename Overview
backend/src/mediawiki/client.ts Extracts UPLOAD_CHUNK_FILE_EXCEPTION as an exported constant, replacing two identical inline string literals in the chunk-upload and commit error-handling branches — no logic change.
backend/src/tests/uploadClient.test.ts Adds mockImageFetch(), callUploadFile(), and makeChunkUploadClient() helpers; refactors all uploadFile error paths tests to use them; reorders the two StorageError tests (chunk before commit); imports the new constant — behaviour unchanged.

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
Loading

Reviews (1): Last reviewed commit: "refactor: deduplicate uploadClient test ..." | Re-trigger Greptile

@DaxServer DaxServer merged commit bf5b7aa into main Jun 7, 2026
5 checks passed
@DaxServer DaxServer deleted the refactor/upload-client-test-cleanup branch June 7, 2026 12:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant