awaBerry Testing Guide -> Testing: methodtest

Testing: methodtest

Summary

This document outlines the technical procedures for executing local integration tests for the connectToDevice and executeCommand methods using the awaBerry Connect agent. It covers essential preconditions such as awaBerry Connect installation and account setup, environment configuration via a .env file for project credentials and device details, and steps for installing dependencies. Detailed instructions are provided for testing device connectivity, executing arbitrary commands, and managing long-running commands by polling for additional results, ensuring robust validation of the agent's core functionalities.

Description

This guide explains how to run the local method tests for connectToDevice and executeCommand.

Preconditions

Before running the tests, ensure you have the following:

  • awaBerry Connect Installed: The awaBerry Connect agent must be installed on the device you want to connect to. You can download it from download.awaberry.com.
  • awaBerry Remote Account: You need an account at app.awaberry.com with web-based access to your device.
  • awaBerry Agentic Project: You must have a project created in the "awaBerry Agentic" section of the app. From this project, you will need your <projectKey> and <projectSecret>.

Configuration

  1. Create .env file:
    In the root directory of this project, create a file named .env.
  2. Add Credentials:
    Add the following content to the .env file, replacing the placeholder values with your actual project credentials and device name:
    projectKey=your_project_key
    projectSecret=your_project_secret
    deviceName=your_device_name
    
  3. Install Dependencies:
    Open your terminal in the project's root directory and run:
    npm install
    

Running the Tests

Run the test files from your project's root directory.

1. Test Device Connection

This test will attempt to connect to your specified device.

The testConnectToDevice.js file reads connection details from a .env file in the project root and uses them to call the connectToDevice function. Upon successful connection, it updates the .env file with the obtained sessionToken and deviceuuid.

To run this test:

node test/methodtest/testConnectToDevice.js

Expected end of test output:

✅ Method execution was succesful

2. Test Command Execution

If the connection test is successful, you can use this command to execute a test command on the connected device.

The testExecuteCommand.js file reads sessionToken and deviceuuid from a .env file, prompts the user for a command via the console, and then calls the executeCommand function. Ensure these values are set, typically after a successful connection test.

To run this test:

node test/methodtest/testExecuteCommand.js

Enter a simple command such as 'date' or 'ls' to test the command execution. On success, the JSON result of the command is printed, ending with:

✅ Method execution was succesful

3. Test Additional Command Results (Long-Running Commands)

This test is designed to handle long-running commands by executing a command and then continuously polling for additional results until the command has completed on the terminal or the user explicitly quits. It also provides an option to send a 'stop command' if the initial command is still running when the user requests to quit.

The testGetAdditionalCommandResults.js file requires sessionToken and deviceuuid to be set in your .env file, similar to the command execution test.

To run this test:

node test/methodtest/testGetAdditionalCommandResults.js

During execution, you can press 'q' to quit the polling loop and optionally send a stop command.

Troubleshooting

  • Missing or invalid inputs:
    Double-check the provided values in projectKey and projectSecret and try again.
  • Device with name '...' not found:
    Verify the deviceName in your .env file matches an active device associated with your awaBerry Agentic project.

Support

For documentation and questions: