-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for groupBy queries (#7)
Update version of prisma-nested-middleware to v3.0.3 so 'groupBy' is included as an option for NestedAction.
- Loading branch information
Showing
6 changed files
with
103 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import { createSoftDeleteMiddleware } from "../../src"; | ||
import { createParams } from "./utils/createParams"; | ||
|
||
describe("groupBy", () => { | ||
|
||
//group by must always have by and order by, else we get an error, | ||
it("does not change groupBy action if model is not in the list", async () => { | ||
const middleware = createSoftDeleteMiddleware({ models: {} }); | ||
|
||
const params = createParams("User", "groupBy", { where: { id: 1 }, by: ['id'], orderBy: {}, }); | ||
const next = jest.fn(() => Promise.resolve({})); | ||
await middleware(params, next); | ||
// params have not been modified | ||
expect(next).toHaveBeenCalledWith(params); | ||
}); | ||
|
||
it("does not modify groupBy results", async () => { | ||
const middleware = createSoftDeleteMiddleware({ models: { User: true } }); | ||
const params = createParams("User", "groupBy", { where: { id: 1 }, by: ['id'], orderBy: {}, }); | ||
const next = jest.fn(() => Promise.resolve([{ id: 1, deleted: true }])); | ||
expect(await middleware(params, next)).toEqual([{ id: 1, deleted: true }]); | ||
}); | ||
|
||
it("excludes deleted records from groupBy", async () => { | ||
const middleware = createSoftDeleteMiddleware({ | ||
models: { User: true }, | ||
}); | ||
|
||
const params = createParams("User", "groupBy", { where: { id: 1 },by: ['id'], orderBy: {} }); | ||
const next = jest.fn(() => Promise.resolve({})); | ||
|
||
await middleware(params, next); | ||
|
||
// params have been modified | ||
expect(next).toHaveBeenCalledWith({ | ||
...params, | ||
action: "groupBy", | ||
args: { | ||
by: ['id'], | ||
orderBy: { }, | ||
where: { | ||
id: 1, | ||
deleted: false, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
|
||
it("allows explicitly querying for deleted records using groupBy", async () => { | ||
const middleware = createSoftDeleteMiddleware({ | ||
models: { User: true }, | ||
}); | ||
|
||
const params = createParams("User", "groupBy", { | ||
where: { id: 1, deleted: true }, by: ['id'], orderBy: {} | ||
}); | ||
const next = jest.fn(() => Promise.resolve({})); | ||
|
||
await middleware(params, next); | ||
|
||
// params have not been modified | ||
expect(next).toHaveBeenCalledWith(params); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters