Skip to content

Commit

Permalink
fix: bulk publish (#6006)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanRibbens committed Apr 24, 2024
1 parent ad01c67 commit c11600a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/payload/src/collections/operations/update.ts
Expand Up @@ -276,7 +276,7 @@ async function update<TSlug extends keyof GeneratedTypes['collections']>(
// Update
// /////////////////////////////////////

if (!shouldSaveDraft) {
if (!shouldSaveDraft || data._status === 'published') {
result = await req.payload.db.updateOne({
id,
collection: collectionConfig.slug,
Expand Down
2 changes: 1 addition & 1 deletion packages/payload/src/collections/operations/updateByID.ts
Expand Up @@ -262,7 +262,7 @@ async function updateByID<TSlug extends keyof GeneratedTypes['collections']>(
// Update
// /////////////////////////////////////

if (!shouldSaveDraft) {
if (!shouldSaveDraft || data._status === 'published') {
result = await req.payload.db.updateOne({
id,
collection: collectionConfig.slug,
Expand Down
20 changes: 19 additions & 1 deletion test/versions/int.spec.ts
Expand Up @@ -437,6 +437,7 @@ describe('Versions', () => {
collection,
data: {
title: patchedTitle,
_status: 'draft',
},
draft: true,
locale: 'en',
Expand All @@ -450,6 +451,7 @@ describe('Versions', () => {
collection,
data: {
title: spanishTitle,
_status: 'draft',
},
draft: true,
locale: 'es',
Expand Down Expand Up @@ -529,9 +531,11 @@ describe('Versions', () => {
},
})

// bulk publish
const updated = await payload.update({
collection: draftCollectionSlug,
data: {
_status: 'published',
description: 'updated description',
},
draft: true,
Expand All @@ -544,8 +548,20 @@ describe('Versions', () => {

const updatedDoc = updated.docs?.[0]

// get the published doc
const findResult = await payload.find({
collection: draftCollectionSlug,
where: {
id: { equals: doc.id },
},
})

const findDoc = findResult.docs?.[0]

expect(updatedDoc.description).toStrictEqual('updated description')
expect(updatedDoc.title).toStrictEqual('updated title') // probably will fail
expect(updatedDoc.title).toStrictEqual('updated title')
expect(findDoc.title).toStrictEqual('updated title')
expect(findDoc.description).toStrictEqual('updated description')
})
})

Expand Down Expand Up @@ -1236,6 +1252,7 @@ describe('Versions', () => {
await payload.updateGlobal({
slug: globalSlug,
data: {
_status: 'draft',
title: updatedTitle2,
},
draft: true,
Expand All @@ -1245,6 +1262,7 @@ describe('Versions', () => {
await payload.updateGlobal({
slug: globalSlug,
data: {
_status: 'draft',
title: updatedTitle2,
},
draft: true,
Expand Down

0 comments on commit c11600a

Please sign in to comment.