test: add unit test suite for platform role and permission management…#78
Conversation
|
@Oluwasuyi-Timilehin Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
|
Warning Review limit reached
Next review available in: 50 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds ChangesPlatform Role and Permission Test Suite
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/__tests__/platform.test.ts`:
- Around line 5-95: The platform test suite is using local stand-ins instead of
the real production entrypoints, so it can pass while the actual
controllers/utilities are broken. Update platform.test.ts to import and exercise
the real permissionController/roleController and platformUtils (especially
transformPermissions), and mock the underlying repository/query dependencies
they use rather than reimplementing their behavior. Make sure the tests reflect
the real transformPermissions contract from platform.utils and keep
normalization expectations aligned with platform.validations instead of the mock
lowercasing/trimming logic.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 998ff6ba-0867-4d3d-8b73-720207cb32d3
📒 Files selected for processing (1)
src/__tests__/platform.test.ts
|
Thank you for your awesome contribution, however after analyzing your implementation, there is a minor fix to be done. Kindly fix it to merge your PR asap. Also do not forget to use fundable.finance to offramp. |
|
will get on that now, thank you |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/__tests__/platform.test.ts (1)
44-48: 📐 Maintainability & Code Quality | 🔵 Trivial
createMockEntityhardcodesRoleEntity.prototypefor permission mocks too.Lines 64/73/81/105/117/128 use this helper for permission records, so they're stamped with
RoleEntity.prototype. This is harmless if the controllers only read plain fields, but will misbehave under anyinstanceof/ prototype-method checks. Consider parameterizing the prototype.♻️ Optional: accept the entity class
-const createMockEntity = (data: any) => { - const entity = Object.create(RoleEntity.prototype); - return Object.assign(entity, data); -}; +const createMockEntity = (data: any, EntityClass: { prototype: object } = RoleEntity) => { + const entity = Object.create(EntityClass.prototype); + return Object.assign(entity, data); +};🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/__tests__/platform.test.ts` around lines 44 - 48, The helper createMockEntity currently always builds objects with RoleEntity.prototype, but it is also used for permission records in platform.test.ts, so those mocks get the wrong prototype. Update createMockEntity to accept the entity class or prototype as a parameter, and then use the appropriate entity prototype at each call site where permission mocks are created so the records match the intended type.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@src/__tests__/platform.test.ts`:
- Around line 44-48: The helper createMockEntity currently always builds objects
with RoleEntity.prototype, but it is also used for permission records in
platform.test.ts, so those mocks get the wrong prototype. Update
createMockEntity to accept the entity class or prototype as a parameter, and
then use the appropriate entity prototype at each call site where permission
mocks are created so the records match the intended type.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 5d5f5fdb-e471-4de9-853d-f4ff763b68df
📒 Files selected for processing (1)
src/__tests__/platform.test.ts
#closes #64
Context
Resolves #64. The platform role and permission controllers lacked focused unit/regression tests under
src/__tests__to validate authorization setup constraints, validation logic, and constraint enforcement.Scope & Changes
src/__tests__/platform.test.tsto validate platform operations.ConflictError.InvalidRequestError.BadRequestError), payload duplicates (ConflictError), and non-existent permissions (NotFoundError).super-adminrole from deletion while verifying that non-super-admin roles can be deleted.platform.utils.tstext-transformation string normalization behavior.Verification & Testing Results
All local verification validations pass seamlessly on Windows environments running Bun
1.3.14:bun run lint): Passed with0 errors.bun run type-check): Completed cleanly with zero type compilation errors.bun run test): All 13 newly targeted specifications pass with 100% statement and line coverage metrics inside the isolated platform workspace module.