Skip to content

Commit

Permalink
Ensure every email we log is to either a User or a non-user address
Browse files Browse the repository at this point in the history
  • Loading branch information
forevermatt committed Nov 12, 2024
1 parent c70b206 commit 75d2513
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
18 changes: 18 additions & 0 deletions application/common/models/EmailLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ public function rules()
'non_user_address',
'emptyIfUserIsSet',
],
[
'non_user_address',
'requiredIfUserIsEmpty',
'skipOnEmpty' => false,
],
], parent::rules());
}

Expand All @@ -137,4 +142,17 @@ public function emptyIfUserIsSet($attribute)
);
}
}

public function requiredIfUserIsEmpty($attribute)
{
if (empty($this->user_id) && empty($this[$attribute])) {
$this->addError(
$attribute,
sprintf(
'Either a user_id or a %s must be set',
$attribute
)
);
}
}
}
11 changes: 11 additions & 0 deletions application/features/bootstrap/EmailContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -1356,4 +1356,15 @@ public function anEmailLogValidationErrorShouldHaveOccurred()
'No EmailLog validation errors were found'
);
}

/**
* @When I try to log an email as sent to neither a User nor a non-user address
*/
public function iTryToLogAnEmailAsSentToNeitherAUserNorANonUserAddress()
{
$this->tempEmailLog = new EmailLog([
'message_type' => EmailLog::MESSAGE_TYPE_ABANDONED_USERS,
]);
$this->tempEmailLog->save();
}
}
4 changes: 4 additions & 0 deletions application/features/email.feature
Original file line number Diff line number Diff line change
Expand Up @@ -442,3 +442,7 @@ Feature: Email
Given a user already exists
When I try to log an email as sent to that User and to a non-user address
Then an email log validation error should have occurred

Scenario: Ensure each EmailLog is to either a User or a non-user address
When I try to log an email as sent to neither a User nor a non-user address
Then an email log validation error should have occurred

0 comments on commit 75d2513

Please sign in to comment.