diff --git a/server/routes/api/collections/collections.ts b/server/routes/api/collections/collections.ts index acb437a222..a38ef02313 100644 --- a/server/routes/api/collections/collections.ts +++ b/server/routes/api/collections/collections.ts @@ -875,6 +875,7 @@ router.post( const collection = await Collection.findByPk(id, { transaction, + lock: transaction.LOCK.UPDATE, }); authorize(user, "move", collection); diff --git a/server/utils/removeIndexCollision.test.ts b/server/utils/removeIndexCollision.test.ts new file mode 100644 index 0000000000..bba295e0a1 --- /dev/null +++ b/server/utils/removeIndexCollision.test.ts @@ -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"); + }); +});