diff --git a/.env.example b/.env.example index 5ca59a0..491bf8c 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/.github/workflows/functional.yml b/.github/workflows/functional.yml index 28a968d..f64a0ed 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 * * *' @@ -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' ] @@ -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 @@ -39,4 +37,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 2454d8a..ad55bfa 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: diff --git a/examples/src/main/java/com/fingerprint/example/FunctionalTests.java b/examples/src/main/java/com/fingerprint/example/FunctionalTests.java index da8fc72..2fbfdec 100644 --- a/examples/src/main/java/com/fingerprint/example/FunctionalTests.java +++ b/examples/src/main/java/com/fingerprint/example/FunctionalTests.java @@ -1,31 +1,51 @@ 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_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"); 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) + ); + 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(); + 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 +65,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 +90,34 @@ 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) + ); + 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"); + } 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); }