mirror of
https://github.com/zenstackhq/zenstack
synced 2026-05-24 10:08:55 +00:00
58 lines
1.5 KiB
TypeScript
58 lines
1.5 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
import type { ClientContract } from '@zenstackhq/orm';
|
|
import { schema } from '../schemas/basic';
|
|
import { createTestClient } from '@zenstackhq/testtools';
|
|
|
|
describe('Client delete tests', () => {
|
|
let client: ClientContract<typeof schema>;
|
|
|
|
beforeEach(async () => {
|
|
client = await createTestClient(schema);
|
|
});
|
|
|
|
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' },
|
|
}),
|
|
).toBeRejectedNotFound();
|
|
|
|
// 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' }),
|
|
});
|
|
});
|
|
});
|