Files
spore/test

# Test Scripts

This directory contains JavaScript test scripts to interact with the Spore device, primarily for testing cluster event broadcasting.

## Prerequisites

These scripts require [Node.js](https://nodejs.org/) to be installed on your system.

## How to Run

### 1. HTTP Cluster Broadcast Color (`test/http-cluster-broadcast-color.js`)

This script sends HTTP POST requests to the `/api/cluster/event` endpoint on your Spore device. It broadcasts NeoPattern color changes across the cluster every 5 seconds.

**Usage:**
```
node test/http-cluster-broadcast-color.js <device-ip>
```
Example:
```
node test/http-cluster-broadcast-color.js 10.0.1.53
```
This will broadcast `{ event: "api/neopattern/color", data: { color: "#RRGGBB", brightness: 128 } }` every 5 seconds to the cluster via `/api/cluster/event`.

### 2. WS Local Color Setter (`test/ws-color-client.js`)

Connects to the device WebSocket (`/ws`) and sets a solid color locally (non-broadcast) every 5 seconds by firing `api/neopattern/color`.

**Usage:**
```
node test/ws-color-client.js ws://<device-ip>/ws
```
Example:
```
node test/ws-color-client.js ws://10.0.1.53/ws
```

### 3. WS Cluster Broadcast Color (`test/ws-cluster-broadcast-color.js`)

Connects to the device WebSocket (`/ws`) and broadcasts a color change to all peers every 5 seconds by firing `cluster/broadcast` with the proper envelope.

**Usage:**
```
node test/ws-cluster-broadcast-color.js ws://<device-ip>/ws
```
Example:
```
node test/ws-cluster-broadcast-color.js ws://10.0.1.53/ws
```

### 4. WS Cluster Broadcast Rainbow (`test/ws-cluster-broadcast-rainbow.js`)

Broadcasts a smooth rainbow color transition over WebSocket using `cluster/broadcast` and the `api/neopattern/color` event. Update rate defaults to `UPDATE_RATE` in the script (e.g., 100 ms).

**Usage:**
```
node test/ws-cluster-broadcast-rainbow.js ws://<device-ip>/ws
```
Example:
```
node test/ws-cluster-broadcast-rainbow.js ws://10.0.1.53/ws
```
Note: Very fast update intervals (e.g., 10 ms) may saturate links or the device.