Skip to content

Commit

Permalink
fix(user): return paginated user list on users endpoint (#283)
Browse files Browse the repository at this point in the history
  • Loading branch information
dipendraupreti committed Mar 29, 2023
1 parent 4ce0514 commit 00954dc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
17 changes: 12 additions & 5 deletions packages/user/src/__test__/resolver.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ import type { MercuriusContext } from "mercurius";
import type { Mock } from "vitest";

const findById = vi.fn();
const list = vi.fn();
const paginatedList = vi.fn();

vi.mock("../model/user-profiles/service", () => ({
default: class UserProfileService {
findById = findById;
list = list;
paginatedList = paginatedList;
},
}));

Expand All @@ -38,7 +38,7 @@ describe("user service resolver", () => {
expect(findById).toBeCalledWith(id);
});

it("Should call the UserProfileService list method with proper limit and offset values", async () => {
it("Should call the UserProfileService paginatedList method with proper limit and offset values", async () => {
const count = 190;

const dataset = await getLimitAndOffsetDataset(count, createConfig());
Expand All @@ -48,8 +48,15 @@ describe("user service resolver", () => {

if (limit && offset) {
resolver.Query.users(undefined, { limit, offset }, context);
/* eslint-disable-next-line unicorn/no-useless-undefined */
expect(list).toBeCalledWith(limit, offset, undefined, undefined);

expect(paginatedList).toBeCalledWith(
limit,
offset,
/* eslint-disable-next-line unicorn/no-useless-undefined */
undefined,
/* eslint-disable-next-line unicorn/no-useless-undefined */
undefined
);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/user/src/model/user-profiles/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const plugin = async (
sort?: string;
};

const data = await service.list(
const data = await service.paginatedList(
limit,
offset,
filters ? JSON.parse(filters) : undefined,
Expand Down
2 changes: 1 addition & 1 deletion packages/user/src/model/user-profiles/resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const Query: Record<string, any> = {
) => {
const service = new Service(context.config, context.database);

return await service.list(
return await service.paginatedList(
arguments_.limit,
arguments_.offset,
arguments_.filters
Expand Down

0 comments on commit 00954dc

Please sign in to comment.