Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ jobs:
'EndToEnd/general/plugin-screens',
'EndToEnd/integrations/divi-builder',
'EndToEnd/integrations/divi-theme',
'EndToEnd/integrations/elementor',
'EndToEnd/integrations/other',
'EndToEnd/integrations/wlm',
'EndToEnd/integrations/woocommerce',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ public function testFormBuilderBlockWithDefaultConfiguration(EndToEndTester $I)
$I->seeElementInDOM('button[type="submit"]');

// Confirm that the email address was added to Kit.
$I->wait(3);
$I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
Expand Down Expand Up @@ -366,7 +365,6 @@ public function testFormBuilderBlockWithFormEnabled(EndToEndTester $I)

// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$subscriber = $I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
Expand Down Expand Up @@ -471,7 +469,6 @@ public function testFormBuilderBlockWithTaggingEnabled(EndToEndTester $I)

// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$subscriber = $I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
Expand Down Expand Up @@ -575,7 +572,6 @@ public function testFormBuilderBlockWithSequenceEnabled(EndToEndTester $I)

// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$subscriber = $I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
Expand Down Expand Up @@ -710,7 +706,6 @@ public function testFormBuilderBlockWithCustomField(EndToEndTester $I)

// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$subscriber = $I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
Expand Down Expand Up @@ -1033,7 +1028,6 @@ public function testFormBuilderWithRecaptchaEnabled(EndToEndTester $I)

// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
Expand Down Expand Up @@ -1096,7 +1090,6 @@ public function testFormBuilderWithRecaptchaEnabledAndHighMinimumScore(EndToEndT
$I->click('div.wp-block-convertkit-form-builder button[type="submit"]');

// Confirm that the email address was not added to Kit, as reCAPTCHA score failed.
$I->wait(3);
$I->apiCheckSubscriberDoesNotExist($I, $emailAddress);
}

Expand Down Expand Up @@ -1167,7 +1160,6 @@ public function testFormBuilderWithStoreEntriesEnabled(EndToEndTester $I)

// Confirm that the email address was added to Kit.
$I->waitForElementVisible('.convertkit-form-builder-subscribed-message');
$I->wait(3);
$subscriber = $I->apiCheckSubscriberExists(
$I,
emailAddress: $emailAddress,
Expand Down
15 changes: 0 additions & 15 deletions tests/EndToEnd/integrations/other/ContactForm7FormCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ public function testSettingsContactForm7ToKitFormMapping(EndToEndTester $I)
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$subscriber = $I->apiCheckSubscriberExists($I, $emailAddress);

Expand Down Expand Up @@ -106,9 +103,6 @@ public function testSettingsContactForm7ToKitLegacyFormMapping(EndToEndTester $I
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$I->apiCheckSubscriberExists($I, $emailAddress);
}
Expand Down Expand Up @@ -138,9 +132,6 @@ public function testSettingsContactForm7ToKitTagMapping(EndToEndTester $I)
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$subscriber = $I->apiCheckSubscriberExists($I, $emailAddress);

Expand Down Expand Up @@ -177,9 +168,6 @@ public function testSettingsContactForm7ToKitSequenceMapping(EndToEndTester $I)
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$subscriber = $I->apiCheckSubscriberExists($I, $emailAddress);

Expand Down Expand Up @@ -245,9 +233,6 @@ public function testSettingsContactForm7SubscribeOption(EndToEndTester $I)
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$I->apiCheckSubscriberExists($I, $emailAddress);
}
Expand Down
24 changes: 0 additions & 24 deletions tests/EndToEnd/integrations/other/ForminatorCest.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,6 @@ public function testSettingsForminatorFormToKitFormMapping(EndToEndTester $I)
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$subscriber = $I->apiCheckSubscriberExists($I, $emailAddress);

Expand Down Expand Up @@ -106,9 +103,6 @@ public function testSettingsForminatorFormToKitLegacyFormMapping(EndToEndTester
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$I->apiCheckSubscriberExists($I, $emailAddress);
}
Expand Down Expand Up @@ -138,9 +132,6 @@ public function testSettingsForminatorFormToKitTagMapping(EndToEndTester $I)
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$subscriber = $I->apiCheckSubscriberExists($I, $emailAddress);

Expand Down Expand Up @@ -177,9 +168,6 @@ public function testSettingsForminatorFormToKitSequenceMapping(EndToEndTester $I
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$subscriber = $I->apiCheckSubscriberExists($I, $emailAddress);

Expand Down Expand Up @@ -270,9 +258,6 @@ public function testSettingsForminatorQuizToKitFormMapping(EndToEndTester $I)
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$I->apiCheckSubscriberExists($I, $emailAddress);
}
Expand Down Expand Up @@ -302,9 +287,6 @@ public function testSettingsForminatorQuizToKitTagMapping(EndToEndTester $I)
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$subscriber = $I->apiCheckSubscriberExists($I, $emailAddress);

Expand Down Expand Up @@ -341,9 +323,6 @@ public function testSettingsForminatorQuizToKitSequenceMapping(EndToEndTester $I
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$subscriber = $I->apiCheckSubscriberExists($I, $emailAddress);

Expand Down Expand Up @@ -409,9 +388,6 @@ public function testSettingsForminatorQuizSubscribeOption(EndToEndTester $I)
emailAddress: $emailAddress
);

// Wait for the API to update.
$I->wait(2);

// Confirm that the email address was added to Kit.
$I->apiCheckSubscriberExists($I, $emailAddress);
}
Expand Down
70 changes: 60 additions & 10 deletions tests/Support/Helper/KitAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,32 @@ public function apiEncodeState($returnTo, $clientID)
*/
public function apiCheckSubscriberExists($I, $emailAddress, $firstName = false)
{
// Run request.
$results = $this->apiRequest(
'subscribers',
'GET',
[
'email_address' => $emailAddress,
'include_total_count' => true,
// Wait for the API to update.
$I->wait(3);

// Check all subscriber states.
'status' => 'all',
]
// Retry the API request as sometimes there's a lag before the subscriber is queryable via the API.
$results = $this->retryUntil(
function () use ($emailAddress) {
$results = $this->apiRequest(
'subscribers',
'GET',
[
'email_address' => $emailAddress,
'include_total_count' => true,

// Check all subscriber states.
'status' => 'all',
]
);

// Return the results only if a subscriber was found, so
// retryUntil() will keep trying otherwise.
return ( $results['pagination']['total_count'] > 0 ) ? $results : false;
}
);

// Check at least one subscriber was returned and it matches the email address.
$I->assertNotFalse($results);
$I->assertGreaterThan(0, $results['pagination']['total_count']);
$I->assertEquals($emailAddress, $results['subscribers'][0]['email_address']);

Expand Down Expand Up @@ -192,6 +204,9 @@ public function apiCheckSubscriberHasNoTags($I, $subscriberID)
*/
public function apiCheckSubscriberDoesNotExist($I, $emailAddress)
{
// Wait for the API to update.
$I->wait(3);

// Run request.
$results = $this->apiRequest(
'subscribers',
Expand Down Expand Up @@ -324,4 +339,39 @@ public function apiRequest($endpoint, $method = 'GET', $params = array())
// Return JSON decoded response.
return json_decode($result->getBody()->getContents(), true);
}

/**
* Repeatedly invokes the given callback until it returns a truthy value, or
* the maximum number of attempts is reached.
*
* Use this to wrap API checks that can be flaky due to ingestion lag at
* Kit's end (e.g. a subscriber created via a form submission isn't always
* immediately queryable via the `subscribers` endpoint).
*
* @since 3.3.2
*
* @param callable $callback Callback to invoke. Should return the value
* to use, or false/null to indicate the
* check has not yet succeeded.
* @param int $attempts Maximum number of attempts.
* @param int $delay Seconds to wait between attempts.
* @return mixed The truthy value returned by $callback, or
* false if all attempts are exhausted.
*/
private function retryUntil(callable $callback, $attempts = 4, $delay = 3)
{
for ($i = 0; $i < $attempts; $i++) {
$result = $callback();
if ($result) {
return $result;
}

// Don't sleep after the final attempt.
if ($i < $attempts - 1) {
sleep($delay);
}
}

return false;
}
}
Loading