Skip to content

Commit 86c3abe

Browse files
committed
chore: update for breaking changes
1 parent d8c1f86 commit 86c3abe

22 files changed

Lines changed: 211 additions & 99 deletions

test/e2e/deletedAt.test.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrismaClient, Profile, User } from "@prisma/client";
1+
import { Prisma, PrismaClient, Profile, User } from "@prisma/client";
22
import faker from "faker";
33

44
import { createSoftDeleteExtension } from "../../src";
@@ -12,18 +12,17 @@ describe("deletedAt", () => {
1212
beforeAll(async () => {
1313
testClient = new PrismaClient();
1414
testClient = testClient.$extends(
15-
createSoftDeleteExtension(
16-
{
17-
models: {
18-
User: {
19-
field: "deletedAt",
20-
createValue: (deleted) => {
21-
return deleted ? new Date() : null;
22-
},
15+
createSoftDeleteExtension({
16+
models: {
17+
User: {
18+
field: "deletedAt",
19+
createValue: (deleted) => {
20+
return deleted ? new Date() : null;
2321
},
2422
},
2523
},
26-
)
24+
dmmf: Prisma.dmmf,
25+
})
2726
);
2827

2928
profile = await client.profile.create({

test/e2e/fluent.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrismaClient, Profile, User } from "@prisma/client";
1+
import { Prisma, PrismaClient, Profile, User } from "@prisma/client";
22
import faker from "faker";
33

44
import { createSoftDeleteExtension } from "../../src";
@@ -12,7 +12,10 @@ describe("fluent", () => {
1212
beforeAll(async () => {
1313
testClient = new PrismaClient();
1414
testClient = testClient.$extends(
15-
createSoftDeleteExtension({ models: { Comment: true, Profile: true } })
15+
createSoftDeleteExtension({
16+
models: { Comment: true, Profile: true },
17+
dmmf: Prisma.dmmf,
18+
})
1619
);
1720

1821
profile = await client.profile.create({

test/e2e/nestedReads.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrismaClient, User } from "@prisma/client";
1+
import { Prisma, PrismaClient, User } from "@prisma/client";
22
import faker from "faker";
33

44
import { createSoftDeleteExtension } from "../../src";
@@ -12,7 +12,7 @@ describe("nested reads", () => {
1212
testClient = new PrismaClient();
1313
testClient = testClient.$extends(
1414
createSoftDeleteExtension(
15-
{ models: { Comment: true, Profile: true } },
15+
{ models: { Comment: true, Profile: true }, dmmf: Prisma.dmmf },
1616
// @ts-expect-error - we don't know what the client is
1717
{ client: testClient }
1818
)

test/e2e/queries.test.ts

Lines changed: 33 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ describe("queries", () => {
1515
beforeAll(async () => {
1616
testClient = new PrismaClient();
1717
testClient = testClient.$extends(
18-
createSoftDeleteExtension({ models: { User: true } })
18+
createSoftDeleteExtension({ models: { User: true }, dmmf: Prisma.dmmf })
1919
);
2020

2121
profile = await client.profile.create({
@@ -362,41 +362,42 @@ describe("queries", () => {
362362
expect(notFoundUser).toBeNull();
363363
});
364364

365-
it.failing("does not break interactive transaction", async() => {
365+
it.failing("does not break interactive transaction", async () => {
366366
// eslint-disable-next-line prefer-const
367367
let localClient = testClient;
368368

369369
// uncomment to make this test succeed
370370
// localClient = new PrismaClient();
371371

372-
await localClient.$transaction(async (transactionClient: any) => {
373-
374-
// read within transaction
375-
const userRead1 = await transactionClient.user.findUnique({
376-
where: { id: firstUser.id },
377-
});
378-
expect(userRead1.name).toBe('Jack');
372+
await localClient.$transaction(
373+
async (transactionClient: any) => {
374+
// read within transaction
375+
const userRead1 = await transactionClient.user.findUnique({
376+
where: { id: firstUser.id },
377+
});
378+
expect(userRead1.name).toBe("Jack");
379379

380-
// modify outside of transaction
381-
await localClient.user.update({
382-
where: { id: firstUser.id },
383-
data: {
384-
name: 'Jill',
385-
},
386-
});
380+
// modify outside of transaction
381+
await localClient.user.update({
382+
where: { id: firstUser.id },
383+
data: {
384+
name: "Jill",
385+
},
386+
});
387387

388-
// read again within transaction
389-
const userRead2 = await transactionClient.user.findUnique({
390-
where: { id: firstUser.id },
391-
});
388+
// read again within transaction
389+
const userRead2 = await transactionClient.user.findUnique({
390+
where: { id: firstUser.id },
391+
});
392392

393-
// read is repeatable
394-
expect(userRead2.name).toBe('Jack');
395-
396-
}, { isolationLevel: Prisma.TransactionIsolationLevel.RepeatableRead });
393+
// read is repeatable
394+
expect(userRead2.name).toBe("Jack");
395+
},
396+
{ isolationLevel: Prisma.TransactionIsolationLevel.RepeatableRead }
397+
);
397398
});
398399

399-
it.failing("does not break sequential transaction", async() => {
400+
it.failing("does not break sequential transaction", async () => {
400401
// eslint-disable-next-line prefer-const
401402
let localClient: PrismaClient = testClient;
402403

@@ -406,45 +407,42 @@ describe("queries", () => {
406407
const [[userRead1, _, userRead2]] = await Promise.all([
407408
localClient.$transaction(
408409
[
409-
410410
// read within transaction (userRead1)
411411
localClient.user.findUniqueOrThrow({
412412
where: { id: firstUser.id },
413413
}),
414-
414+
415415
// sleep for 2 seconds to allow concurrent modification
416416
localClient.$executeRaw`SELECT pg_sleep(1)`,
417417

418-
419418
// read again within transaction (userRead2)
420419
localClient.user.findUniqueOrThrow({
421420
where: { id: firstUser.id },
422-
})
421+
}),
423422
],
424423
{
425424
isolationLevel: Prisma.TransactionIsolationLevel.RepeatableRead,
426425
}
427426
),
428427
localClient.$transaction([
429-
430428
// sleep for 1 second to allow first read to happen in other transaction
431429
localClient.$executeRaw`SELECT pg_sleep(1)`,
432430

433431
// modify
434432
localClient.user.update({
435433
where: { id: firstUser.id },
436434
data: {
437-
name: 'Jill',
435+
name: "Jill",
438436
},
439-
})
437+
}),
440438
]),
441439
]);
442440

443441
// read is repeatable
444-
expect(userRead1.name).toBe('Jack');
445-
expect(userRead2.name).toBe('Jack');
442+
expect(userRead1.name).toBe("Jack");
443+
expect(userRead2.name).toBe("Jack");
446444
});
447-
445+
448446
it("throws a useful error when invalid where is passed", async () => {
449447
// throws useful error when no where is passed
450448
await expect(() => testClient.user.findUnique()).rejects.toThrowError(

test/e2e/where.test.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { PrismaClient, Profile, User } from "@prisma/client";
1+
import { Prisma, PrismaClient, Profile, User } from "@prisma/client";
22
import faker from "faker";
33

44
import { createSoftDeleteExtension } from "../../src";
@@ -12,7 +12,10 @@ describe("where", () => {
1212
beforeAll(async () => {
1313
testClient = new PrismaClient();
1414
testClient = testClient.$extends(
15-
createSoftDeleteExtension({ models: { Comment: true, Profile: true } })
15+
createSoftDeleteExtension({
16+
models: { Comment: true, Profile: true },
17+
dmmf: Prisma.dmmf,
18+
})
1619
);
1720

1821
profile = await client.profile.create({

test/unit/aggregate.test.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { createSoftDeleteExtension } from "../../src";
22
import { MockClient } from "./utils/mockClient";
3+
import { Prisma } from "@prisma/client";
34

45
describe("aggregate", () => {
56
it("does not change aggregate action if model is not in the list", async () => {
67
const client = new MockClient();
78
const extendedClient = client.$extends(
8-
createSoftDeleteExtension({ models: {} })
9+
createSoftDeleteExtension({ models: {}, dmmf: Prisma.dmmf })
910
);
1011

1112
await extendedClient.user.aggregate({
@@ -27,13 +28,16 @@ describe("aggregate", () => {
2728
models: {
2829
User: true,
2930
},
31+
dmmf: Prisma.dmmf,
3032
})
3133
);
3234

3335
await extendedClient.user.aggregate({});
3436

3537
// args have been modified
36-
expect(extendedClient.user.aggregate.query).toHaveBeenCalledWith({ where: { deleted: false } });
38+
expect(extendedClient.user.aggregate.query).toHaveBeenCalledWith({
39+
where: { deleted: false },
40+
});
3741
});
3842

3943
it("excludes deleted record from aggregate with where", async () => {
@@ -43,6 +47,7 @@ describe("aggregate", () => {
4347
models: {
4448
User: true,
4549
},
50+
dmmf: Prisma.dmmf,
4651
})
4752
);
4853

test/unit/config.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import faker from "faker";
22

33
import { createSoftDeleteExtension } from "../../src";
44
import { MockClient } from "./utils/mockClient";
5+
import { Prisma } from "@prisma/client";
56

67
describe("config", () => {
78
it('does not soft delete models where config is passed as "false"', async () => {
@@ -11,6 +12,7 @@ describe("config", () => {
1112
models: {
1213
User: false,
1314
},
15+
dmmf: Prisma.dmmf,
1416
})
1517
);
1618

@@ -54,6 +56,7 @@ describe("config", () => {
5456
field: "deletedAt",
5557
createValue: () => deletedAt,
5658
},
59+
dmmf: Prisma.dmmf,
5760
})
5861
);
5962

@@ -101,6 +104,7 @@ describe("config", () => {
101104
defaultConfig: {
102105
createValue: () => new Date(),
103106
},
107+
dmmf: Prisma.dmmf,
104108
});
105109
}).toThrowError(
106110
"prisma-extension-soft-delete: defaultConfig.field is required"
@@ -117,6 +121,7 @@ describe("config", () => {
117121
defaultConfig: {
118122
field: "deletedAt",
119123
},
124+
dmmf: Prisma.dmmf,
120125
});
121126
}).toThrowError(
122127
"prisma-extension-soft-delete: defaultConfig.createValue is required"
@@ -135,6 +140,7 @@ describe("config", () => {
135140
},
136141
Comment: true,
137142
},
143+
dmmf: Prisma.dmmf,
138144
})
139145
);
140146

@@ -186,6 +192,7 @@ describe("config", () => {
186192
return null;
187193
},
188194
},
195+
dmmf: Prisma.dmmf,
189196
})
190197
);
191198

test/unit/count.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import { createSoftDeleteExtension } from "../../src";
22
import { MockClient } from "./utils/mockClient";
3+
import { Prisma } from "@prisma/client";
34

45
describe("count", () => {
56
it("does not change count action if model is not in the list", async () => {
67
const client = new MockClient();
78
const extendedClient = client.$extends(
8-
createSoftDeleteExtension({ models: {} })
9+
createSoftDeleteExtension({ models: {}, dmmf: Prisma.dmmf })
910
);
1011

1112
await extendedClient.user.count({});
@@ -19,20 +20,24 @@ describe("count", () => {
1920
const extendedClient = client.$extends(
2021
createSoftDeleteExtension({
2122
models: { User: true },
23+
dmmf: Prisma.dmmf,
2224
})
2325
);
2426

2527
await extendedClient.user.count(undefined);
2628

2729
// params have been modified
28-
expect(extendedClient.user.count.query).toHaveBeenCalledWith({ where: { deleted: false } });
30+
expect(extendedClient.user.count.query).toHaveBeenCalledWith({
31+
where: { deleted: false },
32+
});
2933
});
3034

3135
it("excludes deleted records from count with empty args", async () => {
3236
const client = new MockClient();
3337
const extendedClient = client.$extends(
3438
createSoftDeleteExtension({
3539
models: { User: true },
40+
dmmf: Prisma.dmmf,
3641
})
3742
);
3843

@@ -49,6 +54,7 @@ describe("count", () => {
4954
const extendedClient = client.$extends(
5055
createSoftDeleteExtension({
5156
models: { User: true },
57+
dmmf: Prisma.dmmf,
5258
})
5359
);
5460

0 commit comments

Comments
 (0)