Skip to content

Commit

Permalink
Merge branch 'main' of github.com:jwetzell/showbridge
Browse files Browse the repository at this point in the history
  • Loading branch information
jwetzell committed May 4, 2024
2 parents b54f2d1 + 4bc2443 commit fcaf929
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 0 deletions.
87 changes: 87 additions & 0 deletions lib/tests/config/bad_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
{
"http": {
"params": {
"port": 3000
},
"triggers": [
{
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"ws": {
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"osc": {
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"midi": {
"params": {
"virtualInputName": "showbridge Input",
"virtualOutputName": "showbridge Output"
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"udp": {
"params": {
"port": 8000
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"tcp": {
"params": {
"port": 8000
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"mqtt": {
"params": {
"broker": "",
"topics": []
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"cloud": {
"params": {
"url": "",
"rooms": []
}
}
}
88 changes: 88 additions & 0 deletions lib/tests/config/cloud_single_room_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
{
"http": {
"params": {
"port": 3000
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"ws": {
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"osc": {
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"midi": {
"params": {
"virtualInputName": "showbridge Input",
"virtualOutputName": "showbridge Output"
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"udp": {
"params": {
"port": 8000
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"tcp": {
"params": {
"port": 8000
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"mqtt": {
"params": {
"broker": "",
"topics": []
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"cloud": {
"params": {
"url": "",
"room": "test"
}
}
}
63 changes: 63 additions & 0 deletions lib/tests/config/config.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import assert from 'node:assert';
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { describe, test } from 'node:test';
import Config from '../../src/config.js';
describe('Config', () => {
// TODO(jwetzell): find better way to load schema

test('create', () => {
const schema = JSON.parse(readFileSync(path.join(import.meta.dirname, '../../../schema/config.schema.json')));
const goodConfig = JSON.parse(readFileSync(path.join(import.meta.dirname, './good_config.json')));
const config = new Config(goodConfig, schema);

assert.notStrictEqual(config, undefined);
});

test('bad config', () => {
const schema = JSON.parse(readFileSync(path.join(import.meta.dirname, '../../../schema/config.schema.json')));
const badConfig = JSON.parse(readFileSync(path.join(import.meta.dirname, './bad_config.json')));

assert.throws(() => {
const config = new Config(badConfig, schema);
});
});

test('cloud room migration', () => {
const schema = JSON.parse(readFileSync(path.join(import.meta.dirname, '../../../schema/config.schema.json')));
const cloudSingleRoomConfig = JSON.parse(
readFileSync(path.join(import.meta.dirname, './cloud_single_room_config.json'))
);

const config = new Config(cloudSingleRoomConfig, schema);
assert.deepStrictEqual(config.cloud.params.rooms, ['test']);
});

test('getTriggers', () => {
const schema = JSON.parse(readFileSync(path.join(import.meta.dirname, '../../../schema/config.schema.json')));
const goodConfig = JSON.parse(readFileSync(path.join(import.meta.dirname, './good_config.json')));
const config = new Config(goodConfig, schema);

assert.notStrictEqual(config, undefined);
assert.strictEqual(config.getTriggers('http')[0].type, 'any');
assert.strictEqual(config.getTriggers('udp')[0].type, 'any');
assert.strictEqual(config.getTriggers('osc')[0], undefined);
});

test('toJSON', () => {
const schema = JSON.parse(readFileSync(path.join(import.meta.dirname, '../../../schema/config.schema.json')));
const goodConfig = JSON.parse(readFileSync(path.join(import.meta.dirname, './good_config.json')));
const config = new Config(goodConfig, schema);

assert.notStrictEqual(config, undefined);
const toJSON = config.toJSON();
console.log(toJSON);
assert.strictEqual(toJSON.http.triggers[0].comment, undefined);
assert.strictEqual(toJSON.http.triggers[0].type, 'any');
assert.strictEqual(toJSON.osc.triggers[0], undefined);
assert.strictEqual(toJSON.ws.triggers[0].actions[0].type, 'log');
assert.strictEqual(toJSON.ws.triggers[0].actions[0].comment, undefined);
assert.strictEqual(toJSON.ws.triggers[0].actions[0].transforms.length, 0);
assert.strictEqual(toJSON.$schema, undefined);
});
});
83 changes: 83 additions & 0 deletions lib/tests/config/good_config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"$schema": "./config.schema.json",
"http": {
"params": {
"port": 3000
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"ws": {
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"osc": {
"triggers": []
},
"midi": {
"params": {
"virtualInputName": "showbridge Input",
"virtualOutputName": "showbridge Output"
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"udp": {
"params": {
"port": 8000
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"tcp": {
"params": {
"port": 8000
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"mqtt": {
"params": {
"broker": "",
"topics": []
},
"triggers": [
{
"type": "any",
"enabled": true,
"actions": [{ "type": "log", "enabled": true }]
}
]
},
"cloud": {
"params": {
"url": "",
"rooms": []
}
}
}

0 comments on commit fcaf929

Please sign in to comment.