Skip to content

Commit

Permalink
Fix #2000 : Should not delete tags when patching scene without tags (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Gilles authored Apr 19, 2024
1 parent 1154325 commit 2251726
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
11 changes: 5 additions & 6 deletions server/lib/scene/scene.update.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,12 @@ async function update(selector, scene) {

await existingScene.update(scene);

await db.TagScene.destroy({
where: {
scene_id: existingScene.id,
},
});

if (scene.tags) {
await db.TagScene.destroy({
where: {
scene_id: existingScene.id,
},
});
await db.TagScene.bulkCreate(
scene.tags.map((tag) => ({
scene_id: existingScene.id,
Expand Down
11 changes: 11 additions & 0 deletions server/test/lib/scene/scene.update.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ describe('scene.update', () => {
assertSinon.calledOnce(brain.addNamedEntity);
assertSinon.calledOnce(brain.removeNamedEntity);
});
it('should not delete tags when patching scene', async () => {
const scene = await sceneManager.update('test-scene', {
name: 'Name updated',
tags: [{ name: 'tag 1' }],
});
expect(scene.tags).deep.eq([{ name: 'tag 1' }]);
const scene2 = await sceneManager.update('test-scene', {
name: 'Name updated 2',
});
expect(scene2.tags).deep.eq([{ name: 'tag 1' }]);
});
it('should return not found', async () => {
const promise = sceneManager.update('not-found-scene', {
name: 'Updated scene',
Expand Down

0 comments on commit 2251726

Please sign in to comment.