feat: add Subscription enum, converter, entity lifecycle hooks, and ORM-only test rule
This commit is contained in:
parent
c6e2e509eb
commit
0d9baeb6e5
3 changed files with 32 additions and 3 deletions
|
|
@ -293,6 +293,10 @@ public class GlobalExceptionHandler {
|
|||
- Frontend: Vitest for composables and utility functions. Cypress or Playwright for E2E (Phase 1).
|
||||
- Test naming: `shouldXxxWhenYyy` — e.g., `shouldReturn404WhenPlateNotFound`.
|
||||
- Aim for test coverage on business logic, not on getters/setters/boilerplate.
|
||||
- All database interaction in tests must go through JPA repositories
|
||||
or EntityManager. Never use JdbcTemplate, DataSource queries, or
|
||||
raw SQL in test code. Tests interact with the database the same way
|
||||
production code does: through the ORM.
|
||||
|
||||
---
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
package se.bilhalsning.entity;
|
||||
|
||||
import jakarta.persistence.AttributeConverter;
|
||||
import jakarta.persistence.Converter;
|
||||
|
||||
@Converter(autoApply = true)
|
||||
public class SubscriptionConverter implements AttributeConverter<Subscription, String> {
|
||||
|
||||
@Override
|
||||
public String convertToDatabaseColumn(Subscription subscription) {
|
||||
return subscription != null ? subscription.getValue() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Subscription convertToEntityAttribute(String dbData) {
|
||||
if (dbData == null) {
|
||||
return null;
|
||||
}
|
||||
for (Subscription subscription : Subscription.values()) {
|
||||
if (subscription.getValue().equals(dbData)) {
|
||||
return subscription;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Unknown subscription value: " + dbData);
|
||||
}
|
||||
}
|
||||
|
|
@ -2,8 +2,7 @@ package se.bilhalsning.entity;
|
|||
|
||||
import jakarta.persistence.Column;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.EnumType;
|
||||
import jakarta.persistence.Enumerated;
|
||||
import jakarta.persistence.Convert;
|
||||
import jakarta.persistence.Id;
|
||||
import jakarta.persistence.PrePersist;
|
||||
import jakarta.persistence.PreUpdate;
|
||||
|
|
@ -25,7 +24,7 @@ public class User {
|
|||
@Column(name = "password_hash", nullable = false, length = 255)
|
||||
private String passwordHash;
|
||||
|
||||
@Enumerated(EnumType.STRING)
|
||||
@Convert(converter = SubscriptionConverter.class)
|
||||
@Column(name = "subscription", nullable = false, length = 20)
|
||||
private Subscription subscription = Subscription.NONE;
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue