Skip to content

Add unit tests for audit-export, mfa, sensitive-operations, adaptive-ttl services - #1359

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
BigBen-7:test/service-unit-tests-2
Aug 27, 2026
Merged

Add unit tests for audit-export, mfa, sensitive-operations, adaptive-ttl services#1359
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
BigBen-7:test/service-unit-tests-2

Conversation

@BigBen-7

Copy link
Copy Markdown
Contributor

Summary

Closes four issues, each asking for unit test coverage on a previously-untested service:

  • Closes Add unit tests for audit-export service #1265AuditExportService: exportToJson/exportToCsv (pretty-printed JSON, header + row shape, missing-optional-field fallback to '', CSV escaping of commas/quotes/newlines, empty-result and query-failure cases).
  • Closes Add unit tests for mfa service #1268MfaService: generateTotpSecret (encrypts the secret, hashes recovery codes, saves, returns the QR code + plaintext codes), verifySetup (missing-setup and invalid-code rejections), verifyCode (TOTP path, recovery-code fallback + consumption, no-match path), disableMfa (valid/invalid code).
  • Closes Add unit tests for sensitive-operations service #1267SensitiveOperationsService: logSensitiveOperation (category resolution incl. unmapped-action fallback, error propagation) plus each of the eight domain-specific wrappers (user deletion, role change, password change, config change, data export, backup create/restore, permission denied, suspicious activity), including the anonymous-actor (null userId/userEmail) paths.
  • Closes Add unit tests for adaptive-ttl service #1269AdaptiveTTLService: getAdaptiveTTL (no match, disabled rule, no-metrics clamping, increase/decrease paths, corrupt-rule-data fallback), getRecentAdjustments/getAdjustmentStats (parsing + skipping corrupt records, empty-range average), getRules/updateRules/updateRule/removeRule/toggleRule (add vs. replace, no-op when nothing matches), cleanupOldAdjustments, and the cache.performance.analyzed event handler.

No production code was touched — this is test-only, per each issue's scope.

Test plan

  • npx jest on all four new spec files — 59 passed, 0 failed
  • npm run typecheck (tsconfig.build.json) — clean
  • eslint on the new files — clean

…ptive-ttl services

Closes rinafcode#1265, rinafcode#1268, rinafcode#1267, rinafcode#1269 — four previously-untested services
each get a focused *.spec.ts covering every public method's success and
failure/edge-case paths:

- AuditExportService: exportToJson/exportToCsv (pretty-printed JSON,
  header + row shape, missing-optional-field fallback to '', CSV
  escaping of commas/quotes/newlines, empty-result and query-failure
  cases).
- MfaService: generateTotpSecret (encrypts the secret, hashes recovery
  codes, saves, returns the QR code + plaintext codes), verifySetup
  (missing-setup and invalid-code rejections), verifyCode (TOTP path,
  recovery-code fallback + consumption, no-match path), disableMfa
  (valid/invalid code).
- SensitiveOperationsService: logSensitiveOperation (category
  resolution incl. unmapped-action fallback, error propagation) plus
  each of the eight domain-specific wrappers (user deletion, role
  change, password change, config change, data export, backup
  create/restore, permission denied, suspicious activity), including
  the anonymous-actor (null userId/userEmail) paths.
- AdaptiveTTLService: getAdaptiveTTL (no match, disabled rule, no
  metrics clamping, increase/decrease paths, corrupt-rule-data
  fallback), getRecentAdjustments/getAdjustmentStats (parsing +
  skipping corrupt records, empty-range average), getRules/updateRules/
  updateRule/removeRule/toggleRule (add vs. replace, no-op when no
  match), cleanupOldAdjustments, and the
  cache.performance.analyzed event handler.

Verified: `npx jest` on all four specs (59 passed), `npm run typecheck`
(tsconfig.build.json) and `eslint` are clean.
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@BigBen-7 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

@RUKAYAT-CODER

Copy link
Copy Markdown
Contributor

Thank you for contributing to the project.

@RUKAYAT-CODER
RUKAYAT-CODER merged commit e334a43 into rinafcode:main Aug 27, 2026
3 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

2 participants