chore: merges versions simplification
This commit is contained in:
@@ -39,6 +39,7 @@ export default buildConfig({
|
||||
upload: {
|
||||
staticURL: '/media',
|
||||
staticDir: './media',
|
||||
mimeTypes: ['image/png', 'image/jpg', 'image/jpeg', 'image/svg+xml'],
|
||||
resizeOptions: {
|
||||
width: 1280,
|
||||
height: 720,
|
||||
|
||||
56
test/versions/collections/Versions.ts
Normal file
56
test/versions/collections/Versions.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import type { CollectionConfig } from '../../../src/collections/config/types';
|
||||
|
||||
const VersionPosts: CollectionConfig = {
|
||||
slug: 'version-posts',
|
||||
admin: {
|
||||
useAsTitle: 'title',
|
||||
defaultColumns: ['title', 'description', 'createdAt'],
|
||||
preview: () => 'https://payloadcms.com',
|
||||
},
|
||||
versions: {
|
||||
drafts: false,
|
||||
maxPerDoc: 35,
|
||||
retainDeleted: false,
|
||||
},
|
||||
access: {
|
||||
read: ({ req: { user } }) => {
|
||||
if (user) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return {
|
||||
or: [
|
||||
{
|
||||
_status: {
|
||||
equals: 'published',
|
||||
},
|
||||
},
|
||||
{
|
||||
_status: {
|
||||
exists: false,
|
||||
},
|
||||
},
|
||||
],
|
||||
};
|
||||
},
|
||||
readVersions: ({ req: { user } }) => Boolean(user),
|
||||
},
|
||||
fields: [
|
||||
{
|
||||
name: 'title',
|
||||
label: 'Title',
|
||||
type: 'text',
|
||||
required: true,
|
||||
unique: true,
|
||||
localized: true,
|
||||
},
|
||||
{
|
||||
name: 'description',
|
||||
label: 'Description',
|
||||
type: 'textarea',
|
||||
required: true,
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
export default VersionPosts;
|
||||
@@ -4,11 +4,13 @@ import DraftPosts from './collections/Drafts';
|
||||
import AutosaveGlobal from './globals/Autosave';
|
||||
import { devUser } from '../credentials';
|
||||
import DraftGlobal from './globals/Draft';
|
||||
import VersionPosts from './collections/Versions';
|
||||
|
||||
export default buildConfig({
|
||||
collections: [
|
||||
AutosavePosts,
|
||||
DraftPosts,
|
||||
VersionPosts,
|
||||
],
|
||||
globals: [
|
||||
AutosaveGlobal,
|
||||
|
||||
@@ -157,9 +157,14 @@ describe('Versions', () => {
|
||||
const versions = await payload.findVersions({
|
||||
collection,
|
||||
locale: 'all',
|
||||
where: {
|
||||
parent: {
|
||||
equals: collectionLocalPostID,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(versions.docs[0].version.title.en).toStrictEqual(englishTitle);
|
||||
expect(versions.docs[0].version.title.en).toStrictEqual(newEnglishTitle);
|
||||
expect(versions.docs[0].version.title.es).toStrictEqual(spanishTitle);
|
||||
});
|
||||
});
|
||||
@@ -184,7 +189,7 @@ describe('Versions', () => {
|
||||
|
||||
const restore = await payload.restoreVersion({
|
||||
collection,
|
||||
id: versions.docs[0].id,
|
||||
id: versions.docs[1].id,
|
||||
});
|
||||
|
||||
expect(restore.title).toBeDefined();
|
||||
@@ -195,7 +200,7 @@ describe('Versions', () => {
|
||||
draft: true,
|
||||
});
|
||||
|
||||
expect(restoredPost.title).toBe(restore.title);
|
||||
expect(restoredPost.title).toBe(versions.docs[1].version.title);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -226,13 +231,15 @@ describe('Versions', () => {
|
||||
draft: true,
|
||||
});
|
||||
|
||||
const spanishTitle = 'es title';
|
||||
|
||||
// second update to existing draft
|
||||
await payload.update({
|
||||
id: collectionLocalPostID,
|
||||
collection,
|
||||
locale: 'es',
|
||||
data: {
|
||||
title: updatedTitle,
|
||||
title: spanishTitle,
|
||||
},
|
||||
draft: true,
|
||||
});
|
||||
@@ -251,7 +258,62 @@ describe('Versions', () => {
|
||||
|
||||
expect(publishedPost.title).toBe(originalTitle);
|
||||
expect(draftPost.title.en).toBe(updatedTitle);
|
||||
expect(draftPost.title.es).toBe(updatedTitle);
|
||||
expect(draftPost.title.es).toBe(spanishTitle);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Draft Count', () => {
|
||||
it('creates proper number of drafts', async () => {
|
||||
const originalDraft = await payload.create({
|
||||
collection: 'draft-posts',
|
||||
draft: true,
|
||||
data: {
|
||||
title: 'A',
|
||||
description: 'A',
|
||||
_status: 'draft',
|
||||
},
|
||||
});
|
||||
|
||||
await payload.update({
|
||||
collection: 'draft-posts',
|
||||
id: originalDraft.id,
|
||||
draft: true,
|
||||
data: {
|
||||
title: 'B',
|
||||
description: 'B',
|
||||
_status: 'draft',
|
||||
},
|
||||
});
|
||||
|
||||
await payload.update({
|
||||
collection: 'draft-posts',
|
||||
id: originalDraft.id,
|
||||
draft: true,
|
||||
data: {
|
||||
title: 'C',
|
||||
description: 'C',
|
||||
_status: 'draft',
|
||||
},
|
||||
});
|
||||
|
||||
const mostRecentDraft = await payload.findByID({
|
||||
collection: 'draft-posts',
|
||||
id: originalDraft.id,
|
||||
draft: true,
|
||||
});
|
||||
|
||||
expect(mostRecentDraft.title).toStrictEqual('C');
|
||||
|
||||
const versions = await payload.findVersions({
|
||||
collection: 'draft-posts',
|
||||
where: {
|
||||
parent: {
|
||||
equals: originalDraft.id,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
expect(versions.docs).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -423,7 +485,7 @@ describe('Versions', () => {
|
||||
|
||||
expect(data.id).toBeDefined();
|
||||
expect(data.parent.id).toStrictEqual(collectionGraphQLPostID);
|
||||
expect(data.version.title).toStrictEqual(collectionGraphQLOriginalTitle);
|
||||
expect(data.version.title).toStrictEqual(updatedTitle);
|
||||
});
|
||||
|
||||
it('should allow read of versions by querying version content', async () => {
|
||||
|
||||
Reference in New Issue
Block a user