Skip to content

test(user-preferences): guard currency column against entity drift - #1347

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Ajibose:fix/user-preference-currency-column
Aug 27, 2026
Merged

RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Ajibose:fix/user-preference-currency-column

Conversation

@Ajibose

@Ajibose Ajibose commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

Closes #1206

Summary

UserPreference already declares the currency column that migration 1710000000000-AddTimezoneLocalePreferences.ts adds to user_preferences (type: 'varchar', default: 'USD', nullable: true), matching the migration's currency varchar DEFAULT 'USD'. That alignment landed in 79145811 ("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 currency being 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's getMetadataArgsStorage(), that UserPreference declares a currency column with type: 'varchar', default: 'USD', nullable: true (matching the migration), plus sanity checks for the sibling locale/timezone columns 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 existing preferences.service.spec.ts pattern) proving currency round-trips through UserPreferencesService#getPreferences, #updatePreferences, and #resetPreferences.

Modified files

None — the entity already declares currency; no production code changed.

Implementation details

  • The entity metadata assertion reads TypeORM's internal MetadataArgsStorage directly rather than spinning up a real database connection, so the test is fast and has no infra dependency, while still failing loudly if the @Column decorator for currency is ever removed or its options (type/default/nullable) drift from what the migration produces.
  • The service tests mirror the mocking style already used in src/notifications/preferences/preferences.service.spec.ts (a plain jest-mocked Repository, injected via getRepositoryToken) to stay consistent with existing conventions in the codebase.

Tests added

  • UserPreference entity - schema drift (#1206)
    • declares a currency column matching the AddTimezoneLocalePreferences migration
    • still declares the locale and timezone columns added by the same migration
    • reads a currency value assigned on the entity instance
  • UserPreferencesService - currency (#1206)
    • returns the currency column when reading an existing preference row
    • persists an updated currency value
    • recreates default preferences with currency undefined so the entity default of USD applies

How to test

pnpm install
npx jest src/user-preferences

All 6 new tests pass; no other test files were touched.

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
@drips-wave

drips-wave Bot commented Aug 27, 2026

Copy link
Copy Markdown

@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! 🚀

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 d9fcf93 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

Development

Successfully merging this pull request may close these issues.

user_preferences.currency column exists in DB but not in the entity

2 participants