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"
|
| "failedToRemoveRegistration"
|
||||||
| "invalidLinkCode"
|
| "invalidLinkCode"
|
||||||
| "loginSuccessful"
|
| "loginSuccessful"
|
||||||
| "loginFailed";
|
| "loginFailed"
|
||||||
|
| "noSonosDevices";
|
||||||
|
|
||||||
const translations: Record<SUPPORTED_LANG, Record<KEY, string>> = {
|
const translations: Record<SUPPORTED_LANG, Record<KEY, string>> = {
|
||||||
"en-US": {
|
"en-US": {
|
||||||
@@ -71,6 +72,7 @@ const translations: Record<SUPPORTED_LANG, Record<KEY, string>> = {
|
|||||||
invalidLinkCode: "Invalid linkCode!",
|
invalidLinkCode: "Invalid linkCode!",
|
||||||
loginSuccessful: "Login successful!",
|
loginSuccessful: "Login successful!",
|
||||||
loginFailed: "Login failed!",
|
loginFailed: "Login failed!",
|
||||||
|
noSonosDevices: "No sonos devices",
|
||||||
},
|
},
|
||||||
"nl-NL": {
|
"nl-NL": {
|
||||||
AppLinkMessage: "Sonos koppelen aan $BONOB_SONOS_SERVICE_NAME",
|
AppLinkMessage: "Sonos koppelen aan $BONOB_SONOS_SERVICE_NAME",
|
||||||
@@ -104,6 +106,7 @@ const translations: Record<SUPPORTED_LANG, Record<KEY, string>> = {
|
|||||||
invalidLinkCode: "Ongeldige linkcode!",
|
invalidLinkCode: "Ongeldige linkcode!",
|
||||||
loginSuccessful: "Inloggen gelukt!",
|
loginSuccessful: "Inloggen gelukt!",
|
||||||
loginFailed: "Inloggen mislukt!",
|
loginFailed: "Inloggen mislukt!",
|
||||||
|
noSonosDevices: "Geen Sonos-apparaten",
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import {
|
|||||||
GetMetadataResponse,
|
GetMetadataResponse,
|
||||||
} from "../src/smapi";
|
} from "../src/smapi";
|
||||||
import {
|
import {
|
||||||
|
aDevice,
|
||||||
BLONDIE,
|
BLONDIE,
|
||||||
BOB_MARLEY,
|
BOB_MARLEY,
|
||||||
getAppLinkMessage,
|
getAppLinkMessage,
|
||||||
@@ -19,7 +20,7 @@ import { InMemoryMusicService } from "./in_memory_music_service";
|
|||||||
import { InMemoryLinkCodes } from "../src/link_codes";
|
import { InMemoryLinkCodes } from "../src/link_codes";
|
||||||
import { Credentials } from "../src/music_service";
|
import { Credentials } from "../src/music_service";
|
||||||
import makeServer from "../src/server";
|
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 supersoap from "./supersoap";
|
||||||
import url, { URLBuilder } from "../src/url_builder";
|
import url, { URLBuilder } from "../src/url_builder";
|
||||||
|
|
||||||
@@ -171,6 +172,17 @@ describe("scenarios", () => {
|
|||||||
);
|
);
|
||||||
const linkCodes = new InMemoryLinkCodes();
|
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(() => {
|
beforeEach(() => {
|
||||||
musicService.clear();
|
musicService.clear();
|
||||||
linkCodes.clear();
|
linkCodes.clear();
|
||||||
@@ -255,7 +267,7 @@ describe("scenarios", () => {
|
|||||||
const bonobUrl = url("http://localhost:1234");
|
const bonobUrl = url("http://localhost:1234");
|
||||||
const bonob = bonobService("bonob", 123, bonobUrl);
|
const bonob = bonobService("bonob", 123, bonobUrl);
|
||||||
const server = makeServer(
|
const server = makeServer(
|
||||||
SONOS_DISABLED,
|
fakeSonos,
|
||||||
bonob,
|
bonob,
|
||||||
bonobUrl,
|
bonobUrl,
|
||||||
musicService,
|
musicService,
|
||||||
@@ -273,7 +285,7 @@ describe("scenarios", () => {
|
|||||||
const bonobUrl = url("http://localhost:1234/");
|
const bonobUrl = url("http://localhost:1234/");
|
||||||
const bonob = bonobService("bonob", 123, bonobUrl);
|
const bonob = bonobService("bonob", 123, bonobUrl);
|
||||||
const server = makeServer(
|
const server = makeServer(
|
||||||
SONOS_DISABLED,
|
fakeSonos,
|
||||||
bonob,
|
bonob,
|
||||||
bonobUrl,
|
bonobUrl,
|
||||||
musicService,
|
musicService,
|
||||||
@@ -291,7 +303,7 @@ describe("scenarios", () => {
|
|||||||
const bonobUrl = url("http://localhost:1234/context-for-bonob");
|
const bonobUrl = url("http://localhost:1234/context-for-bonob");
|
||||||
const bonob = bonobService("bonob", 123, bonobUrl);
|
const bonob = bonobService("bonob", 123, bonobUrl);
|
||||||
const server = makeServer(
|
const server = makeServer(
|
||||||
SONOS_DISABLED,
|
fakeSonos,
|
||||||
bonob,
|
bonob,
|
||||||
bonobUrl,
|
bonobUrl,
|
||||||
musicService,
|
musicService,
|
||||||
|
|||||||
@@ -193,6 +193,7 @@ describe("server", () => {
|
|||||||
it("should display it", async () => {
|
it("should display it", async () => {
|
||||||
const res = await request(server)
|
const res = await request(server)
|
||||||
.get(bonobUrl.append({ pathname: "/" }).pathname())
|
.get(bonobUrl.append({ pathname: "/" }).pathname())
|
||||||
|
.set("accept-language", acceptLanguage)
|
||||||
.send();
|
.send();
|
||||||
|
|
||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
@@ -212,15 +213,67 @@ describe("server", () => {
|
|||||||
it("should be empty", async () => {
|
it("should be empty", async () => {
|
||||||
const res = await request(server)
|
const res = await request(server)
|
||||||
.get(bonobUrl.append({ pathname: "/" }).pathname())
|
.get(bonobUrl.append({ pathname: "/" }).pathname())
|
||||||
|
.set("accept-language", acceptLanguage)
|
||||||
.send();
|
.send();
|
||||||
|
|
||||||
expect(res.status).toEqual(200);
|
expect(res.status).toEqual(200);
|
||||||
|
expect(res.text).toMatch(`<h2>${lang("devices")} \(0\)</h2>`);
|
||||||
expect(res.text).not.toMatch(/class=device/);
|
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({
|
const service1 = aService({
|
||||||
name: "s1",
|
name: "s1",
|
||||||
sid: 1,
|
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 service1 = aService();
|
||||||
|
|
||||||
const service2 = 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({
|
const bonobService = aService({
|
||||||
name: "bonobNotMissing",
|
name: "bonobNotMissing",
|
||||||
sid: 99,
|
sid: 99,
|
||||||
});
|
});
|
||||||
|
|
||||||
const fakeSonos: Sonos = {
|
const fakeSonos: Sonos = {
|
||||||
devices: () => Promise.resolve([]),
|
devices: () => Promise.resolve([device1, device2]),
|
||||||
services: () => Promise.resolve([service1, service2, bonobService]),
|
services: () => Promise.resolve([service1, service2, bonobService]),
|
||||||
remove: () => Promise.resolve(false),
|
remove: () => Promise.resolve(false),
|
||||||
register: () => Promise.resolve(false),
|
register: () => Promise.resolve(false),
|
||||||
@@ -365,6 +430,7 @@ describe("server", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("/about", () => {
|
describe("/about", () => {
|
||||||
const sonos = {
|
const sonos = {
|
||||||
|
|||||||
@@ -6,10 +6,15 @@
|
|||||||
<h3><%= it.lang("expectedConfig") %></h3>
|
<h3><%= it.lang("expectedConfig") %></h3>
|
||||||
<div><%= JSON.stringify(it.bonobService) %></div>
|
<div><%= JSON.stringify(it.bonobService) %></div>
|
||||||
<br/>
|
<br/>
|
||||||
|
<% if(it.devices.length > 0) { %>
|
||||||
<form action="<%= it.createRegistrationRoute %>" method="POST">
|
<form action="<%= it.createRegistrationRoute %>" method="POST">
|
||||||
<input type="submit" value="<%= it.lang("register") %>">
|
<input type="submit" value="<%= it.lang("register") %>">
|
||||||
</form>
|
</form>
|
||||||
<br/>
|
<br/>
|
||||||
|
<% } else { %>
|
||||||
|
<h3><%= it.lang("noSonosDevices") %></h3>
|
||||||
|
<br/>
|
||||||
|
<% } %>
|
||||||
|
|
||||||
<% if(it.registeredBonobService) { %>
|
<% if(it.registeredBonobService) { %>
|
||||||
<h3><%= it.lang("existingServiceConfig") %></h3>
|
<h3><%= it.lang("existingServiceConfig") %></h3>
|
||||||
|
|||||||
Reference in New Issue
Block a user