mirror of
https://github.com/zenstackhq/zenstack
synced 2026-05-24 10:08:55 +00:00
79 lines
2.4 KiB
TypeScript
79 lines
2.4 KiB
TypeScript
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
|
|
import type { ClientContract } from '../../src/client';
|
|
import { schema } from '../schemas/basic';
|
|
import { createClientSpecs } from './client-specs';
|
|
|
|
const PG_DB_NAME = 'client-api-delete-many-tests';
|
|
|
|
describe.each(createClientSpecs(PG_DB_NAME))('Client deleteMany tests', ({ createClient }) => {
|
|
let client: ClientContract<typeof schema>;
|
|
|
|
beforeEach(async () => {
|
|
client = await createClient();
|
|
});
|
|
|
|
afterEach(async () => {
|
|
await client?.$disconnect();
|
|
});
|
|
|
|
it('works with toplevel deleteMany', async () => {
|
|
await client.user.create({
|
|
data: {
|
|
id: '1',
|
|
email: 'u1@test.com',
|
|
},
|
|
});
|
|
await client.user.create({
|
|
data: {
|
|
id: '2',
|
|
email: 'u2@test.com',
|
|
},
|
|
});
|
|
|
|
// delete not found
|
|
await expect(
|
|
client.user.deleteMany({
|
|
where: { email: 'u3@test.com' },
|
|
}),
|
|
).resolves.toMatchObject({ count: 0 });
|
|
await expect(client.user.findMany()).toResolveWithLength(2);
|
|
|
|
// delete one
|
|
await expect(
|
|
client.user.deleteMany({
|
|
where: { email: 'u1@test.com' },
|
|
}),
|
|
).resolves.toMatchObject({ count: 1 });
|
|
await expect(client.user.findMany()).toResolveWithLength(1);
|
|
|
|
// delete all
|
|
await expect(client.user.deleteMany()).resolves.toMatchObject({
|
|
count: 1,
|
|
});
|
|
await expect(client.user.findMany()).toResolveWithLength(0);
|
|
});
|
|
|
|
it('works with deleteMany with limit', async () => {
|
|
await client.user.create({
|
|
data: { id: '1', email: 'u1@test.com' },
|
|
});
|
|
await client.user.create({
|
|
data: { id: '2', email: 'u2@test.com' },
|
|
});
|
|
|
|
await expect(
|
|
client.user.deleteMany({
|
|
where: { email: 'u3@test.com' },
|
|
limit: 1,
|
|
}),
|
|
).resolves.toMatchObject({ count: 0 });
|
|
await expect(client.user.findMany()).toResolveWithLength(2);
|
|
|
|
await expect(
|
|
client.user.deleteMany({
|
|
limit: 1,
|
|
}),
|
|
).resolves.toMatchObject({ count: 1 });
|
|
await expect(client.user.findMany()).toResolveWithLength(1);
|
|
});
|
|
});
|