fix: improve E2E test probes and enable function webhook events

- Fix testPasswordRecoveryUrlParams: use URL-based probes instead of
  userId-based probes to distinguish between test cases that share the
  same user
- Enable functions.* webhook events in ProjectCustom for function
  webhook tests that were silently passing by matching stale events
- Fix setupTeamMembership: add email address probe to getLastEmail to
  prevent picking up wrong invitation email
- Fix getLastEmail multi-email race: assert count inside assertEventually
  when requesting multiple emails

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jake Barnby
2026-02-24 15:15:59 +13:00
parent 5cb36a0a3a
commit 07dc088e4e
4 changed files with 16 additions and 13 deletions
+1 -1
View File
@@ -188,7 +188,7 @@ trait ProjectCustom
'name' => 'Webhook Test',
'events' => [
'databases.*',
// 'functions.*', TODO @christyjacob4 : enable test once we allow functions.* events
'functions.*',
'buckets.*',
'teams.*',
'users.*'
+1
View File
@@ -167,6 +167,7 @@ abstract class Scope extends TestCase
$result = end($emails);
} else {
$result = array_slice($emails, -1 * $limit);
$this->assertCount($limit, $result, "Expected {$limit} emails but only got " . count($result));
}
$this->assertNotEmpty($result, 'Expected email result to be non-empty');
@@ -6441,8 +6441,8 @@ class ProjectsConsoleClientTest extends Scope
$userId = $response['body']['userId'];
$lastEmail = $this->getLastEmail(1, function ($email) use ($userId) {
$this->assertStringContainsString($userId, $email['html'] ?? '');
$lastEmail = $this->getLastEmail(1, function ($email) use ($url) {
$this->assertStringContainsString($url, $email['html'] ?? '');
});
$this->assertEquals($this->getUser()['email'], $lastEmail['to'][0]['address']);
@@ -6474,8 +6474,8 @@ class ProjectsConsoleClientTest extends Scope
$userId = $response['body']['userId'];
$lastEmail = $this->getLastEmail(1, function ($email) use ($userId) {
$this->assertStringContainsString($userId, $email['html'] ?? '');
$lastEmail = $this->getLastEmail(1, function ($email) use ($url) {
$this->assertStringContainsString($url, $email['html'] ?? '');
});
$this->assertEquals($this->getUser()['email'], $lastEmail['to'][0]['address']);
@@ -6507,8 +6507,8 @@ class ProjectsConsoleClientTest extends Scope
$userId = $response['body']['userId'];
$lastEmail = $this->getLastEmail(1, function ($email) use ($userId) {
$this->assertStringContainsString($userId, $email['html'] ?? '');
$lastEmail = $this->getLastEmail(1, function ($email) use ($url, $userId) {
$this->assertStringContainsString($url . '?userId=' . $userId, $email['html'] ?? '');
});
$this->assertEquals($this->getUser()['email'], $lastEmail['to'][0]['address']);
@@ -6540,8 +6540,8 @@ class ProjectsConsoleClientTest extends Scope
$userId = $response['body']['userId'];
$lastEmail = $this->getLastEmail(1, function ($email) use ($userId) {
$this->assertStringContainsString($userId, $email['html'] ?? '');
$lastEmail = $this->getLastEmail(1, function ($email) use ($url, $userId) {
$this->assertStringContainsString($url . '?userId=' . $userId, $email['html'] ?? '');
});
$this->assertEquals($this->getUser()['email'], $lastEmail['to'][0]['address']);
@@ -6573,8 +6573,8 @@ class ProjectsConsoleClientTest extends Scope
$userId = $response['body']['userId'];
$lastEmail = $this->getLastEmail(1, function ($email) use ($userId) {
$this->assertStringContainsString($userId, $email['html'] ?? '');
$lastEmail = $this->getLastEmail(1, function ($email) {
$this->assertStringContainsString('INJECTED', $email['html'] ?? '');
});
$this->assertEquals($this->getUser()['email'], $lastEmail['to'][0]['address']);
+4 -2
View File
@@ -277,8 +277,10 @@ trait WebhooksBase
$membershipId = $team['body']['$id'];
$userId = $team['body']['userId'];
// Get the secret from email
$lastEmail = $this->getLastEmail();
// Get the secret from email (use probe to match correct email by recipient address)
$lastEmail = $this->getLastEmail(1, function ($msg) use ($email) {
$this->assertEquals($email, $msg['to'][0]['address'] ?? '');
});
$tokens = $this->extractQueryParamsFromEmailLink($lastEmail['html'] ?? '');
$secret = $tokens['secret'] ?? '';