Ability to register bonob service with sonos via button

This commit is contained in:
simojenki
2021-01-31 19:02:03 +11:00
parent 6f161abd95
commit 2ed2fce280
10 changed files with 742 additions and 316 deletions

View File

@@ -1,15 +1,12 @@
import request from "supertest";
import makeServer from "../src/server";
import { SONOS_DISABLED, Sonos, Device, Service } from "../src/sonos";
import { SONOS_DISABLED, Sonos, Device } from "../src/sonos";
import { aDevice, aService } from './builders';
describe("index", () => {
const BONOB_FOR_TEST: Service = {
name: "test bonob",
id: 999
}
describe("when sonos integration is disabled", () => {
const server = makeServer(SONOS_DISABLED, BONOB_FOR_TEST);
const server = makeServer(SONOS_DISABLED, aService());
describe("devices list", () => {
it("should be empty", async () => {
@@ -22,64 +19,61 @@ describe("index", () => {
});
describe("when there are 2 devices and bonob is not registered", () => {
const device1 : Device = {
const service1 = aService({
name: "s1",
sid: 1,
});
const service2 = aService({
name: "s2",
sid: 2,
});
const service3 = aService({
name: "s3",
sid: 3,
});
const service4 = aService({
name: "s4",
sid: 4,
});
const missingBonobService = aService({
name: "bonobMissing",
sid: 88
})
const device1: Device = aDevice({
name: "device1",
group: "group1",
ip: "172.0.0.1",
port: 4301,
services: [
{
name: "s1",
id: 1,
},
{
name: "s2",
id: 2,
},
],
};
const device2: Device = {
});
const device2: Device = aDevice({
name: "device2",
group: "group2",
ip: "172.0.0.2",
port: 4302,
services: [
{
name: "s3",
id: 3,
},
{
name: "s4",
id: 4,
},
],
}
});
const fakeSonos: Sonos = {
devices: () =>Promise.resolve([device1, device2]),
devices: () => Promise.resolve([device1, device2]),
services: () => Promise.resolve([service1, service2, service3, service4]),
register: () => Promise.resolve(false),
};
const server = makeServer(fakeSonos, BONOB_FOR_TEST);
const server = makeServer(fakeSonos, missingBonobService);
describe("devices list", () => {
it("should contain the devices returned from sonos", async () => {
const res = await request(server).get("/").send();
expect(res.status).toEqual(200);
expect(res.text).toMatch(
/device1\s+\(172.0.0.1:4301\)/
);
expect(res.text).toMatch(
/device2\s+\(172.0.0.2:4302\)/
);
expect(res.text).toMatch(/device1\s+\(172.0.0.1:4301\)/);
expect(res.text).toMatch(/device2\s+\(172.0.0.2:4302\)/);
});
});
describe("services", () => {
it("should contain a list of services returned from sonos", async () => {
const res = await request(server).get("/").send();
expect(res.status).toEqual(200);
expect(res.text).toMatch(/Services\s+4/);
expect(res.text).toMatch(/s1\s+\(1\)/);
@@ -93,64 +87,35 @@ describe("index", () => {
it("should be not-registered", async () => {
const res = await request(server).get("/").send();
expect(res.status).toEqual(200);
expect(res.text).toMatch(
/test bonob\s+\(999\) is not-registered/
);
})
expect(res.text).toMatch(/No existing service registration/);
});
});
});
describe("when there are 2 devices and bonob is registered", () => {
const device1 : Device = {
name: "device1",
group: "group1",
ip: "172.0.0.1",
port: 4301,
services: [
{
name: "s1",
id: 1,
},
{
name: "s2",
id: 2,
},
BONOB_FOR_TEST
],
};
const device2: Device = {
name: "device2",
group: "group2",
ip: "172.0.0.2",
port: 4302,
services: [
{
name: "s1",
id: 1,
},
{
name: "s4",
id: 4,
},
BONOB_FOR_TEST
],
}
const service1 = aService();
const service2 = aService();
const bonobService = aService({
name: "bonobNotMissing",
sid: 99
})
const fakeSonos: Sonos = {
devices: () =>Promise.resolve([device1, device2]),
devices: () => Promise.resolve([]),
services: () => Promise.resolve([service1, service2, bonobService]),
register: () => Promise.resolve(false),
};
const server = makeServer(fakeSonos, BONOB_FOR_TEST);
const server = makeServer(fakeSonos, bonobService);
describe("registration status", () => {
it("should be registered", async () => {
const res = await request(server).get("/").send();
expect(res.status).toEqual(200);
expect(res.text).toMatch(
/test bonob\s+\(999\) is registered/
);
})
expect(res.text).toMatch(/Existing service config/);
});
});
});
});