Skip to content

Commit

Permalink
fix(selector): remove double type nesting
Browse files Browse the repository at this point in the history
  • Loading branch information
DASPRiD committed Feb 15, 2024
1 parent ecd16e6 commit 66f45cf
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ type PaginatedCollectionSelector<TDocument> = Selector<
>;

export const createPaginatedCollectionSelector =
<TDocument extends DocumentResult<ResourceCollectionDocumentResult<AnyResourceDeserializer>>>(
<TDocument extends ResourceCollectionDocumentResult<AnyResourceDeserializer>>(
documentSelector: Selector<TDocument>,
): PaginatedCollectionSelector<TDocument> =>
(raw: unknown) => {
Expand Down
29 changes: 29 additions & 0 deletions test/selector.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
type Relationships,
createDataSelector,
createNullableResourceSelector,
createPaginatedCollectionSelector,
createResourceCollectionSelector,
createResourceSelector,
} from "../src/index.js";
Expand Down Expand Up @@ -230,3 +231,31 @@ describe("crateDataSelector", () => {
});
});
});

describe("cratePaginatedCollectionSelector", () => {
it("should extract page params", () => {
const selector = createPaginatedCollectionSelector(
createResourceCollectionSelector({
type: "article",
attributesSchema: z.object({ title: z.string() }),
}),
);

const result = selector({
data: [],
links: {
next: "/?page[number]=2",
},
});

expect(result).toEqual({
data: [],
links: {
next: "/?page[number]=2",
},
pageParams: {
next: { number: "2" },
},
});
});
});

0 comments on commit 66f45cf

Please sign in to comment.