Repository navigation
FINERACT-3171: Move client validation to ClientDataValidator - #7118
Conversation
Move the existing name, date, and activation checks out of the Client entity and call them from the write services. Cover validation errors and the side effects skipped on failure. Assisted-By: OpenAI-Codex-GPT-6.2-Sol
|
Thanks @Joab-SC, looks good to me. I compared the moved checks with what was removed from Client and they're the same (codes, messages, order), and each of instance(), activate() and validateUpdate() has only one caller, which now calls the validator in the same spot. Nice that the service tests check nothing gets saved on failure. A few small things, nothing blocking:
|
adamsaghy
left a comment
There was a problem hiding this comment.
Thanks @Joab-SC. The request checks keep their codes, messages, parameters and order, and they run at the same points as before, so the API behaviour is unchanged. One change goes beyond the ticket, though:
- The "already active" guard should stay in
Client.activate. FINERACT-3171 says to move request validation out but "keep invariant checks that protect the entity's own state in the entity". "Cannot activate an already active client" is exactly that kind of check. Without it,Client.activatesilently re-activates an active client and overwritesactivationDate,activatedByandofficeJoiningDate. FINERACT-3169 did the same split forSavingsAccount(requirePendingApprovalstayed in the entity). Please keep that check inClient.activate(as before, or as a smallrequireNotActive(...)method onClient) and move only the name and date checks toClientDataValidator.
Optional:
- The ticket says to validate "before it changes the entity". For activation this is easy: the only checked value that
activatechanges isactivationDate, which you already have. SovalidateClient(...)can run beforeclient.activate(...)withactivationDatepassed in (inline). ImalkaPerera raised this too. validateClientActivationRejectsAlreadyActiveClient: if the check stays in the validator, use a non-ISO pattern (e.g.dd/MM/yyyy) and assert the formatted value, so the test proves the formatter is used.- #7064 adds tests at the same place in
ClientDataValidatorTest, so whichever PR lands second needs a small rebase.
Assisted-By: OpenAI-Codex-GPT-6.2-Sol
|
Thanks, Adam and Imlaka. I restored the already-active guard in Client.activate(...) and moved request validation ahead of the state change. The service still reports the already-active error first if both checks would fail. The entity test verifies that a second activation preserves the original fields and that the error carries the requested date formatted as 09/01/2026. All 28 focused tests passed across the three affected test classes, and Spotless passed. |
adamsaghy
left a comment
There was a problem hiding this comment.
Thanks @Joab-SC, all points from my earlier review are addressed. The already-active guard stays in the entity as requireNotActive, and request validation now runs before client.activate(...). The moved checks are identical to the removed entity code and run at the same points for create, update and activate, so error codes, messages, parameters, order and the already-active precedence are unchanged. CI is green; the one E2E failure was an unrelated random short-name collision in a working capital scenario and passed on re-run. Follow-ups worth a ticket: the reopen-date rule's code/message mismatch and the shape of the already-active error. Note that #7064 adds the same ClientCreateUpdateWritePlatformServiceTest file, so it will need a rebase after this lands.
Description
Move client name and date validation from the
Cliententity toClientDataValidator. The create, update, and activation services now call the validator explicitly, keeping the request validation rules in one place while preserving the existing API errors.Client.activate(...)retains the already-active guard so a second activation cannot overwrite the original activation date, activating user, or office joining date. The activation service checks the client's state first, validates the requested activation date, and then changes the entity. This preserves which error is returned if the client is already active and the requested date is also invalid.Add validator tests for the specific errors returned and service tests that verify downstream work is skipped when validation fails. The entity test also verifies that a rejected second activation preserves the original fields and that the error uses the requested date format.
The existing mismatch between the reopen-date comparison and its error code and message is preserved for a separate follow-up. Non-person client validation is handled separately in #7064.
JIRA: FINERACT-3171
Verification
ClientActivationTest,ClientDataValidatorTest, andClientLifecycleWritePlatformServiceTest.Checklist
Assisted-By: OpenAI-Codex-GPT-6.2-Sol.