Skip to content

Feat/primitives - #1161

Merged
nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
nafiuishaaq:feat/primitives
Aug 31, 2026
Merged

nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
nafiuishaaq:feat/primitives

Conversation

@nafiuishaaq

Copy link
Copy Markdown
Contributor

Summary of Changes

Created a new test file [test/cache/cache.service.e2e-spec.ts](file:///c:/Users/hp/Desktop/wave 8/PropChain-BackEnd/test/cache/cache.service.e2e-spec.ts) that tests all the core cache functionality against a real Redis instance, using the existing e2e test harness. The tests cover:

1. Lock Acquisition (setNx primitive)

  • ✅ Successfully acquire a lock when the key is not present
  • ✅ Fail to acquire an already held lock (contention testing)
  • ✅ Re-acquire a lock after it expires (lock expiry/ttl testing)

2. TTL Behavior

  • ✅ Retrieve values before TTL expires
  • ✅ Return undefined after TTL expires
  • ✅ Use default TTL when not specified

3. Tag-based Invalidation

4. Additional Core Functionality

  • Basic cache operations (set/get/del/delMultiple/clear)
  • getOrSet cache-aside pattern
  • Connection health checks
  • Stats retrieval

Test Architecture

The tests run against a real Redis instance as required (since distributed primitives like locks and TTLs can't be properly tested with mocks), using the same NestJS testing module setup as the existing cache tests. Each test is isolated with cache clearing before execution to prevent cross-test contamination.

Coverage Impact

These tests will significantly improve the coverage of the cache module, which previously only had tests for metrics and stats. The new tests exercise all the uncovered primitives:

Summary of Changes

Created a new test file [test/backup/backup.service.e2e-spec.ts](file:///c:/Users/hp/Desktop/wave 8/PropChain-BackEnd/test/backup/backup.service.e2e-spec.ts) that tests all the core backup functionality against a real Prisma test database, using the existing e2e test harness. The tests cover:

1. Schedule Refresh on Boot (onModuleInit)

  • ✅ Verifies that ensureScheduleConfig creates the default schedule if it doesn't exist
  • ✅ Tests that the scheduled job starts when the schedule is enabled
  • ✅ Confirms that existing scheduled jobs are stopped before creating new ones during schedule updates

2. Status Reporting

  • ✅ Returns correct status with zero backups initially
  • ✅ Reports accurate metrics when there's a completed backup
  • ✅ Properly identifies running backup/restore jobs
  • ✅ getSchedule returns the current configuration
  • ✅ listBackups returns backups in correct descending chronological order

3. Restore Flow (Success and Failure Cases)

  • ✅ Successfully restores an existing, valid backup file
  • ✅ Throws NotFoundException for non-existent backups
  • ✅ Throws NotFoundException when backup file is missing from storage
  • ✅ Throws ConflictException when another job is already running
  • ✅ Handles restore failures correctly, updating database with error status
  • ✅ Verifies restore metadata (restoredById, restoredAt) is properly set
  • closes Audit module has no tests: trail recording and query logic is uncovered #1124

4. Additional Core Functionality

  • Manual backup creation with proper command execution
  • Retention policy enforcement (old backups are deleted when exceeding retention count)
  • All database interactions are tested against a real test database

Test Architecture

The tests run against a real Prisma test database as required (since restore and scheduling logic can't be properly tested with mocks alone). We use Jest to mock the child_process execFile calls to avoid actually running pg_dump/psql in the test environment, while still testing all the surrounding logic. Each test is isolated with proper cleanup before and after execution.

Coverage Impact

These tests will significantly improve the coverage of the backup module, which previously only had limited unit tests. The new tests exercise all the uncovered primitives:

The tests are ready to be run with npm test and will execute in CI along with the existing test suite.

@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@nafiuishaaq 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 ddce2e8 into MettaChain:main Aug 31, 2026
6 of 7 checks passed
DeFex-lab pushed a commit to DeFex-lab/PropChain-BackEnd that referenced this pull request Oct 12, 2026
DeFex-lab pushed a commit to DeFex-lab/PropChain-BackEnd that referenced this pull request Oct 15, 2026
DeFex-lab pushed a commit to DeFex-lab/PropChain-BackEnd that referenced this pull request Oct 22, 2026
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