diff --git a/packages/payload/src/collections/operations/update.ts b/packages/payload/src/collections/operations/update.ts index f080474c2..83da92765 100644 --- a/packages/payload/src/collections/operations/update.ts +++ b/packages/payload/src/collections/operations/update.ts @@ -129,6 +129,7 @@ export const updateOperation = async ({ collection: collectionConfig.slug, locale, + pagination: false, req, where: versionsWhere, }) @@ -266,7 +267,8 @@ export const updateOperation = async = (props) => { {collection?.versions?.drafts ? ( diff --git a/test/versions/e2e.spec.ts b/test/versions/e2e.spec.ts index e31e9f13f..b3abf8dbd 100644 --- a/test/versions/e2e.spec.ts +++ b/test/versions/e2e.spec.ts @@ -19,7 +19,6 @@ * - tabs * - text * - richtext - * - restore version * - specify locales to show */ diff --git a/test/versions/int.spec.ts b/test/versions/int.spec.ts index 6a264922b..921ca12a2 100644 --- a/test/versions/int.spec.ts +++ b/test/versions/int.spec.ts @@ -1,5 +1,7 @@ import type { Payload } from 'payload' +import { ValidationError } from 'payload/errors' + import type { NextRESTClient } from '../helpers/NextRESTClient.js' import { devUser } from '../credentials.js' @@ -472,7 +474,84 @@ describe('Versions', () => { expect(draftPost.title.en).toBe(patchedTitle) expect(draftPost.title.es).toBe(spanishTitle) }) + + it('should validate when publishing with the draft arg', async () => { + // no title (not valid for publishing) + const doc = await payload.create({ + collection: draftCollectionSlug, + data: { + description: 'desc', + }, + draft: true, + }) + + await expect(async () => { + // should not be able to publish a doc that fails validation + await payload.update({ + id: doc.id, + collection: draftCollectionSlug, + data: { _status: 'published' }, + draft: true, + }) + }).rejects.toThrow(ValidationError) + + // succeeds but returns zero docs updated, with an error + const updateManyResult = await payload.update({ + collection: draftCollectionSlug, + data: { _status: 'published' }, + draft: true, + where: { + id: { equals: doc.id }, + }, + }) + + expect(updateManyResult.docs).toHaveLength(0) + expect(updateManyResult.errors).toStrictEqual([ + { id: doc.id, message: 'The following field is invalid: title' }, + ]) + }) }) + + describe('Update Many', () => { + it('should update many using drafts', async () => { + const doc = await payload.create({ + collection: draftCollectionSlug, + data: { + title: 'initial value', + description: 'description to bulk update', + _status: 'published', + }, + }) + + await payload.update({ + collection: draftCollectionSlug, + id: doc.id, + draft: true, + data: { + title: 'updated title', + }, + }) + + const updated = await payload.update({ + collection: draftCollectionSlug, + data: { + description: 'updated description', + }, + draft: true, + where: { + id: { + in: [doc.id], + }, + }, + }) + + const updatedDoc = updated.docs?.[0] + + expect(updatedDoc.description).toStrictEqual('updated description') + expect(updatedDoc.title).toStrictEqual('updated title') // probably will fail + }) + }) + describe('Delete', () => { let postToDelete beforeEach(async () => {