mirror of
https://github.com/zenstackhq/zenstack
synced 2026-05-24 10:08:55 +00:00
* refactor: move e2e orm tests to e2e project, fix bundle issues * add missing package * include all tests * more fixes * update lockfile * extract policy plugin to its own package * fix lint * addressing review comments
71 lines
1.9 KiB
TypeScript
71 lines
1.9 KiB
TypeScript
import { createTestProject, generateTsSchemaInPlace } from '@zenstackhq/testtools';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
import { describe, expect, it } from 'vitest';
|
|
import { createTestClient } from '@zenstackhq/testtools';
|
|
|
|
describe('Import tests', () => {
|
|
it('works with imported models', async () => {
|
|
const workDir = createTestProject();
|
|
|
|
fs.writeFileSync(
|
|
path.join(workDir, 'user.zmodel'),
|
|
`
|
|
import './post'
|
|
model User {
|
|
id Int @id @default(autoincrement())
|
|
email String
|
|
posts Post[]
|
|
}
|
|
`,
|
|
);
|
|
fs.writeFileSync(
|
|
path.join(workDir, 'post.zmodel'),
|
|
`
|
|
import './user'
|
|
|
|
model Post {
|
|
id Int @id @default(autoincrement())
|
|
title String
|
|
author User @relation(fields: [authorId], references: [id])
|
|
authorId Int
|
|
}
|
|
`,
|
|
);
|
|
fs.writeFileSync(
|
|
path.join(workDir, 'main.zmodel'),
|
|
`
|
|
import './user'
|
|
import './post'
|
|
|
|
datasource db {
|
|
provider = "sqlite"
|
|
url = "file:./dev.db"
|
|
}
|
|
`,
|
|
);
|
|
|
|
const { schema } = await generateTsSchemaInPlace(path.join(workDir, 'main.zmodel'));
|
|
const client: any = await createTestClient(schema);
|
|
|
|
await expect(
|
|
client.user.create({
|
|
data: {
|
|
id: 1,
|
|
email: 'u1@test.com',
|
|
posts: {
|
|
create: { title: 'Post1' },
|
|
},
|
|
},
|
|
include: { posts: true },
|
|
}),
|
|
).resolves.toMatchObject({
|
|
email: 'u1@test.com',
|
|
posts: [
|
|
expect.objectContaining({
|
|
title: 'Post1',
|
|
}),
|
|
],
|
|
});
|
|
});
|
|
});
|