test(user-preferences): guard currency column against entity drift - #1347
Merged
RUKAYAT-CODER merged 1 commit intoAug 27, 2026
Merged
Conversation
Add regression tests confirming UserPreference declares the `currency` column added by the AddTimezoneLocalePreferences migration, and that it round-trips correctly through UserPreferencesService (read, update, reset). Without this coverage, a future refactor could silently drop the column from the entity again, as happened in rinafcode#1206. Closes rinafcode#1206
|
@Ajibose 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! 🚀 |
Contributor
|
thank you for contributing to the project. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #1206
Summary
UserPreferencealready declares thecurrencycolumn that migration1710000000000-AddTimezoneLocalePreferences.tsadds touser_preferences(type: 'varchar', default: 'USD', nullable: true), matching the migration'scurrency varchar DEFAULT 'USD'. That alignment landed in79145811("fix(migrations): reconcile entity/migration drift and enforce strict schema check"), so the column is already readable through the entity and the drift check no longer wants to drop it.What was missing was regression coverage: nothing in the test suite would catch
currencybeing silently dropped from the entity again in a future change. This PR closes that gap.Changes
New files
src/user-preferences/entities/user-preference.entity.spec.ts— verifies, via TypeORM'sgetMetadataArgsStorage(), thatUserPreferencedeclares acurrencycolumn withtype: 'varchar',default: 'USD',nullable: true(matching the migration), plus sanity checks for the siblinglocale/timezonecolumns and that the property itself reads/writes correctly on an instance.src/user-preferences/user-preferences.service.spec.ts— unit tests (mocked repository, following the existingpreferences.service.spec.tspattern) provingcurrencyround-trips throughUserPreferencesService#getPreferences,#updatePreferences, and#resetPreferences.Modified files
None — the entity already declares
currency; no production code changed.Implementation details
MetadataArgsStoragedirectly rather than spinning up a real database connection, so the test is fast and has no infra dependency, while still failing loudly if the@Columndecorator forcurrencyis ever removed or its options (type/default/nullable) drift from what the migration produces.src/notifications/preferences/preferences.service.spec.ts(a plain jest-mockedRepository, injected viagetRepositoryToken) to stay consistent with existing conventions in the codebase.Tests added
UserPreference entity - schema drift (#1206)AddTimezoneLocalePreferencesmigrationUserPreferencesService - currency (#1206)How to test
All 6 new tests pass; no other test files were touched.