testing rollback

This commit is contained in:
Dan Ribbens
2023-08-22 11:07:52 -04:00
parent ddc692a966
commit 0296c51324
2 changed files with 961 additions and 1 deletions

View File

@@ -1,3 +1,4 @@
import { PayloadRequest } from 'payload/types';
import { CollectionConfig } from '../../src/collections/config/types';
import { buildConfigWithDefaults } from '../buildConfigWithDefaults';
@@ -14,6 +15,17 @@ export const Posts: CollectionConfig = {
type: 'number',
localized: true,
},
{
name: 'throw',
type: 'checkbox',
hooks: {
afterChange: [(value) => {
if (value) {
throw new Error('Throwing error for testing');
}
}],
},
},
{
name: 'myArray',
type: 'array',
@@ -182,8 +194,12 @@ const config = buildConfigWithDefaults({
// password: devUser.password,
// },
// });
const req = {} as PayloadRequest;
req.transactionID = await payload.db.beginTransaction();
const page1 = await payload.create({
req,
collection: 'pages',
data: {
slug: 'first',
@@ -191,12 +207,16 @@ const config = buildConfigWithDefaults({
});
const page2 = await payload.create({
req,
collection: 'pages',
data: {
slug: 'second',
},
});
await payload.db.commitTransaction(req.transactionID);
const findResult = await payload.find({
collection: 'pages',
where: { slug: { equals: 'second' } },
@@ -214,7 +234,10 @@ const config = buildConfigWithDefaults({
},
});
req.transactionID = await payload.db.beginTransaction();
const person2 = await payload.create({
req,
collection: 'people',
data: {
fullName: 'Elliot DeNolf',
@@ -222,8 +245,10 @@ const config = buildConfigWithDefaults({
});
const post = await payload.create({
req,
collection: 'posts',
data: {
throw: true,
title: 'hello',
number: 1337,
myGroup: {
@@ -303,7 +328,7 @@ const config = buildConfigWithDefaults({
],
},
});
await payload.db.commitTransaction(req.transactionID);
await payload.update({
collection: 'posts',
id: post.id,