Skip to content

Commit 3a4fb57

Browse files
committed
Add tests for sortFields type
1 parent ea25ca3 commit 3a4fb57

File tree

2 files changed

+173
-3
lines changed

2 files changed

+173
-3
lines changed

src/__snapshots__/sql-cursor-pagination.test.ts.snap

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,122 @@ exports[`SqlCursorPagination > errors > throws an error if \`before\` was for a
666666
}
667667
`;
668668

669+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 1`] = `2`;
670+
671+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 2`] = `
672+
{
673+
"bindings": [],
674+
"sql": "\`id\` asc",
675+
}
676+
`;
677+
678+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 3`] = `
679+
{
680+
"bindings": [],
681+
"sql": "\`id\` asc",
682+
}
683+
`;
684+
685+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 4`] = `
686+
{
687+
"bindings": [],
688+
"sql": "\`id\` asc",
689+
}
690+
`;
691+
692+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 5`] = `
693+
{
694+
"bindings": {},
695+
"sql": "\`id\` asc",
696+
}
697+
`;
698+
699+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 6`] = `
700+
{
701+
"bindings": [],
702+
"sql": "1",
703+
}
704+
`;
705+
706+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 7`] = `
707+
{
708+
"bindings": [],
709+
"sql": "1",
710+
}
711+
`;
712+
713+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 8`] = `
714+
{
715+
"bindings": [],
716+
"sql": "1",
717+
}
718+
`;
719+
720+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 9`] = `
721+
{
722+
"bindings": {},
723+
"sql": "1",
724+
}
725+
`;
726+
727+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 10`] = `2`;
728+
729+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 11`] = `
730+
{
731+
"bindings": [],
732+
"sql": "\`id\` asc",
733+
}
734+
`;
735+
736+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 12`] = `
737+
{
738+
"bindings": [],
739+
"sql": "\`id\` asc",
740+
}
741+
`;
742+
743+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 13`] = `
744+
{
745+
"bindings": [],
746+
"sql": "\`id\` asc",
747+
}
748+
`;
749+
750+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 14`] = `
751+
{
752+
"bindings": {},
753+
"sql": "\`id\` asc",
754+
}
755+
`;
756+
757+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 15`] = `
758+
{
759+
"bindings": [],
760+
"sql": "1",
761+
}
762+
`;
763+
764+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 16`] = `
765+
{
766+
"bindings": [],
767+
"sql": "1",
768+
}
769+
`;
770+
771+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 17`] = `
772+
{
773+
"bindings": [],
774+
"sql": "1",
775+
}
776+
`;
777+
778+
exports[`SqlCursorPagination > errors > throws an error if \`sortFields\` is invalid 18`] = `
779+
{
780+
"bindings": {},
781+
"sql": "1",
782+
}
783+
`;
784+
669785
exports[`SqlCursorPagination > errors > throws an error if a duplicate cursor is created 1`] = `Infinity`;
670786

671787
exports[`SqlCursorPagination > errors > throws an error if a duplicate cursor is created 2`] = `

src/sql-cursor-pagination.test.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,13 @@ describe('SqlCursorPagination', () => {
888888
first: 1,
889889
},
890890
setup: {
891-
sortFields: [{ field: '!', order: Asc }],
891+
sortFields: [
892+
{
893+
// @ts-expect-error invalid field name
894+
field: '!',
895+
order: Asc,
896+
},
897+
],
892898
},
893899
}),
894900
).rejects.toThrowError('Invalid field name');
@@ -900,8 +906,56 @@ describe('SqlCursorPagination', () => {
900906
first: 1,
901907
},
902908
setup: {
903-
// @ts-expect-error invalid order
904-
sortFields: [{ field: 'a', order: 'oops' }],
909+
sortFields: [
910+
{
911+
field: {
912+
// @ts-expect-error invalid field alias
913+
alias: '!',
914+
name: 'id',
915+
},
916+
order: Asc,
917+
},
918+
],
919+
},
920+
}),
921+
).rejects.toThrowError('"!" field is missing');
922+
923+
await expect(
924+
async () =>
925+
await runWithPagination({
926+
query: {
927+
first: 1,
928+
},
929+
setup: {
930+
sortFields: [
931+
{
932+
field: {
933+
// @ts-expect-error invalid field alias
934+
alias: 'a.id',
935+
name: 'id',
936+
},
937+
order: Asc,
938+
},
939+
],
940+
},
941+
}),
942+
).rejects.toThrowError('"a.id" field is missing');
943+
944+
await expect(
945+
async () =>
946+
await runWithPagination({
947+
query: {
948+
first: 1,
949+
},
950+
setup: {
951+
sortFields: [
952+
{
953+
// @ts-expect-error invalid field name
954+
field: 'a',
955+
// @ts-expect-error invalid order
956+
order: 'oops',
957+
},
958+
],
905959
},
906960
}),
907961
).rejects.toThrowError(

0 commit comments

Comments
 (0)