Add locking to collection.move mutation

Add removeIndexCollision tests
This commit is contained in:
Tom Moor
2024-07-23 22:13:56 -04:00
parent fd851dfbd1
commit bbe6df19ea
2 changed files with 17 additions and 0 deletions
@@ -875,6 +875,7 @@ router.post(
const collection = await Collection.findByPk(id, {
transaction,
lock: transaction.LOCK.UPDATE,
});
authorize(user, "move", collection);
+16
View File
@@ -0,0 +1,16 @@
import { buildCollection } from "@server/test/factories";
import removeIndexCollision from "./removeIndexCollision";
describe("removeIndexCollision", () => {
it("should return the next available index", async () => {
const collection = await buildCollection({ index: "P" });
expect(
await removeIndexCollision(collection.teamId, collection.index!)
).toEqual("h");
});
it("should return existing index if no collision", async () => {
const collection = await buildCollection({ index: "%P" });
expect(await removeIndexCollision(collection.teamId, "n")).toEqual("n");
});
});