cal.pub0.org/test/lib/prisma.test.ts

93 lines
1.9 KiB
TypeScript
Raw Normal View History

2021-07-07 10:43:13 +00:00
import { expect, it } from "@jest/globals";
import { whereAndSelect } from "@lib/prisma";
2021-07-06 18:20:25 +00:00
it("can decorate using whereAndSelect", async () => {
whereAndSelect(
(queryObj) => {
expect(queryObj).toStrictEqual({ where: { id: 1 }, select: { example: true } });
2021-07-06 18:20:25 +00:00
},
{ id: 1 },
["example"]
);
2021-07-06 18:20:25 +00:00
});
it("can do nested selects using . seperator", async () => {
whereAndSelect(
(queryObj) => {
2021-07-06 18:20:25 +00:00
expect(queryObj).toStrictEqual({
where: {
uid: 1,
},
select: {
description: true,
attendees: {
select: {
email: true,
name: true,
},
},
},
2021-07-06 18:20:25 +00:00
});
},
{ uid: 1 },
["description", "attendees.email", "attendees.name"]
);
});
2021-07-06 18:20:25 +00:00
it("can handle nesting deeply", async () => {
whereAndSelect(
(queryObj) => {
2021-07-06 18:20:25 +00:00
expect(queryObj).toStrictEqual({
where: {
uid: 1,
},
select: {
description: true,
attendees: {
select: {
email: {
select: {
nested: true,
},
2021-07-06 18:20:25 +00:00
},
name: true,
},
},
},
2021-07-06 18:20:25 +00:00
});
},
{ uid: 1 },
["description", "attendees.email.nested", "attendees.name"]
);
2021-07-06 18:20:25 +00:00
});
it("can handle nesting multiple", async () => {
whereAndSelect(
(queryObj) => {
2021-07-06 18:20:25 +00:00
expect(queryObj).toStrictEqual({
where: {
uid: 1,
},
select: {
description: true,
attendees: {
select: {
email: true,
name: true,
},
},
bookings: {
select: {
id: true,
name: true,
},
},
},
2021-07-06 18:20:25 +00:00
});
},
{ uid: 1 },
["description", "attendees.email", "attendees.name", "bookings.id", "bookings.name"]
);
2021-07-06 18:20:25 +00:00
});