Add ability to report if bonob is registered

This commit is contained in:
simojenki
2021-01-30 23:02:58 +11:00
parent 494e36092d
commit ad09a88de8
5 changed files with 170 additions and 46 deletions

View File

@@ -1,12 +1,19 @@
import { SonosManager, SonosDevice } from "@svrooij/sonos";
import { MusicServicesService } from "@svrooij/sonos/lib/services";
import { shuffle } from 'underscore';
import { shuffle } from "underscore";
jest.mock("@svrooij/sonos");
import { AMAZON_MUSIC, APPLE_MUSIC, AUDIBLE } from "./music_services";
import sonos, { SONOS_DISABLED, asDevice, Device, servicesFrom } from "../src/sonos";
import sonos, {
SONOS_DISABLED,
asDevice,
Device,
servicesFrom,
registrationStatus,
BONOB_SERVICE,
} from "../src/sonos";
const mockSonosManagerConstructor = <jest.Mock<SonosManager>>SonosManager;
@@ -15,6 +22,28 @@ describe("sonos", () => {
mockSonosManagerConstructor.mockClear();
});
describe("bonobRegistrationStatus", () => {
describe("when bonob is registered", () => {
it("should return 'registered'", () => {
expect(
registrationStatus([
{ id: 1, name: "not bonob" },
BONOB_SERVICE,
{ id: 2, name: "also not bonob" },
])
).toBe("registered");
});
});
describe("when bonob is not registered", () => {
it("should return not-registered", () => {
expect(registrationStatus([{ id: 1, name: "not bonob" }])).toBe(
"not-registered"
);
});
});
});
describe("asDevice", () => {
it("should convert", async () => {
const musicServicesService = {
@@ -71,12 +100,19 @@ describe("sonos", () => {
const service4 = { id: 4, name: "A" };
const d1 = someDevice({ services: shuffle([service1, service2]) });
const d2 = someDevice({ services: shuffle([service1, service2, service3]) });
const d2 = someDevice({
services: shuffle([service1, service2, service3]),
});
const d3 = someDevice({ services: shuffle([service4]) });
const devices: Device[] = [d1, d2, d3];
expect(servicesFrom(devices)).toEqual([service4, service2, service3, service1])
expect(servicesFrom(devices)).toEqual([
service4,
service2,
service3,
service1,
]);
});
});