Skip to content

Conversation

KyrillosNageh
Copy link
Contributor

Summary

This PR resolves #2051 where SHAFT was unable to handle multipart file uploads when using Map-based parameters, and failed to preserve Arabic text.

Changes

  • Added ParametersType.MULTIPART to explicitly handle multipart form-data.
  • Implemented UTF-8 charset for text parts in multipart uploads.
  • Added Map→List parameter normalization to share the same request-building path for both APIs.
  • Added RestActions overloads to support Map parameters without breaking the deprecated List-based API.
  • Updated multipart detection to auto-trigger for File parameters.

Testing

  • Verified uploads work with both List<List<Object>> and Map<String, Object> parameter formats.
  • Confirmed Arabic text and other UTF-8 characters are preserved correctly in responses.

Impact

Backwards-compatible; deprecated List API still works.

public class TestUpload {
   SHAFT.API api;
    @Test
    public void testUploadWithList() {
        api = new SHAFT.API("http://localhost:3000/");
        SHAFT.Properties.api.set().swaggerValidationEnabled(false);

        List<List<Object>> parameters = Arrays.asList(
                Arrays.asList("image", new File("src/test/resources/search.PNG")),
                Arrays.asList("arabicText", "تست اوتوميشن")
        );

        api.post("upload")
                .setContentType("multipart/form-data; charset=UTF-8") // Ensure UTF-8 encoding
                .setParameters(parameters, RestActions.ParametersType.MULTIPART)
                .setTargetStatusCode(200)
                .perform();

        api.assertThatResponse()
                .extractedJsonValue("arabicText").isEqualTo("تست اوتوميشن");
        SHAFT.Report.log("Shaft API Response:" + api.getResponseBody());
    }

    @Test
    public void testUploadWithMap() {
        api = new SHAFT.API("http://localhost:3000/");
        SHAFT.Properties.api.set().swaggerValidationEnabled(false);

        Map<String, Object> parameters = new HashMap<>();
        parameters.put("image", new File("src/test/resources/search.PNG"));
        parameters.put("arabicText", "تست أوتوميشن");

        api.post("upload")
                .setContentType("multipart/form-data; charset=UTF-8") // Ensure UTF-8 encoding
                .setParameters(parameters, RestActions.ParametersType.MULTIPART)
                .setTargetStatusCode(200)
                .perform();

        api.assertThatResponse()
                .extractedJsonValue("arabicText").isEqualTo("تست أوتوميشن");
        SHAFT.Report.log("Shaft API Response:" + api.getResponseBody());
    }
}

…→List normalization

- Introduced ParametersType.MULTIPART for detecting multipart requests.
- Added UTF-8 charset for multipart text parts (Arabic + non-ASCII support).
- Normalized Map parameters → List to support both APIs.
- Added overloads in RestActions to handle Map without breaking deprecated List API.
- Fixes ShaftHQ#2051
@KyrillosNageh KyrillosNageh marked this pull request as draft August 9, 2025 18:37
Copy link

codecov bot commented Aug 9, 2025

Codecov Report

❌ Patch coverage is 59.64912% with 23 lines in your changes missing coverage. Please review.
✅ Project coverage is 52.68%. Comparing base (59f4c16) to head (529da9a).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
src/main/java/com/shaft/api/RestActions.java 60.00% 13 Missing and 5 partials ⚠️
src/main/java/com/shaft/api/RequestBuilder.java 58.33% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #2054      +/-   ##
============================================
- Coverage     54.62%   52.68%   -1.95%     
+ Complexity     1477     1428      -49     
============================================
  Files           117      117              
  Lines         10579    10624      +45     
  Branches       1039     1050      +11     
============================================
- Hits           5779     5597     -182     
- Misses         4114     4358     +244     
+ Partials        686      669      -17     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@KyrillosNageh KyrillosNageh marked this pull request as ready for review August 10, 2025 19:34
@MohabMohie MohabMohie merged commit 1974da1 into ShaftHQ:main Aug 13, 2025
16 of 17 checks passed
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.

[Bug]: SHAFT Unable to Handle Multipart File Upload for API Testing
2 participants