Allow document to be dragged to the top of a collection (#4489)
This commit is contained in:
@@ -1910,7 +1910,22 @@ describe("#documents.move", () => {
|
|||||||
});
|
});
|
||||||
const body = await res.json();
|
const body = await res.json();
|
||||||
expect(res.status).toEqual(400);
|
expect(res.status).toEqual(400);
|
||||||
expect(body.message).toEqual("index: Number must be greater than 0");
|
expect(body.message).toEqual(
|
||||||
|
"index: Number must be greater than or equal to 0"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("should move doc to the top of collection as its first child", async () => {
|
||||||
|
const { user, document, collection } = await seed();
|
||||||
|
const res = await server.post("/api/documents.move", {
|
||||||
|
body: {
|
||||||
|
token: user.getJwtToken(),
|
||||||
|
id: document.id,
|
||||||
|
collectionId: collection.id,
|
||||||
|
index: 0,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(res.status).toEqual(200);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("should move the document", async () => {
|
it("should move the document", async () => {
|
||||||
|
|||||||
@@ -208,7 +208,7 @@ export const DocumentsMoveSchema = BaseIdSchema.extend({
|
|||||||
parentDocumentId: z.string().uuid().optional(),
|
parentDocumentId: z.string().uuid().optional(),
|
||||||
|
|
||||||
/** Helps evaluate the new index in collection structure upon move */
|
/** Helps evaluate the new index in collection structure upon move */
|
||||||
index: z.number().positive().optional(),
|
index: z.number().gte(0).optional(),
|
||||||
}).refine((obj) => !(obj.parentDocumentId === obj.id), {
|
}).refine((obj) => !(obj.parentDocumentId === obj.id), {
|
||||||
message: "infinite loop detected, cannot nest a document inside itself",
|
message: "infinite loop detected, cannot nest a document inside itself",
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user