feat: reorder inventory images atomically
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-11 00:13:44 -04:00
parent 72e9a79b67
commit 0e81fc4022
15 changed files with 275 additions and 22 deletions
+13
View File
@@ -0,0 +1,13 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { moveImageInOrder } from '../../src/modules/inventory/domain/image-order.js';
test('moves one image next to its neighbor without changing the input order', () => {
const images = [{ id: 'a' }, { id: 'b' }, { id: 'c' }];
assert.deepEqual(moveImageInOrder(images, 'b', 'up').map(({ id }) => id), ['b', 'a', 'c']);
assert.deepEqual(moveImageInOrder(images, 'b', 'down').map(({ id }) => id), ['a', 'c', 'b']);
assert.deepEqual(images.map(({ id }) => id), ['a', 'b', 'c']);
assert.equal(moveImageInOrder(images, 'a', 'up'), images);
assert.equal(moveImageInOrder(images, 'c', 'down'), images);
assert.throws(() => moveImageInOrder(images, 'a', 'left'), { code: 'IMAGE_MOVE_INVALID' });
});