|
1 | 1 | import { Cursor } from '../cursor/Cursor'; |
2 | 2 | import { Foo, FooConnection, FooConnectionBuilder, FooEdge } from '../../test/FooConnection'; |
3 | 3 | import { BarConnectionBuilder, FruitBar, NutBar } from '../../test/BarConnection'; |
| 4 | +import { ConnectionArgsValidationError } from '../error'; |
4 | 5 |
|
5 | 6 | describe('ConnectionBuilder', () => { |
6 | 7 | test('First page is built correctly', () => { |
@@ -283,4 +284,67 @@ describe('ConnectionBuilder', () => { |
283 | 284 | ], |
284 | 285 | }); |
285 | 286 | }); |
| 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 | + }); |
286 | 350 | }); |
0 commit comments