mirror of
https://github.com/wkulhanek/bonob.git
synced 2025-12-21 17:33:29 +01:00
Remove register button when there are no sonos devices (#39)
This commit is contained in:
@@ -36,7 +36,8 @@ export type KEY =
|
||||
| "failedToRemoveRegistration"
|
||||
| "invalidLinkCode"
|
||||
| "loginSuccessful"
|
||||
| "loginFailed";
|
||||
| "loginFailed"
|
||||
| "noSonosDevices";
|
||||
|
||||
const translations: Record<SUPPORTED_LANG, Record<KEY, string>> = {
|
||||
"en-US": {
|
||||
@@ -71,6 +72,7 @@ const translations: Record<SUPPORTED_LANG, Record<KEY, string>> = {
|
||||
invalidLinkCode: "Invalid linkCode!",
|
||||
loginSuccessful: "Login successful!",
|
||||
loginFailed: "Login failed!",
|
||||
noSonosDevices: "No sonos devices",
|
||||
},
|
||||
"nl-NL": {
|
||||
AppLinkMessage: "Sonos koppelen aan $BONOB_SONOS_SERVICE_NAME",
|
||||
@@ -104,6 +106,7 @@ const translations: Record<SUPPORTED_LANG, Record<KEY, string>> = {
|
||||
invalidLinkCode: "Ongeldige linkcode!",
|
||||
loginSuccessful: "Inloggen gelukt!",
|
||||
loginFailed: "Inloggen mislukt!",
|
||||
noSonosDevices: "Geen Sonos-apparaten",
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import {
|
||||
GetMetadataResponse,
|
||||
} from "../src/smapi";
|
||||
import {
|
||||
aDevice,
|
||||
BLONDIE,
|
||||
BOB_MARLEY,
|
||||
getAppLinkMessage,
|
||||
@@ -19,7 +20,7 @@ import { InMemoryMusicService } from "./in_memory_music_service";
|
||||
import { InMemoryLinkCodes } from "../src/link_codes";
|
||||
import { Credentials } from "../src/music_service";
|
||||
import makeServer from "../src/server";
|
||||
import { Service, bonobService, SONOS_DISABLED } from "../src/sonos";
|
||||
import { Service, bonobService, Sonos } from "../src/sonos";
|
||||
import supersoap from "./supersoap";
|
||||
import url, { URLBuilder } from "../src/url_builder";
|
||||
|
||||
@@ -171,6 +172,17 @@ describe("scenarios", () => {
|
||||
);
|
||||
const linkCodes = new InMemoryLinkCodes();
|
||||
|
||||
const fakeSonos: Sonos = {
|
||||
devices: () => Promise.resolve([aDevice({
|
||||
name: "device1",
|
||||
ip: "172.0.0.1",
|
||||
port: 4301,
|
||||
})]),
|
||||
services: () => Promise.resolve([]),
|
||||
remove: () => Promise.resolve(true),
|
||||
register: () => Promise.resolve(true),
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
musicService.clear();
|
||||
linkCodes.clear();
|
||||
@@ -255,7 +267,7 @@ describe("scenarios", () => {
|
||||
const bonobUrl = url("http://localhost:1234");
|
||||
const bonob = bonobService("bonob", 123, bonobUrl);
|
||||
const server = makeServer(
|
||||
SONOS_DISABLED,
|
||||
fakeSonos,
|
||||
bonob,
|
||||
bonobUrl,
|
||||
musicService,
|
||||
@@ -273,7 +285,7 @@ describe("scenarios", () => {
|
||||
const bonobUrl = url("http://localhost:1234/");
|
||||
const bonob = bonobService("bonob", 123, bonobUrl);
|
||||
const server = makeServer(
|
||||
SONOS_DISABLED,
|
||||
fakeSonos,
|
||||
bonob,
|
||||
bonobUrl,
|
||||
musicService,
|
||||
@@ -291,7 +303,7 @@ describe("scenarios", () => {
|
||||
const bonobUrl = url("http://localhost:1234/context-for-bonob");
|
||||
const bonob = bonobService("bonob", 123, bonobUrl);
|
||||
const server = makeServer(
|
||||
SONOS_DISABLED,
|
||||
fakeSonos,
|
||||
bonob,
|
||||
bonobUrl,
|
||||
musicService,
|
||||
|
||||
@@ -193,6 +193,7 @@ describe("server", () => {
|
||||
it("should display it", async () => {
|
||||
const res = await request(server)
|
||||
.get(bonobUrl.append({ pathname: "/" }).pathname())
|
||||
.set("accept-language", acceptLanguage)
|
||||
.send();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
@@ -212,15 +213,67 @@ describe("server", () => {
|
||||
it("should be empty", async () => {
|
||||
const res = await request(server)
|
||||
.get(bonobUrl.append({ pathname: "/" }).pathname())
|
||||
.set("accept-language", acceptLanguage)
|
||||
.send();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.text).toMatch(`<h2>${lang("devices")} \(0\)</h2>`);
|
||||
expect(res.text).not.toMatch(/class=device/);
|
||||
expect(res.text).toContain(lang("noSonosDevices"));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there are 2 devices and bonob is not registered", () => {
|
||||
describe("when sonos integration is enabled", () => {
|
||||
describe("there are no devices and bonob is not registered", () => {
|
||||
const missingBonobService = aService({
|
||||
name: "bonobMissing",
|
||||
sid: 88,
|
||||
});
|
||||
|
||||
const fakeSonos: Sonos = {
|
||||
devices: () => Promise.resolve([]),
|
||||
services: () =>
|
||||
Promise.resolve([]),
|
||||
remove: () => Promise.resolve(false),
|
||||
register: () => Promise.resolve(false),
|
||||
};
|
||||
|
||||
const server = makeServer(
|
||||
fakeSonos,
|
||||
missingBonobService,
|
||||
bonobUrl,
|
||||
new InMemoryMusicService()
|
||||
);
|
||||
|
||||
describe("devices list", () => {
|
||||
it("should be empty", async () => {
|
||||
const res = await request(server)
|
||||
.get(bonobUrl.append({ pathname: "/" }).path())
|
||||
.set("accept-language", acceptLanguage)
|
||||
.send();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.text).toMatch(`<h2>${lang("devices")} \(0\)</h2>`);
|
||||
expect(res.text).not.toMatch(/class=device/);
|
||||
expect(res.text).toContain(lang("noSonosDevices"));
|
||||
});
|
||||
});
|
||||
|
||||
describe("services", () => {
|
||||
it("should be empty", async () => {
|
||||
const res = await request(server)
|
||||
.get(bonobUrl.append({ pathname: "/" }).path())
|
||||
.set("accept-language", acceptLanguage)
|
||||
.send();
|
||||
|
||||
expect(res.status).toEqual(200);
|
||||
expect(res.text).toMatch(`<h2>${lang("services")} \(0\)</h2>`);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("there are 2 devices and bonob is not registered", () => {
|
||||
const service1 = aService({
|
||||
name: "s1",
|
||||
sid: 1,
|
||||
@@ -320,18 +373,30 @@ describe("server", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("when there are 2 devices and bonob is registered", () => {
|
||||
describe("there are 2 devices and bonob is registered", () => {
|
||||
const service1 = aService();
|
||||
|
||||
const service2 = aService();
|
||||
|
||||
const device1: Device = aDevice({
|
||||
name: "device1",
|
||||
ip: "172.0.0.1",
|
||||
port: 4301,
|
||||
});
|
||||
|
||||
const device2: Device = aDevice({
|
||||
name: "device2",
|
||||
ip: "172.0.0.2",
|
||||
port: 4302,
|
||||
});
|
||||
|
||||
const bonobService = aService({
|
||||
name: "bonobNotMissing",
|
||||
sid: 99,
|
||||
});
|
||||
|
||||
const fakeSonos: Sonos = {
|
||||
devices: () => Promise.resolve([]),
|
||||
devices: () => Promise.resolve([device1, device2]),
|
||||
services: () => Promise.resolve([service1, service2, bonobService]),
|
||||
remove: () => Promise.resolve(false),
|
||||
register: () => Promise.resolve(false),
|
||||
@@ -365,6 +430,7 @@ describe("server", () => {
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("/about", () => {
|
||||
const sonos = {
|
||||
|
||||
@@ -6,10 +6,15 @@
|
||||
<h3><%= it.lang("expectedConfig") %></h3>
|
||||
<div><%= JSON.stringify(it.bonobService) %></div>
|
||||
<br/>
|
||||
<% if(it.devices.length > 0) { %>
|
||||
<form action="<%= it.createRegistrationRoute %>" method="POST">
|
||||
<input type="submit" value="<%= it.lang("register") %>">
|
||||
</form>
|
||||
<br/>
|
||||
<% } else { %>
|
||||
<h3><%= it.lang("noSonosDevices") %></h3>
|
||||
<br/>
|
||||
<% } %>
|
||||
|
||||
<% if(it.registeredBonobService) { %>
|
||||
<h3><%= it.lang("existingServiceConfig") %></h3>
|
||||
|
||||
Reference in New Issue
Block a user