Skip to content

Don't use outdated events in functional tests #159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 2, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FP_PRIVATE_API_KEY=<FP_PRIVATE_API_KEY>
FP_VISITOR_ID=<FP_VISITOR_ID>
FP_REQUEST_ID=<FP_REQUEST_ID>
FP_VISITOR_ID_TO_DELETE=<FP_VISITOR_ID>
FP_REQUEST_ID_TO_UPDATE=<FP_REQUEST_ID>
# "eu" or "ap", the default is "us"
FP_REGION=<FP_REGION>
FP_REGION=<FP_REGION>
60 changes: 41 additions & 19 deletions run_checks.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
$dotenv->safeLoad();

$api_key = $_ENV['FP_PRIVATE_API_KEY'] ?? getenv('FP_PRIVATE_API_KEY') ?? 'Private API Key not defined';
$visitor_id = $_ENV['FP_VISITOR_ID'] ?? getenv('FP_VISITOR_ID') ?? 'Visitor ID not defined';
$visitor_id_to_delete = $_ENV['FP_VISITOR_ID_TO_DELETE'] ?? getenv('FP_VISITOR_ID_TO_DELETE') ?? false;
$request_id = $_ENV['FP_REQUEST_ID'] ?? getenv('FP_REQUEST_ID') ?? 'Request ID not defined';
$request_id_to_update = $_ENV['FP_REQUEST_ID_TO_UPDATE'] ?? getenv('FP_REQUEST_ID_TO_UPDATE') ?? false;
$region_env = $_ENV['FP_REGION'] ?? getenv('FP_REGION') ?? 'us';

Expand All @@ -47,6 +45,28 @@
// https://github.com/swagger-api/swagger-codegen/issues/11820
error_reporting(error_reporting() & ~E_DEPRECATED);

// FingerprintApi->searchEvents usage example
try {
// 3 month from now
$start = (new DateTime())->sub(new DateInterval('P3M'));
$end = new DateTime();

/** @var SearchEventsResponse $result */
list($result, $response) = $client->searchEvents(10, start: $start->getTimestamp() * 1000, end: $end->getTimestamp() * 1000);
if (!is_countable($result->getEvents()) || count($result->getEvents()) === 0) {
throw new Exception('No events found');
}
$identification_data = $result->getEvents()[0]->getProducts()->getIdentification()->getData();
$visitor_id = $identification_data->getVisitorId();
$request_id = $identification_data->getRequestId();
fwrite(STDOUT, sprintf("\n\nGot events: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->searchEvents: %s\n", $e->getMessage()));

exit(1);
}

// FingerprintApi->getVisits usage example
try {
/** @var VisitorsGetResponse $result */
list($result, $response) = $client->getVisits($visitor_id);
Expand All @@ -60,6 +80,7 @@
exit(1);
}

// FingerprintApi->deleteVisitorData usage example
if ($visitor_id_to_delete) {
try {
list($model, $response) = $client->deleteVisitorData($visitor_id_to_delete);
Expand All @@ -70,6 +91,7 @@
}
}

// FingerprintApi->getEvent usage example
try {
/** @var EventsGetResponse $result */
list($result, $response) = $client->getEvent($request_id);
Expand All @@ -83,23 +105,7 @@
exit(1);
}

try {
// 2 years from now
$start = (new DateTime())->sub(new DateInterval('P2Y'));
$end = new DateTime();

/** @var SearchEventsResponse $result */
list($result, $response) = $client->searchEvents(10, start: $start->getTimestamp() * 1000, end: $end->getTimestamp() * 1000);
if (!is_countable($result->getEvents()) || count($result->getEvents()) === 0) {
throw new Exception('No events found');
}
fwrite(STDOUT, sprintf("\n\nGot events: %s \n", $response->getBody()->getContents()));
} catch (Exception $e) {
fwrite(STDERR, sprintf("\n\nException when calling FingerprintApi->searchEvents: %s\n", $e->getMessage()));

exit(1);
}

// FingerprintApi->updateEvent usage example
if ($request_id_to_update) {
try {
$body = new EventsUpdateRequest([
Expand All @@ -113,6 +119,7 @@
}
}

// Call API asynchronously examples
$eventPromise = $client->getEventAsync($request_id);
$eventPromise->then(function ($tuple) use ($request_id) {
list($result, $response) = $tuple;
Expand All @@ -139,6 +146,7 @@
exit(1);
})->wait();

// Webhook verification example
$webhookSecret = 'secret';
$webhookData = 'data';
$webhookHeader = 'v1=1b2c16b75bd2a870c114153ccda5bcfca63314bc722fa160d690de133ccbb9db';
Expand All @@ -151,6 +159,20 @@
exit(1);
}

// Check that old events are still match expected format
try {
list($result_old) = $client->searchEvents(1, start: $start->getTimestamp() * 1000, end: $end->getTimestamp() * 1000, reverse: true);
$identification_data_old = $result_old->getEvents()[0]->getProducts()->getIdentification()->getData();
$visitor_id_old = $identification_data_old->getVisitorId();
$request_id_old = $identification_data_old->getRequestId();

list($result, $response) = $client->getEvent($request_id_old);
list($result, $response) = $client->getVisits($visitor_id_old);
fwrite(STDERR, sprintf("\n\nOld events are good\n"));
} catch (Exception $e) {
fwrite(STDERR, sprintf("\n\nException when trying to read old data: %s\n", $e->getMessage()));
}

// Enable the deprecated ArrayAccess return type warning again if needed
error_reporting(error_reporting() | E_DEPRECATED);

Expand Down
Loading