From 7891a8ee8b942b160fc2ab84956a11f6c7029a2c Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Fri, 19 Mar 2021 08:01:13 -0700 Subject: [PATCH] fix: Cannot create collection if all collections deleted --- server/api/collections.js | 5 ++++- server/api/collections.test.js | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/server/api/collections.js b/server/api/collections.js index a516f34c..bdee2e3f 100644 --- a/server/api/collections.js +++ b/server/api/collections.js @@ -74,7 +74,10 @@ router.post("collections.create", auth(), async (ctx) => { ); } } else { - index = fractionalIndex(null, collections[0].index); + index = fractionalIndex( + null, + collections.length ? collections[0].index : null + ); } index = await removeIndexCollision(user.teamId, index); diff --git a/server/api/collections.test.js b/server/api/collections.test.js index a68be9bd..2a4c816f 100644 --- a/server/api/collections.test.js +++ b/server/api/collections.test.js @@ -1002,7 +1002,7 @@ describe("#collections.create", () => { }); it("should create collection", async () => { - const { user } = await seed(); + const user = await buildUser(); const res = await server.post("/api/collections.create", { body: { token: user.getJwtToken(), name: "Test" }, });