zenstack/packages/runtime/test/client-api/delete.test.ts
2025-04-01 13:57:43 -07:00

64 lines
1.8 KiB
TypeScript

import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import type { Client } from '../../src/client';
import { schema } from '../test-schema';
import { createClientSpecs } from './client-specs';
const PG_DB_NAME = 'client-api-delete-tests';
describe.each(createClientSpecs(PG_DB_NAME))(
'Client delete tests',
({ createClient }) => {
let client: Client<typeof schema>;
beforeEach(async () => {
client = await createClient();
await client.$pushSchema();
});
afterEach(async () => {
await client?.$disconnect();
});
it('works with toplevel delete', async () => {
let user = await client.user.create({
data: {
id: '1',
email: 'u1@test.com',
},
});
// not found
await expect(
client.user.delete({
where: { id: '2' },
})
).toRejectNotFound();
// found
await expect(
client.user.delete({
where: { id: user.id },
})
).resolves.toMatchObject(user);
// include relations
user = await client.user.create({
data: {
id: '1',
email: 'u1@test.com',
profile: {
create: { bio: 'Bio' },
},
},
});
await expect(
client.user.delete({
where: { id: user.id },
include: { profile: true },
})
).resolves.toMatchObject({
profile: expect.objectContaining({ bio: 'Bio' }),
});
});
}
);