# Testing Main Module

While we encourage setting up automated testing using Mocha you can also test your main module methods manually. Typically you will want to test the output of the `doLookup` method to make sure it is doing what you expect. To run the `doLookup` method in isolation from Polarity you can create a Node.js program that `requires` it and then manually call `doLookup`.

Start by creating a file called `test-runner.js` and placing it in the root directory of your integration.

In the `test-runner.js` file require your main-module (if you are following the default guidelines this file will be called `integration.js`).

{% code title="test-runner.js" %}

```javascript
'use strict';

let myIntegration = require('./integration');
```

{% endcode %}

Next, create an options object and set any option values required by your integration. These will be passed to the `doLookup` method.

{% code title="test-runner.js" %}

```javascript
let options = {
    apiKey: '<set your api key>',
    warnOnLookupLimit: true
};
```

{% endcode %}

Create an array of entity objects to be passed to your `doLookup` method. Note that you only need to provide the properties used by your integration.

{% code title="test-runner.js" %}

```javascript
let entities = [
    {
        value: 'fd904addbdfe548c22ffa5223ed9eee7',
        isHash: true
    },
    {
        value: '95.108.142.138',
        isIPv4: true
    }
];
```

{% endcode %}

Call the `doLookup` method of your integration passing in the `entities`, `options` and a callback method.

{% code title="test-runner.js" %}

```javascript
myIntegration.doLookup(entities, options, function(err, result){
   if(err){
       console.info("ERRORS:");
       console.info(JSON.stringify(err, null, 4));
   }else{
       console.info("RESULTS:");
       console.info(JSON.stringify(result, null, 4));
   }
});
```

{% endcode %}

Execute your program from the command line on the server using `node`. The program will output any errors or the result. In addition, if you have syntax errors in your integration those will be caught and displayed in the console.

```bash
node test-runner.js
```

## Final Code

The following is the full `test-runner.js` program which can be adapted to your needs.

{% code title="test-runner.js" %}

```javascript
'use strict';

let myIntegration = require('./integration');

let options = {
    apiKey: '<set your api key>',
    warnOnLookupLimit: true
};

let entities = [
    {
        value: 'fd904addbdfe548c22ffa5223ed9eee7',
        isHash: true
    },
    {
        value: '95.108.142.138',
        isIPv4: true
    }
];

myIntegration.doLookup(entities, options, function(err, result){
   if(err){
       console.info("ERRORS:");
       console.info(JSON.stringify(err, null, 4));
   }else{
       console.info("RESULTS:");
       console.info(JSON.stringify(result, null, 4));
   }
});
```

{% endcode %}

{% hint style="info" %}
In most cases you can rely on the automated error reporting from the Polarity UI.  Creating a `test-runner` as in the example above is valuable when you are trying to trace through particular sections of code to identify issues.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.polarity.io/integrations/build-an-integration/debugging/testing-main-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
