Skip to content

test: add unit tests for 4 services (achievements-notifications, achievements, analytics, batch-size-guard) - #1361

Merged
RUKAYAT-CODER merged 2 commits into
rinafcode:mainfrom
NteinPrecious:feat/unit-tests-1253-1254-1255-1256
Aug 27, 2026
Merged

test: add unit tests for 4 services (achievements-notifications, achievements, analytics, batch-size-guard)#1361
RUKAYAT-CODER merged 2 commits into
rinafcode:mainfrom
NteinPrecious:feat/unit-tests-1253-1254-1255-1256

Conversation

@NteinPrecious

Copy link
Copy Markdown
Contributor

Summary

This PR adds focused unit test suites for four previously untested services, satisfying the acceptance criteria of issues #1253#1256.


#1253 — achievements-notifications.service

Added src/achievements/achievements-notifications.service.spec.ts.

Covers:

  • sendAchievementUnlockedNotification — marks notification sent; swallows repository errors gracefully
  • sendBatchNotifications — returns correct count; returns 0 on empty result or repository failure
  • resendFailedNotifications — retries up to 100 records; returns 0 on failure

Closes #1253


#1254 — achievements.service

Added src/achievements/achievements.service.spec.ts (co-located with source, as required).

Covers:

  • createAchievement — saves entity and invalidates cache
  • getAchievementById — returns dto; throws NotFoundException when missing
  • updateAchievement — updates and invalidates cache; throws NotFoundException when missing
  • deactivateAchievement — sets isActive: false
  • hasAchievement — returns true/false based on unlock record
  • getUserAchievementCount — delegates to repository
  • unlockAchievement — creates unlock event; skips duplicate; throws NotFoundException
  • initializeProgress — reuses existing progress; creates when absent; throws NotFoundException
  • getUserProgressForAchievement — returns dto; throws NotFoundException when absent

Closes #1254


#1255 — analytics.service

Added src/analytics/analytics.service.spec.ts.

Covers:

  • trackEvent — validates, batches, increments counter; re-throws BadRequestException; wraps unknown errors
  • recordEvent and all assessment helpers — no-throw when counter is null
  • getEvents — returns empty set; applies all optional filters
  • getAnalyticsSummary — returns zeroed summary; maps raw query results into response shape

Closes #1255


#1256 — batch-size-guard.service

Added src/analytics/services/batch-size-guard.service.spec.ts.

Covers:

  • canAdd — returns true below max; returns false at and above max; increments dropped count only on rejection
  • getDroppedCount — starts at zero; accumulates correctly
  • resetDroppedCount — resets to zero; idempotent on zero

Closes #1256

@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@NteinPrecious 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 573050b 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