Fix test failures and module resolution issues #75
+105
−42
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
After changing the database package from CommonJS to ESM, multiple tests were failing with module resolution errors and outdated test expectations that no longer matched the current implementation.
Root Causes
databasepackage was compiled to CommonJS (require) but had"type": "module"inpackage.json, causing a mismatch when importing the ESM-only@nbw/configpackagebeforeEach, causing "Cannot overwrite model once compiled" errors@Injectdecorators were failing dependency injection in Bun's test environmentChanges Made
1. Fixed Module Resolution (
packages/database/tsconfig.build.json)modulefrom"CommonJS"to"ES2022"to matchpackage.json's"type": "module"import/export) compatible with@nbw/config2. Fixed Mongoose Test Setup (
apps/backend/src/song/song.service.spec.ts)aggregate,populatemongooseimport formongoose.Types.ObjectId()usagegetSongFilemethod tomockFileService3. Fixed Dependency Injection (
apps/backend/src/song/song.controller.ts,apps/backend/src/song/my-songs/my-songs.controller.ts)@Inject(SongService)and@Inject(FileService)decorators4. Updated Test Expectations
SongController Tests (
apps/backend/src/song/song.controller.spec.ts)getSongFileBufferinstead ofgetSongDownloadUrl, expects buffer/file response instead of redirectquerySongsinstead of deprecatedgetSongByPageSongService Tests (
apps/backend/src/song/song.service.spec.ts)aggregatemethod directlyjest.spyOn, addedpopulatemockAuthController Tests (
apps/backend/src/auth/auth.controller.spec.ts)authServicejest.clearAllMocks()inbeforeEachfor test isolationauthService(since actual login is handled by callback endpoints)Testing
Files Changed
packages/database/tsconfig.build.json- Changed module format to ESMapps/backend/src/song/song.controller.ts- Added @Inject decoratorsapps/backend/src/song/my-songs/my-songs.controller.ts- Added @Inject decoratorapps/backend/src/song/song.service.spec.ts- Fixed mock model setup and test expectationsapps/backend/src/song/song.controller.spec.ts- Updated test expectations to match implementationapps/backend/src/auth/auth.controller.spec.ts- Fixed test expectations and added test isolation