mirror of
https://github.com/zenstackhq/zenstack
synced 2026-05-24 10:08:55 +00:00
* WIP(orm): mysql support * WIP: more progress with fixing tests * WIP: get all client api tests pass * WIP: get all tests pass * fix executor * add MySQL to CI matrix * fix sqlite test runs * fix test * fix delete readback check * set mysql container max connections * fix tests * fix test * refactor: extract duplicated mysql/pg code into base class * address PR comments * refactor: remove order by duplicated code * refactor: optimize stripTableReference * addressing PR comments * fix tests
48 lines
1.6 KiB
TypeScript
48 lines
1.6 KiB
TypeScript
import { createId } from '@paralleldrive/cuid2';
|
|
import { createTestClient } from '@zenstackhq/testtools';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { getSchema } from '../schemas/basic';
|
|
|
|
describe('Client API tests', () => {
|
|
const schema = getSchema('sqlite');
|
|
|
|
it('works with queries', async () => {
|
|
const client = await createTestClient(schema);
|
|
|
|
const kysely = client.$qb;
|
|
|
|
const uid = createId();
|
|
await kysely
|
|
.insertInto('User')
|
|
.values({
|
|
id: uid,
|
|
email: 'a@b.com',
|
|
updatedAt: new Date().toISOString().replace('Z', '+00:00'),
|
|
})
|
|
.execute();
|
|
|
|
const u1 = await kysely.selectFrom('User').select('email').where('id', '=', uid).executeTakeFirst();
|
|
expect(u1).toBeTruthy();
|
|
|
|
await kysely
|
|
.insertInto('Post')
|
|
.values({
|
|
id: createId(),
|
|
authorId: uid,
|
|
title: 'Post1',
|
|
content: 'My post',
|
|
updatedAt: new Date().toISOString().replace('Z', '+00:00'),
|
|
})
|
|
.execute();
|
|
|
|
const u2 = await kysely
|
|
.selectFrom('User')
|
|
.innerJoin('Post', 'User.id', 'Post.authorId')
|
|
.select(['User.email', 'Post.title'])
|
|
.executeTakeFirstOrThrow();
|
|
expect(u2).toMatchObject({ title: 'Post1', email: 'a@b.com' });
|
|
|
|
const u3 = await kysely.selectFrom('User').selectAll().executeTakeFirstOrThrow();
|
|
expect(u3).toMatchObject({ email: 'a@b.com', role: 'USER' });
|
|
});
|
|
});
|