Skip to content
Merged
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
73 changes: 71 additions & 2 deletions packages/runtime/test/client-api/mixin.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { describe, expect, it } from 'vitest';
import { createTestClient } from '../utils';

describe('Client API Mixins', () => {
const schema = `
it('includes fields and attributes from mixins', async () => {
const schema = `
type TimeStamped {
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
Expand All @@ -27,7 +28,6 @@ model Bar with CommonFields {
}
`;

it('includes fields and attributes from mixins', async () => {
const client = await createTestClient(schema, {
usePrismaPush: true,
});
Expand Down Expand Up @@ -77,4 +77,73 @@ model Bar with CommonFields {
}),
).rejects.toThrow('constraint failed');
});

it('supports multiple-level mixins', async () => {
const schema = `
type Base1 {
id String @id @default(cuid())
}

type Base2 with Base1 {
fieldA String
}

model A with Base2 {
field String
b B[]
}

model B {
id String @id @default(cuid())
a A @relation(fields: [aId], references: [id])
aId String
}
`;

const client = await createTestClient(schema);
await expect(
client.b.create({
data: {
a: {
create: {
field: 'test',
fieldA: 'testA',
},
},
},
include: { a: true },
}),
).resolves.toMatchObject({
a: {
id: expect.any(String),
field: 'test',
fieldA: 'testA',
},
});
});

it('works with multiple id fields from base', async () => {
const schema = `
type Base {
id1 String
id2 String
value String
@@id([id1, id2])
}

model Item with Base {
x String
}
`;

const client = await createTestClient(schema);
await expect(
client.item.create({
data: { id1: '1', id2: '2', value: 'test', x: 'x' },
}),
).resolves.toMatchObject({
id1: '1',
id2: '2',
});
});
});