feat: camel-case feature names in inertia middleware - #6
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds automatic conversion of feature flag names from kebab-case to camelCase when sharing toggles with Inertia frontends, aligning with JavaScript naming conventions.
Changes:
- Modified
ShareTogglesWithInertiamiddleware to transform toggle keys usingStr::camel() - Added comprehensive test coverage for the camelCase conversion functionality
- Updated README documentation to reflect the camelCase usage in JavaScript
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/Middleware/ShareTogglesWithInertia.php | Implements camelCase transformation using Laravel's Str::camel() helper on toggle keys while preserving boolean values |
| tests/Feature/InertiaMiddlewareTest.php | Adds three test cases covering basic sharing, key conversion, and value preservation |
| README.md | Updates JavaScript example to use camelCase property access (flags.newCheckout) instead of bracket notation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| it('converts kebab-case toggle names to camelCase', function () { | ||
| config()->set('toggle.flags', [ | ||
| 'test-flag' => true, | ||
| 'another-feature-flag' => false, | ||
| 'simple' => true, | ||
| ]); | ||
|
|
||
| $middleware = new ShareTogglesWithInertia; | ||
| $request = Request::create('/'); | ||
|
|
||
| $shared = $middleware->share($request); | ||
|
|
||
| expect($shared['flags']) | ||
| ->toHaveKey('testFlag') | ||
| ->toHaveKey('anotherFeatureFlag') | ||
| ->toHaveKey('simple') | ||
| ->not->toHaveKey('test-flag') | ||
| ->not->toHaveKey('another-feature-flag'); | ||
| }); |
There was a problem hiding this comment.
Consider adding test coverage for edge cases with different naming conventions. While the current tests cover kebab-case conversion well, it would be beneficial to test how snake_case (e.g., 'feature_flag'), PascalCase (e.g., 'FeatureFlag'), and mixed formats are handled by Str::camel(). This ensures the behavior is consistent and predictable for various input formats that users might employ.
No description provided.