Skip to content

test: add AdminService unit tests for user management and fraud actions - #1173

Merged
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
shadrackmanfred:fix/1086-admin-service-tests
Sep 1, 2026
Merged

test: add AdminService unit tests for user management and fraud actions#1173
nanaf6203-bit merged 1 commit into
MettaChain:mainfrom
shadrackmanfred:fix/1086-admin-service-tests

Conversation

@shadrackmanfred

Copy link
Copy Markdown
Contributor

Summary

Adds the missing unit coverage for AdminService — the highest-privilege service in the module — plus a controller-level RBAC spec that pins the admin-only boundary. Prior to this PR src/admin/admin.service.ts had 0% coverage; the module had no spec at all for the service.

Coverage (from the scoped run below)

File              | % Stmts | % Branch | % Funcs | % Lines
admin.service.ts  |   76.66 |    69.56 |   61.29 |   76.13

Coverage command used: npx jest test/admin --coverage --collectCoverageFrom='src/admin/**/*.ts'

What's covered

test/admin/admin.service.spec.ts (25 tests)

  • User management: listUsers (page/limit defaults, search filter, base64 cursor pagination incl. no-double-offset, next-cursor generation), updateUser (not-found path, field updates, ROLE_CHANGE audit log + session revocation on role change, USER_BLOCKED/USER_UNBLOCKED audit logs), setUserBlockedState
  • Content moderation: getModerationQueue (default PENDING status, status + cursor filters), approveProperty, rejectProperty, flagProperty (incl. activity log), bulkModerate (approve vs. flag paths, per-owner logs)
  • Fraud actions: listFraudAlerts, alert summary, reviewFraudAlert, addFraudAlertNote, blockFraudUser (block from alert), scanUserForFraud, scanPropertyForFraud — each asserting the fraud-service delegation with the acting admin
  • Transaction monitoring: updateTransactionStatus delegates with actor

test/admin/admin.controller.spec.ts (3 tests)

  • Role enforcement: every user-management, moderation, and fraud route carries @Roles(UserRole.ADMIN) metadata
  • RolesGuard admits ADMIN and rejects USER and AGENT with ForbiddenException on admin-only routes

Verification

  • npm test — new specs pass (module total: 32 tests, 4 suites)
  • npx tsc --noEmit — no new errors
  • No production behavior changed

Closes #1086

AdminService had no test coverage despite implementing the
highest-privilege operations. Pin the behavior and the RBAC boundary:

- admin.service.spec.ts: cover getDashboard, listUsers (offset and
  base64 cursor pagination), updateUser (role/block audit logging,
  session revocation, not-found path), setUserBlockedState,
  moderation queue, approve/reject/flag/bulk moderation, and fraud
  delegation (review, block, user/property scans) — AdminService
  statement coverage rises to ~77%
- admin.controller.spec.ts: assert every user-management and fraud
  route carries the ADMIN role metadata and that RolesGuard admits
  ADMIN while rejecting USER/AGENT with ForbiddenException
@drips-wave

drips-wave Bot commented Sep 1, 2026

Copy link
Copy Markdown

@shadrackmanfred 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! 🚀

Learn more about application limits

@nanaf6203-bit
nanaf6203-bit merged commit 22993b0 into MettaChain:main Sep 1, 2026
4 of 7 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.

AdminService has no unit tests: user management and fraud actions are uncovered

2 participants