Integration testing

Learn how to write integration tests for your Nuxt integration.

When writing integration tests, it is generally recommended to avoid relying on external services for faster and more reliable results.

The Nuxt SDK allows you to set up a custom endpoint so you can mock responses and test your integration without relying on our servers.

Set a custom endpoint

You can run tests against a mock server by specifying a custom base endpoint URL in your Nuxt configuration:

1234567
export default defineNuxtConfig({  modules: ['@croct/plug-nuxt'],  croct: {    appId: '00000000-0000-0000-0000-000000000000',    baseEndpointUrl: 'http://localhost:3010',  },})

These are the endpoints you can mock:

PathDescription
/client/web/cidEndpoint for assigning a CID.
/client/web/evaluateEndpoint for query evaluation.
/client/web/trackEndpoint for tracking events.
/contentEndpoint for content retrieval.

If you enable test mode, you do not need to mock the /client/web/track endpoint, as the SDK replaces the transport layer with a fake one that simulates successful calls.

Create a mock server

Mockoon is a free and open-source tool for quickly mocking APIs and services. You can define rules to mock different responses based on request parameters, which is perfect for testing different slots and query results.

To get started, install the Mockoon CLI:

npm install -g @mockoon/cli

Then, create a configuration file named croct.json with your mock rules. The easiest way to do this is to use the Mockoon desktop app, which generates a configuration file for you.

Lastly, run the following command to start the mock server:

mockoon start --config croct.json

After starting the mock server, accessing your application should return the mocked content and query results.