2021-07-07 10:43:13 +00:00
|
|
|
import { expect, it } from "@jest/globals";
|
2021-09-22 19:52:38 +00:00
|
|
|
|
2021-07-06 18:23:33 +00:00
|
|
|
import { whereAndSelect } from "@lib/prisma";
|
2021-07-06 18:20:25 +00:00
|
|
|
|
2021-07-06 18:23:33 +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 },
|
2021-08-19 12:27:01 +00:00
|
|
|
["example"]
|
2021-07-06 18:23:33 +00:00
|
|
|
);
|
2021-07-06 18:20:25 +00:00
|
|
|
});
|
|
|
|
|
2021-07-06 18:23:33 +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:23:33 +00:00
|
|
|
},
|
2021-07-06 18:20:25 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
{ uid: 1 },
|
2021-08-19 12:27:01 +00:00
|
|
|
["description", "attendees.email", "attendees.name"]
|
2021-07-06 18:23:33 +00:00
|
|
|
);
|
|
|
|
});
|
2021-07-06 18:20:25 +00:00
|
|
|
|
2021-07-06 18:23:33 +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: {
|
2021-07-06 18:23:33 +00:00
|
|
|
nested: true,
|
2021-08-19 12:27:01 +00:00
|
|
|
},
|
2021-07-06 18:20:25 +00:00
|
|
|
},
|
|
|
|
name: true,
|
|
|
|
},
|
|
|
|
},
|
2021-07-06 18:23:33 +00:00
|
|
|
},
|
2021-07-06 18:20:25 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
{ uid: 1 },
|
2021-08-19 12:27:01 +00:00
|
|
|
["description", "attendees.email.nested", "attendees.name"]
|
2021-07-06 18:23:33 +00:00
|
|
|
);
|
2021-07-06 18:20:25 +00:00
|
|
|
});
|
|
|
|
|
2021-07-06 18:23:33 +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-08-19 12:27:01 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-07-06 18:20:25 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
{ uid: 1 },
|
2021-08-19 12:27:01 +00:00
|
|
|
["description", "attendees.email", "attendees.name", "bookings.id", "bookings.name"]
|
2021-07-06 18:23:33 +00:00
|
|
|
);
|
2021-07-06 18:20:25 +00:00
|
|
|
});
|