End-to-end tests are written using Postman. These must be executed in an environment where the plugin is installed and configured to communicate with both a Commercetools project and a Klaviyo account.
The end-to-end tests for realtime events use the Commercetools API to create/update data in commercetools and verify that the data is synced correctly into Klaviyo using the Klaviyo API. These tests do not have direct access to the plugin.
All tests are grouped into a Postman collection (klaviyo ct plugin e2e tests).
Each test is made of different steps (API calls) that are grouped into folders (e.g. customer created).
Example:
klaviyo ct plugin e2e tests
└───customer created
│ │ POST Obtain Access Token
│ │ POST Create customer in CT
│ │ GET Profile in Klaviyo
│
└───order created
│ POST Obtain Access Token
│ POST Create cart in CT
│ POST Create order in CT
│ GET Event in Klaviyo
The test collection is exported from postman and saved in the repository
at src/test/e2e/postman/klaviyo-e2e-tests.postman_collection.json
To edit the existing tests:
- import the test collection into postman
- edit or add new tests
- re-export the collection and overwrite the json file in the repository
https://learning.postman.com/docs/running-collections/intro-to-collection-runs/
https://learning.postman.com/docs/running-collections/building-workflows/
https://learning.postman.com/docs/writing-scripts/test-scripts/
The tests require API keys and other information to run. This sensitive information cannot be saved in the repository and should be manually added in postman.
- Create a new environment in postman with the following variables:
ct_host=https://api.us-central1.gcp.commercetools.comct_auth_url=https://auth.us-central1.gcp.commercetools.comct_client_id= use the same CT client id configured in the GitHub secretCT_E2E_CLIENT_IDct_client_secret= use the same CT secret configured in the GitHub secretCT_E2E_SECRETproject-key=klaviyo-dev(commercetools project key)klaviyoPrivateKey= the klaviyo private key for the dev klaviyo projectklaviyoBaseUrl=https://a.klaviyo.com/
- Select the new postman environment when running the test collection
To run all tests select the collection in postman and click on the Run button.
To run a single test select the directory in postman and click on the Run button.
Test can be run using the postman or newman CLI. The CLI can use an environment file exported from postman:
newman run src/test/e2e/postman/klaviyo-e2e-tests.postman_collection.json -e src/test/e2e/postman/env.postman_environment.jsonor all environment variables can be passed in via the CLI:
newman run src/test/e2e/postman/klaviyo-e2e-tests.postman_collection.json --env-var "ct_client_id=..."