Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 29 additions & 31 deletions packages/cli/test/ts-schema-gen.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,56 +370,54 @@ model User {

expect(schema.models).toMatchObject({
User: {
name: "User",
name: 'User',
fields: {
id: {
name: "id",
type: "String",
name: 'id',
type: 'String',
id: true,
attributes: [
{
name: "@id"
name: '@id',
},
{
name: "@default",
name: '@default',
args: [
{
name: "value",
name: 'value',
value: {
kind: "call",
function: "uuid",
kind: 'call',
function: 'uuid',
args: [
{
kind: "literal",
value: 7
}
]
}
}
]
}
kind: 'literal',
value: 7,
},
],
},
},
],
},
],
default: {
kind: "call",
function: "uuid",
kind: 'call',
function: 'uuid',
args: [
{
kind: "literal",
value: 7
}
]
}
}
kind: 'literal',
value: 7,
},
],
},
},
},
idFields: [
"id"
],
idFields: ['id'],
uniqueFields: {
id: {
type: "String"
}
}
}
type: 'String',
},
},
},
});
});
});
8 changes: 5 additions & 3 deletions packages/sdk/src/ts-schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -507,9 +507,11 @@ export class TsSchemaGenerator {
...(defaultValue.args.length > 0
? [
ts.factory.createArrayLiteralExpression(
defaultValue.args.map((arg) => this.createExpressionUtilsCall('literal', [
this.createLiteralNode(arg)
])),
defaultValue.args.map((arg) =>
this.createExpressionUtilsCall('literal', [
this.createLiteralNode(arg),
]),
),
),
]
: []),
Expand Down
5 changes: 4 additions & 1 deletion packages/testtools/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export type CreateTestClientOptions<Schema extends SchemaDef> = Omit<ClientOptio
usePrismaPush?: boolean;
extraSourceFiles?: Record<string, string>;
workDir?: string;
debug?: boolean;
};

export async function createTestClient<Schema extends SchemaDef>(
Expand Down Expand Up @@ -103,7 +104,9 @@ export async function createTestClient<Schema extends SchemaDef>(
}

invariant(workDir);
console.log(`Work directory: ${workDir}`);
if (options?.debug) {
console.log(`Work directory: ${workDir}`);
}

const { plugins, ...rest } = options ?? {};
const _options: ClientOptions<Schema> = {
Expand Down
12 changes: 7 additions & 5 deletions tests/regression/test/v2-migrated/issue-1058.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createTestClient } from '@zenstackhq/testtools';
import { it } from 'vitest';
import { describe, it } from 'vitest';

it('verifies issue 1058', async () => {
const schema = `
describe('Regression for issue #1058', () => {
it('verifies issue 1058', async () => {
const schema = `
model User {
id String @id @default(cuid())
name String
Expand Down Expand Up @@ -45,8 +46,9 @@ it('verifies issue 1058', async () => {
entity Entity @relation(fields: [entityId], references: [id], onUpdate: NoAction)
userId String
user User @relation(fields: [userId], references: [id], onDelete: Cascade, onUpdate: NoAction)
}
}
`;

await createTestClient(schema, { provider: 'postgresql' });
await createTestClient(schema, { provider: 'postgresql' });
});
});
194 changes: 98 additions & 96 deletions tests/regression/test/v2-migrated/issue-1080.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { createPolicyTestClient } from '@zenstackhq/testtools';
import { expect, it } from 'vitest';
import { describe, expect, it } from 'vitest';

it('verifies issue 1080', async () => {
const db = await createPolicyTestClient(
`
describe('Regression for issue #1080', () => {
it('verifies issue 1080', async () => {
const db = await createPolicyTestClient(
`
model Project {
id String @id @unique @default(uuid())
Fields Field[]
Expand All @@ -20,110 +21,111 @@ model Field {
@@allow('all', true)
}
`,
);
);

const project = await db.project.create({
include: { Fields: true },
data: {
Fields: {
create: [{ name: 'first' }, { name: 'second' }],
const project = await db.project.create({
include: { Fields: true },
data: {
Fields: {
create: [{ name: 'first' }, { name: 'second' }],
},
},
},
});
});

let updated = await db.project.update({
where: { id: project.id },
include: { Fields: true },
data: {
Fields: {
upsert: [
{
where: { id: project.Fields[0].id },
create: { name: 'first1' },
update: { name: 'first1' },
},
{
where: { id: project.Fields[1].id },
create: { name: 'second1' },
update: { name: 'second1' },
},
],
let updated = await db.project.update({
where: { id: project.id },
include: { Fields: true },
data: {
Fields: {
upsert: [
{
where: { id: project.Fields[0].id },
create: { name: 'first1' },
update: { name: 'first1' },
},
{
where: { id: project.Fields[1].id },
create: { name: 'second1' },
update: { name: 'second1' },
},
],
},
},
},
});
expect(updated).toMatchObject({
Fields: expect.arrayContaining([
expect.objectContaining({ name: 'first1' }),
expect.objectContaining({ name: 'second1' }),
]),
});
});
expect(updated).toMatchObject({
Fields: expect.arrayContaining([
expect.objectContaining({ name: 'first1' }),
expect.objectContaining({ name: 'second1' }),
]),
});

updated = await db.project.update({
where: { id: project.id },
include: { Fields: true },
data: {
Fields: {
upsert: {
where: { id: project.Fields[0].id },
create: { name: 'first2' },
update: { name: 'first2' },
updated = await db.project.update({
where: { id: project.id },
include: { Fields: true },
data: {
Fields: {
upsert: {
where: { id: project.Fields[0].id },
create: { name: 'first2' },
update: { name: 'first2' },
},
},
},
},
});
expect(updated).toMatchObject({
Fields: expect.arrayContaining([
expect.objectContaining({ name: 'first2' }),
expect.objectContaining({ name: 'second1' }),
]),
});
});
expect(updated).toMatchObject({
Fields: expect.arrayContaining([
expect.objectContaining({ name: 'first2' }),
expect.objectContaining({ name: 'second1' }),
]),
});

updated = await db.project.update({
where: { id: project.id },
include: { Fields: true },
data: {
Fields: {
upsert: {
where: { id: project.Fields[0].id },
create: { name: 'first3' },
update: { name: 'first3' },
},
update: {
where: { id: project.Fields[1].id },
data: { name: 'second3' },
updated = await db.project.update({
where: { id: project.id },
include: { Fields: true },
data: {
Fields: {
upsert: {
where: { id: project.Fields[0].id },
create: { name: 'first3' },
update: { name: 'first3' },
},
update: {
where: { id: project.Fields[1].id },
data: { name: 'second3' },
},
},
},
},
});
expect(updated).toMatchObject({
Fields: expect.arrayContaining([
expect.objectContaining({ name: 'first3' }),
expect.objectContaining({ name: 'second3' }),
]),
});
});
expect(updated).toMatchObject({
Fields: expect.arrayContaining([
expect.objectContaining({ name: 'first3' }),
expect.objectContaining({ name: 'second3' }),
]),
});

updated = await db.project.update({
where: { id: project.id },
include: { Fields: true },
data: {
Fields: {
upsert: {
where: { id: 'non-exist' },
create: { name: 'third1' },
update: { name: 'third1' },
},
update: {
where: { id: project.Fields[1].id },
data: { name: 'second4' },
updated = await db.project.update({
where: { id: project.id },
include: { Fields: true },
data: {
Fields: {
upsert: {
where: { id: 'non-exist' },
create: { name: 'third1' },
update: { name: 'third1' },
},
update: {
where: { id: project.Fields[1].id },
data: { name: 'second4' },
},
},
},
},
});
expect(updated).toMatchObject({
Fields: expect.arrayContaining([
expect.objectContaining({ name: 'first3' }),
expect.objectContaining({ name: 'second4' }),
expect.objectContaining({ name: 'third1' }),
]),
});
expect(updated).toMatchObject({
Fields: expect.arrayContaining([
expect.objectContaining({ name: 'first3' }),
expect.objectContaining({ name: 'second4' }),
expect.objectContaining({ name: 'third1' }),
]),
});
});
});
Loading
Loading