Skip to content

Commit 44a541d

Browse files
committed
Keep identical address change IDs
An address change record allows two changes: - setting an address - opting out of the donation receipt Each of those actions takes an `AddressChangeId` and "rotates" the current ID to the `previousIdentifier`. When doing both changes, the Id should only be rotated once, to avoid `hasBeenUsed` returning the wrong value and to be able to check in the frontend if the previous ID still returns a (used) address changed record.
1 parent e0b7a00 commit 44a541d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Domain/Model/AddressChange.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,10 @@ public function hasBeenUsed(): bool {
120120
}
121121

122122
private function markAsModified( AddressChangeId $newIdentifier ): void {
123-
$this->previousIdentifier = $this->getCurrentIdentifier();
124-
$this->identifier = $newIdentifier;
123+
if ( !$this->getCurrentIdentifier()->equals( $newIdentifier ) ) {
124+
$this->previousIdentifier = $this->getCurrentIdentifier();
125+
$this->identifier = $newIdentifier;
126+
}
125127

126128
$this->modifiedAt = new \DateTime();
127129
$this->resetExportState();

tests/Unit/Domain/Model/AddressChangeTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,4 +152,15 @@ public function testAddressChangesWithOptOutAreUsed(): void {
152152

153153
$this->assertTrue( $addressChange->hasBeenUsed() );
154154
}
155+
156+
public function testMultipleModificationsWithTheSameIdentifierKeepsIdentifiers(): void {
157+
$addressChange = $this->newPersonAddressChange();
158+
$initialIdentifier = $addressChange->getCurrentIdentifier();
159+
160+
$addressChange->performAddressChange( ValidAddress::newValidPersonalAddress(), $this->newIdentifier );
161+
$addressChange->optOutOfDonationReceipt( $this->newIdentifier );
162+
163+
$this->assertEquals( $initialIdentifier, $addressChange->getPreviousIdentifier() );
164+
$this->assertEquals( $this->newIdentifier, $addressChange->getCurrentIdentifier() );
165+
}
155166
}

0 commit comments

Comments
 (0)