Skip to content

Commit ca2a428

Browse files
authored
test: more cases for mixins (#108)
1 parent 55d4e77 commit ca2a428

File tree

1 file changed

+71
-2
lines changed

1 file changed

+71
-2
lines changed

packages/runtime/test/client-api/mixin.test.ts

Lines changed: 71 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { describe, expect, it } from 'vitest';
22
import { createTestClient } from '../utils';
33

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

30-
it('includes fields and attributes from mixins', async () => {
3131
const client = await createTestClient(schema, {
3232
usePrismaPush: true,
3333
});
@@ -77,4 +77,73 @@ model Bar with CommonFields {
7777
}),
7878
).rejects.toThrow('constraint failed');
7979
});
80+
81+
it('supports multiple-level mixins', async () => {
82+
const schema = `
83+
type Base1 {
84+
id String @id @default(cuid())
85+
}
86+
87+
type Base2 with Base1 {
88+
fieldA String
89+
}
90+
91+
model A with Base2 {
92+
field String
93+
b B[]
94+
}
95+
96+
model B {
97+
id String @id @default(cuid())
98+
a A @relation(fields: [aId], references: [id])
99+
aId String
100+
}
101+
`;
102+
103+
const client = await createTestClient(schema);
104+
await expect(
105+
client.b.create({
106+
data: {
107+
a: {
108+
create: {
109+
field: 'test',
110+
fieldA: 'testA',
111+
},
112+
},
113+
},
114+
include: { a: true },
115+
}),
116+
).resolves.toMatchObject({
117+
a: {
118+
id: expect.any(String),
119+
field: 'test',
120+
fieldA: 'testA',
121+
},
122+
});
123+
});
124+
125+
it('works with multiple id fields from base', async () => {
126+
const schema = `
127+
type Base {
128+
id1 String
129+
id2 String
130+
value String
131+
@@id([id1, id2])
132+
}
133+
134+
model Item with Base {
135+
x String
136+
}
137+
`;
138+
139+
const client = await createTestClient(schema);
140+
await expect(
141+
client.item.create({
142+
data: { id1: '1', id2: '2', value: 'test', x: 'x' },
143+
}),
144+
).resolves.toMatchObject({
145+
id1: '1',
146+
id2: '2',
147+
});
148+
});
80149
});

0 commit comments

Comments
 (0)