From 01f5961d447df56f9434de4b54f4f99529c0f2f7 Mon Sep 17 00:00:00 2001 From: callemand Date: Mon, 2 Oct 2023 14:07:03 +0200 Subject: [PATCH] Fix again --- server/lib/scene/scene.update.js | 12 +++++++----- server/test/lib/scene/scene.init.test.js | 4 ++-- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/server/lib/scene/scene.update.js b/server/lib/scene/scene.update.js index fa669b2b2b..a7460cd71c 100644 --- a/server/lib/scene/scene.update.js +++ b/server/lib/scene/scene.update.js @@ -40,12 +40,14 @@ async function update(selector, scene) { }, }); - await Promise.each(scene.tags, (tag) => { - db.TagScene.create({ - scene_id: existingScene.id, - name: tag.name, + if (scene.tags) { + await Promise.each(scene.tags, (tag) => { + db.TagScene.create({ + scene_id: existingScene.id, + name: tag.name, + }); }); - }); + } const plainScene = existingScene.get({ plain: true }); // Remove scene in brain if already present diff --git a/server/test/lib/scene/scene.init.test.js b/server/test/lib/scene/scene.init.test.js index 4c06fce42d..60a1dc81e9 100644 --- a/server/test/lib/scene/scene.init.test.js +++ b/server/test/lib/scene/scene.init.test.js @@ -46,7 +46,7 @@ describe('scene.init', () => { it('should init scene all scheduled task', async () => { await sceneManager.init(); - assert.callCount(scheduler.scheduleJob, 3); + assert.callCount(scheduler.scheduleJob, 4); assert.calledWithMatch( scheduler.scheduleJob, { tz: 'Europe/Paris', hour: 0, minute: 0, second: 0 }, @@ -55,7 +55,7 @@ describe('scene.init', () => { assert.calledWithMatch(scheduler.scheduleJob, '* * * * *', sinon.match.func); // Check that scheduled method send an event - scheduler.scheduleJob.getCall(2).callback(); + scheduler.scheduleJob.getCall(3).callback(); assert.calledOnceWithExactly(event.emit, 'calendar.check-if-event-is-coming'); }); });