zenstack/packages/plugins/react/tests/react-hooks.test.ts
Yiming e93ca5bf10
fix: zod typing for DateTime field, improve overall code generation (#363)
Co-authored-by: Abdullah Hassan <iAbdullahHassan@gmail.com>
2023-04-22 09:19:26 -07:00

77 lines
1.5 KiB
TypeScript

/// <reference types="@types/jest" />
import { loadSchema } from '@zenstackhq/testtools';
describe('React Hooks Plugin Tests', () => {
let origDir: string;
beforeAll(() => {
origDir = process.cwd();
});
afterEach(() => {
process.chdir(origDir);
});
const sharedModel = `
model User {
id String @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
email String @unique
role String @default('USER')
posts Post[]
}
model Post {
id String @id
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
title String
author User? @relation(fields: [authorId], references: [id])
authorId String?
published Boolean @default(false)
viewCount Int @default(0)
}
model Foo {
id String @id
@@ignore
}
`;
it('swr generator', async () => {
await loadSchema(
`
plugin react {
provider = '${process.cwd()}/dist'
output = '$projectRoot/hooks'
}
${sharedModel}
`,
true,
false,
[`${origDir}/dist`, 'react', '@types/react', 'swr'],
true
);
});
it('react-query generator', async () => {
await loadSchema(
`
plugin react {
provider = '${process.cwd()}/dist'
output = '$projectRoot/hooks'
fetcher = 'react-query'
}
${sharedModel}
`,
true,
false,
[`${origDir}/dist`, 'react', '@types/react', '@tanstack/react-query'],
true
);
});
});