Skip to content

Conversation

@denischilik
Copy link
Contributor

Background

This change improves the integration testing workflow by adding automated preprocessing capabilities for WireMock request recordings. Previously, recorded API request bodies contained dynamic fields (timestamps, device IDs, UUIDs) that changed on every test run, requiring manual editing of mapping files. This made test maintenance time-consuming and error-prone.

What Has Changed

  • Added field replacement functions to extract_request_body.py script:
    • replace_field_value() - recursively replaces single field values in JSON
    • replace_fields_from_list() - replaces multiple fields from a predefined list
  • Added --replace command line parameter to enable automatic replacement of 16 known dynamic fields
  • Dynamic fields (IDs, timestamps, device info) are now automatically replaced with ${json-unit.ignore} placeholders
  • Updated integration tests documentation with detailed workflow for recording and maintaining test request bodies
  • Added extracted request bodies for log_event and identify mappings
  • Cleaned up code comments in integration test source files

Benefits

  • Faster test development: No more manual editing of dynamic fields
  • Easier maintenance: Request bodies can be easily regenerated when SDK API changes
  • Better documentation: Clear workflow for recording relevant API calls only
  • Consistent test data: Automated replacement ensures no dynamic fields are missed

Checklist

  • I have performed a self-review of my own code.
  • I have made corresponding changes to the documentation.
  • I have added tests that prove my fix is effective or that my feature works.
  • I have tested this locally.

Additional Notes

The --replace parameter uses a default list of 16 dynamic fields commonly found in mParticle API requests. This list can be extended as needed for future test cases.

Reference Issue (For employees only. Ignore if you are an outside contributor)

- Add response body files for identify, log event, and config endpoints
- Add mapping files for v1 identify, v2 log event, and v4 config
Script extracts JSON request bodies from WireMock mapping files
and saves them as separate files for easier test data management.
- Add replace_field_value() function to recursively replace single field values
- Add replace_fields_from_list() function to replace multiple fields from a list
- Both functions support custom replacement values with default unit.ignore
- Add DEFAULT_REPLACE_FIELDS constant with 16 known dynamic fields
- Add --replace command line parameter to enable field replacement
- When enabled, replaces dynamic fields (IDs, timestamps, device info) with ${json-unit.ignore}
- Update script documentation and help text
- Add detailed steps for recording API requests with test code
- Document extract_request_body.py and update_mapping_from_extracted.py scripts
- Explain workflow for editing and maintaining test request bodies
- Add best practices for recording only relevant API calls
- Document benefits of the new workflow (dynamic field replacement, easier maintenance)
- Clarify that recorded mappings need to be filtered to keep only relevant ones
Copy link
Contributor

@nickolas-dimitrakas nickolas-dimitrakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Co-authored-by: Nickolas Dimitrakas <[email protected]>
- `wiremock-recordings/mappings/*.json` - API request/response mappings
- `wiremock-recordings/__files/*` - Response body files

### `extract_request_body.py` - Extract Request Body from WireMock Mapping
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we add python as well to the Prerequisites?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don’t need to list Python in the prerequisites because macOS already includes a system Python installation out of the box. Since the script is lightweight and doesn’t rely on any external libraries, it will run fine with the default Python that comes pre-installed on every Mac

@denischilik denischilik merged commit 69a8ed3 into main Nov 17, 2025
9 of 11 checks passed
@denischilik denischilik deleted the feat/SDKE-528-Implement-Script-To-Preprocess-Request-Recordings branch November 17, 2025 15:45
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.

5 participants