From ac9f97f60d5d87bc58a50de42bdb4fdf9339e1ec Mon Sep 17 00:00:00 2001 From: Ilya Taratukhin Date: Thu, 27 Mar 2025 13:03:16 +0100 Subject: [PATCH 1/4] chore: don't use outdated events in functional tests --- .env.example | 6 +- .../fingerprint/example/FunctionalTests.java | 55 ++++++++++++++----- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/.env.example b/.env.example index 5ca59a02..491bf8cb 100644 --- a/.env.example +++ b/.env.example @@ -1,5 +1,5 @@ FPJS_API_SECRET= -FPJS_VISITOR_ID= -FPJS_REQUEST_ID= +FPJS_VISITOR_ID_TO_DELETE= +FPJS_REQUEST_ID_TO_UPDATE= # "eu" or "ap", "us" is the default -FPJS_API_REGION= \ No newline at end of file +FPJS_API_REGION= diff --git a/examples/src/main/java/com/fingerprint/example/FunctionalTests.java b/examples/src/main/java/com/fingerprint/example/FunctionalTests.java index da8fc72a..0ed7b5fd 100644 --- a/examples/src/main/java/com/fingerprint/example/FunctionalTests.java +++ b/examples/src/main/java/com/fingerprint/example/FunctionalTests.java @@ -1,23 +1,22 @@ package com.fingerprint.example; import com.fingerprint.api.FingerprintApi; -import com.fingerprint.model.EventsGetResponse; -import com.fingerprint.model.EventsUpdateRequest; -import com.fingerprint.model.SearchEventsResponse; -import com.fingerprint.model.VisitorsGetResponse; +import com.fingerprint.model.*; import com.fingerprint.sdk.ApiClient; import com.fingerprint.sdk.ApiException; import com.fingerprint.sdk.Configuration; import java.sql.Timestamp; +import java.time.Instant; +import java.time.temporal.ChronoUnit; import java.util.Date; import java.util.HashMap; public class FunctionalTests { public static void main(String... args) { String FPJS_API_SECRET = System.getenv("FPJS_API_SECRET"); - String FPJS_VISITOR_ID = System.getenv("FPJS_VISITOR_ID"); - String FPJS_REQUEST_ID = System.getenv("FPJS_REQUEST_ID"); + String FPJS_VISITOR_ID = ""; + String FPJS_REQUEST_ID = ""; String FPJS_API_REGION = System.getenv("FPJS_API_REGION"); String FPJS_REQUEST_ID_TO_UPDATE = System.getenv("FPJS_REQUEST_ID_TO_UPDATE"); String FPJS_VISITOR_ID_TO_DELETE = System.getenv("FPJS_VISITOR_ID_TO_DELETE"); @@ -26,6 +25,23 @@ public static void main(String... args) { ApiClient client = Configuration.getDefaultApiClient(FPJS_API_SECRET, FPJS_API_REGION != null ? FPJS_API_REGION : "us"); FingerprintApi api = new FingerprintApi(client); + long end = Instant.now().toEpochMilli(); + long start = Instant.now().minus(90L, ChronoUnit.DAYS).toEpochMilli(); + + // Search events + try { + final SearchEventsResponse events = api.searchEvents(2, new FingerprintApi.SearchEventsOptionalParams() + .setStart(start) + .setEnd(end) + ); + Identification firstEventIdentificationData = events.getEvents().get(0).getProducts().getIdentification().getData(); + FPJS_VISITOR_ID = firstEventIdentificationData.getVisitorId(); + FPJS_REQUEST_ID = firstEventIdentificationData.getRequestId(); + System.out.println(events.getEvents()); + } catch (ApiException e) { + System.err.println("Exception when calling FingerprintApi.searchEvents:" + e.getMessage()); + System.exit(1); + } // Get identification event try { @@ -45,15 +61,6 @@ public static void main(String... args) { System.exit(1); } - // Search events - try { - final SearchEventsResponse events = api.searchEvents(2, new FingerprintApi.SearchEventsOptionalParams().setBot("bad")); - System.out.println(events.getEvents()); - } catch (ApiException e) { - System.err.println("Exception when calling FingerprintApi.searchEvents:" + e.getMessage()); - System.exit(1); - } - // Update identification event if (FPJS_REQUEST_ID_TO_UPDATE != null) { @@ -79,6 +86,24 @@ public static void main(String... args) { } } + // Check that old events are still match expected format + try { + final SearchEventsResponse oldEvents = api.searchEvents(2, new FingerprintApi.SearchEventsOptionalParams() + .setStart(start) + .setEnd(end) + .setReverse(true) + ); + Identification oldEventIdentificationData = oldEvents.getEvents().get(0).getProducts().getIdentification().getData(); + String FPJS_OLD_VISITOR_ID = oldEventIdentificationData.getVisitorId(); + String FPJS_OLD_REQUEST_ID = oldEventIdentificationData.getRequestId(); + api.getEvent(FPJS_OLD_REQUEST_ID); + api.getVisits(FPJS_OLD_VISITOR_ID, null, null, null, null, null); + System.out.println("Old events are good"); + } catch (ApiException e) { + System.err.println("Exception when trying to read old data:" + e.getMessage()); + System.exit(1); + } + System.out.println("Checks Passed"); System.exit(0); } From c6ce9b6d55608efe78341b4c4b65c1ec9b2693e9 Mon Sep 17 00:00:00 2001 From: Ilya Taratukhin Date: Tue, 1 Apr 2025 17:25:26 +0200 Subject: [PATCH 2/4] chore: use latest ubuntu as a tests runner --- .github/workflows/functional.yml | 4 ++-- .github/workflows/test.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 28a968d1..49cd57bd 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -11,7 +11,7 @@ on: jobs: functional_tests: name: "Functional Tests Java ${{ matrix.java }}" - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest strategy: matrix: java: [ '11', '17', '21' ] @@ -39,4 +39,4 @@ jobs: notification_title: 'Java SDK Functional Tests has {status_message}' job_status: ${{ needs.functional_tests.result }} secrets: - SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} + SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }} diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2454d8aa..ad55bfa0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -7,7 +7,7 @@ on: jobs: test: - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest name: Java ${{ matrix.Java }} strategy: matrix: From 549f81bf09487220f9de1e415993fc19a702b889 Mon Sep 17 00:00:00 2001 From: Ilya Taratukhin Date: Tue, 1 Apr 2025 17:30:11 +0200 Subject: [PATCH 3/4] chore: apply review findings --- .../fingerprint/example/FunctionalTests.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/examples/src/main/java/com/fingerprint/example/FunctionalTests.java b/examples/src/main/java/com/fingerprint/example/FunctionalTests.java index 0ed7b5fd..2fbfdecd 100644 --- a/examples/src/main/java/com/fingerprint/example/FunctionalTests.java +++ b/examples/src/main/java/com/fingerprint/example/FunctionalTests.java @@ -15,11 +15,11 @@ public class FunctionalTests { public static void main(String... args) { String FPJS_API_SECRET = System.getenv("FPJS_API_SECRET"); - String FPJS_VISITOR_ID = ""; - String FPJS_REQUEST_ID = ""; String FPJS_API_REGION = System.getenv("FPJS_API_REGION"); String FPJS_REQUEST_ID_TO_UPDATE = System.getenv("FPJS_REQUEST_ID_TO_UPDATE"); String FPJS_VISITOR_ID_TO_DELETE = System.getenv("FPJS_VISITOR_ID_TO_DELETE"); + String FPJS_VISITOR_ID = ""; + String FPJS_REQUEST_ID = ""; // Create a new instance of the API client ApiClient client = Configuration.getDefaultApiClient(FPJS_API_SECRET, FPJS_API_REGION != null ? FPJS_API_REGION : "us"); @@ -34,6 +34,10 @@ public static void main(String... args) { .setStart(start) .setEnd(end) ); + if (events.getEvents().isEmpty()) { + System.err.println("FingerprintApi.searchEvents: is empty"); + System.exit(1); + } Identification firstEventIdentificationData = events.getEvents().get(0).getProducts().getIdentification().getData(); FPJS_VISITOR_ID = firstEventIdentificationData.getVisitorId(); FPJS_REQUEST_ID = firstEventIdentificationData.getRequestId(); @@ -93,9 +97,19 @@ public static void main(String... args) { .setEnd(end) .setReverse(true) ); + if (oldEvents.getEvents().isEmpty()) { + System.err.println("FingerprintApi.searchEvents: is empty for old events"); + System.exit(1); + } Identification oldEventIdentificationData = oldEvents.getEvents().get(0).getProducts().getIdentification().getData(); String FPJS_OLD_VISITOR_ID = oldEventIdentificationData.getVisitorId(); String FPJS_OLD_REQUEST_ID = oldEventIdentificationData.getRequestId(); + + if (FPJS_VISITOR_ID.equals(FPJS_OLD_VISITOR_ID) || FPJS_REQUEST_ID.equals(FPJS_OLD_REQUEST_ID)) { + System.err.println("Old events are identical to new"); + System.exit(1); + } + api.getEvent(FPJS_OLD_REQUEST_ID); api.getVisits(FPJS_OLD_VISITOR_ID, null, null, null, null, null); System.out.println("Old events are good"); From 1fdd8c92a17d871ea61ee6b5d486f91c6178356f Mon Sep 17 00:00:00 2001 From: Ilya Taratukhin Date: Tue, 1 Apr 2025 17:33:23 +0200 Subject: [PATCH 4/4] chore: use `push` event instead of `pull_request` target for functional tests --- .github/workflows/functional.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/functional.yml b/.github/workflows/functional.yml index 49cd57bd..f64a0ed9 100644 --- a/.github/workflows/functional.yml +++ b/.github/workflows/functional.yml @@ -1,9 +1,9 @@ name: Functional Tests on: - pull_request_target: - branches: - - '*' + push: + branches-ignore: + - main workflow_dispatch: schedule: - cron: '0 5 * * *' @@ -28,8 +28,6 @@ jobs: env: FPJS_API_SECRET: "${{ secrets.FPJS_API_SECRET }}" FPJS_API_REGION: "${{ secrets.FPJS_API_REGION }}" - FPJS_VISITOR_ID: "${{ secrets.FPJS_VISITOR_ID }}" - FPJS_REQUEST_ID: "${{ secrets.FPJS_REQUEST_ID }}" report_status: needs: functional_tests