Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log an error in applyPreset if room in list cannot be found with tests #123

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/prototypes/SonosSystem/applyPreset.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,16 @@ function applyPreset(preset) {
let coordinator;

promise = promise.then(() => {
players = preset.players.map(playerInfo => this.getPlayer(playerInfo.roomName));
players = preset.players.map(playerInfo => {
const result = this.getPlayer(playerInfo.roomName);
if (!result) {
logger.error(`preset ${preset.favorite}: bad room name ${playerInfo.roomName}`);
}

// it will be undefined which results in an error later. We filter it below
// so that the bad or missing room is ignored and the other players work.
return result;
}).filter(player => player !== undefined);
});

promise = promise.then(() => {
Expand Down
14 changes: 11 additions & 3 deletions test/unit/prototypes/SonosSystem/applyPreset.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ describe('SonosSystem.applyPreset', () => {
let coordinator;
let member;
let preset;
let badRoomPreset;
let superfluousPlayer;
let otherPlayer;

Expand Down Expand Up @@ -84,7 +85,7 @@ describe('SonosSystem.applyPreset', () => {
system.getPlayer.withArgs('Office').returns(member);

preset = {
players: [{ roomName: 'Kitchen', volume: 1 }, { roomName: 'Other room', volume: 2 }, {
players: [{ roomName: 'Kitchen', volume: 1 }, { roomName: 'Other room', volume: 2 }, { roomName: 'Bad room', volume: 2 }, {
roomName: 'Office',
volume: 3,
mute: true
Expand All @@ -102,11 +103,17 @@ describe('SonosSystem.applyPreset', () => {
sleep: 600
};
});
badRoomPreset = preset;

describe('When applying preset', () => {

beforeEach(() => {
return applyPreset.call(system, preset);
let result = applyPreset.call(system, preset);
if (preset === badRoomPreset) {
expect(result.stderr).to.contain('ERROR preset My favorite: bad room name Bad room');
}

return result;
});

it('Pauses all zones', () => {
Expand Down Expand Up @@ -181,7 +188,7 @@ describe('SonosSystem.applyPreset', () => {
describe('When it contains an mute=false', () => {

beforeEach(() => {
preset.players[2].mute = false;
preset.players[3].mute = false;
});

beforeEach(() => {
Expand Down Expand Up @@ -289,4 +296,5 @@ describe('SonosSystem.applyPreset', () => {
expect(player.setAVTransport.firstCall.args[1]).equal(preset.metadata);
});
});

});