mirror of
https://github.com/better-auth/better-auth.git
synced 2026-07-29 11:50:12 -05:00
test: skip if adapter doesn't support transaction (#4753)
This commit is contained in:
@@ -20,7 +20,7 @@ exports[`init > should match config 1`] = `
|
||||
"supportsDates": false,
|
||||
"supportsJSON": false,
|
||||
"supportsNumericIds": true,
|
||||
"transaction": [Function],
|
||||
"transaction": false,
|
||||
"usePlural": undefined,
|
||||
},
|
||||
"debugLogs": false,
|
||||
|
||||
@@ -874,12 +874,26 @@ async function adapterTest(
|
||||
|
||||
test.skipIf(disabledTests?.SHOULD_ROLLBACK_FAILING_TRANSACTION)(
|
||||
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.SHOULD_ROLLBACK_FAILING_TRANSACTION}`,
|
||||
async ({ onTestFailed }) => {
|
||||
async ({ onTestFailed, skip }) => {
|
||||
await resetDebugLogs();
|
||||
onTestFailed(async () => {
|
||||
await printDebugLogs();
|
||||
});
|
||||
const customAdapter = await adapter();
|
||||
|
||||
// Check if adapter actually supports transactions
|
||||
const enableTransaction =
|
||||
customAdapter?.options?.adapterConfig.transaction;
|
||||
if (!enableTransaction) {
|
||||
skip(
|
||||
`Skipping test: ${
|
||||
customAdapter?.options?.adapterConfig.adapterName || "Adapter"
|
||||
}
|
||||
does not support transactions`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const user5 = {
|
||||
name: "user5",
|
||||
email: getUniqueEmail("user5@email.com"),
|
||||
@@ -924,12 +938,25 @@ async function adapterTest(
|
||||
|
||||
test.skipIf(disabledTests?.SHOULD_RETURN_TRANSACTION_RESULT)(
|
||||
`${testPrefix ? `${testPrefix} - ` : ""}${adapterTests.SHOULD_RETURN_TRANSACTION_RESULT}`,
|
||||
async ({ onTestFailed }) => {
|
||||
async ({ onTestFailed, skip }) => {
|
||||
await resetDebugLogs();
|
||||
onTestFailed(async () => {
|
||||
await printDebugLogs();
|
||||
});
|
||||
const customAdapter = await adapter();
|
||||
|
||||
const enableTransaction =
|
||||
customAdapter?.options?.adapterConfig.transaction;
|
||||
if (!enableTransaction) {
|
||||
skip(
|
||||
`Skipping test: ${
|
||||
customAdapter?.options?.adapterConfig.adapterName || "Adapter"
|
||||
}
|
||||
does not support transactions`,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
const result = await customAdapter.transaction(async (tx) => {
|
||||
const createdUser = await tx.create<User>({
|
||||
model: "user",
|
||||
|
||||
@@ -77,8 +77,11 @@ describe("sign-up with custom fields", async (it) => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should rollback when session creation fails", async () => {
|
||||
it("should rollback when session creation fails", async ({ skip }) => {
|
||||
const ctx = await auth.$context;
|
||||
if (!ctx.adapter.options?.adapterConfig.transaction) {
|
||||
skip();
|
||||
}
|
||||
const originalCreateSession = ctx.internalAdapter.createSession;
|
||||
ctx.internalAdapter.createSession = vi
|
||||
.fn()
|
||||
|
||||
@@ -92,7 +92,9 @@ describe("organization creation in database hooks", async () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should handle errors gracefully when organization creation fails in hook", async () => {
|
||||
it("should handle errors gracefully when organization creation fails in hook", async ({
|
||||
skip,
|
||||
}) => {
|
||||
let firstUserCreated = false;
|
||||
let errorOnSecondUser: any = null;
|
||||
|
||||
@@ -123,6 +125,12 @@ describe("organization creation in database hooks", async () => {
|
||||
},
|
||||
});
|
||||
|
||||
if (!db.options?.adapterConfig.transaction) {
|
||||
skip(
|
||||
"Skipping since transactions are enabled and will rollback automatically",
|
||||
);
|
||||
}
|
||||
|
||||
// First user should succeed
|
||||
const result1 = await client.signUp.email({
|
||||
email: "user1-hook@example.com",
|
||||
|
||||
Reference in New Issue
Block a user