Skip to content

Commit be41dd9

Browse files
committed
test: connection arguments
1 parent 868f2af commit be41dd9

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

src/builder/ConnectionBuilder.spec.ts

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Cursor } from '../cursor/Cursor';
22
import { Foo, FooConnection, FooConnectionBuilder, FooEdge } from '../../test/FooConnection';
33
import { BarConnectionBuilder, FruitBar, NutBar } from '../../test/BarConnection';
4+
import { ConnectionArgsValidationError } from '../error';
45

56
describe('ConnectionBuilder', () => {
67
test('First page is built correctly', () => {
@@ -283,4 +284,67 @@ describe('ConnectionBuilder', () => {
283284
],
284285
});
285286
});
287+
288+
describe('Connection arguments', () => {
289+
test('Should throw an error if the connection does not support offset pagination', () => {
290+
const createBuilder = () =>
291+
new FooConnectionBuilder({
292+
page: 1,
293+
});
294+
295+
expect(createBuilder).toThrow(
296+
new ConnectionArgsValidationError('This connection does not support the "page" argument for pagination.'),
297+
);
298+
});
299+
300+
test('Should throw an error if first is less than zero', () => {
301+
const createBuilder = () =>
302+
new FooConnectionBuilder({
303+
first: -1,
304+
});
305+
306+
expect(createBuilder).toThrow(
307+
new ConnectionArgsValidationError(`The "first" argument accepts a value between 0 and 100, inclusive.`),
308+
);
309+
});
310+
311+
test('Should throw an error if both "first" and "last" arguments are supplied', () => {
312+
const createBuilder = () =>
313+
new FooConnectionBuilder({
314+
first: 5,
315+
last: 5,
316+
});
317+
318+
expect(createBuilder).toThrow(
319+
new ConnectionArgsValidationError(
320+
'It is not permitted to specify both "first" and "last" arguments simultaneously.',
321+
),
322+
);
323+
});
324+
325+
test('Should throw an error if last is less than zero', () => {
326+
const createBuilder = () =>
327+
new FooConnectionBuilder({
328+
last: -1,
329+
});
330+
331+
expect(createBuilder).toThrow(
332+
new ConnectionArgsValidationError(`The "last" argument accepts a value between 0 and 100, inclusive.`),
333+
);
334+
});
335+
336+
test('Should throw an error if both "after" and "before" arguments are supplied', () => {
337+
const createBuilder = () =>
338+
new FooConnectionBuilder({
339+
after: '...',
340+
before: '...'
341+
});
342+
343+
expect(createBuilder).toThrow(
344+
new ConnectionArgsValidationError(
345+
'It is not permitted to specify both "after" and "before" arguments simultaneously.',
346+
),
347+
);
348+
});
349+
});
286350
});

0 commit comments

Comments
 (0)