-
Notifications
You must be signed in to change notification settings - Fork 106
/
ex3.pagination-all-orders.test.ts
51 lines (45 loc) · 2.09 KB
/
ex3.pagination-all-orders.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { assert } from 'chai';
import { slow, suite, test, timeout } from 'mocha-typescript';
import { getAllOrders } from '../src/data/orders';
@suite('EX3: "All Orders List" Query - Pagination tests')
class AllOrdersPaginationTest {
@test('First item is the same, regardless of page size')
public async firstPage() {
let first40Result = await getAllOrders({ perPage: 40, page: 1 });
let first20Result = await getAllOrders({ perPage: 20, page: 1 });
assert.isArray(first20Result, 'Expected result to be an array');
assert.equal(first20Result.length, 20, 'Expected 20 orders in array when perPage = 20');
assert.equal(first40Result.length, 40, 'Expected 40 orders in array when perPage = 40');
}
@test('When perPage = 20, page 2 starts at item 20')
public async offset() {
let first40Result = await getAllOrders({ perPage: 40, page: 1 });
let first20Result = await getAllOrders({ perPage: 20, page: 1 });
let second20Result = await getAllOrders({ perPage: 20, page: 2 });
assert.isArray(second20Result, 'Expected result to be an array');
assert.equal(second20Result.length, 20, 'Expected 20 orders in array');
assert.deepEqual(
second20Result[0],
first40Result[20],
'First item on the second page of 20 is the 20th item on the first page of 40'
);
}
@test('If no perPage option is specified, page size is 25')
public async pageOf25ByDefault() {
let firstPageResult = await getAllOrders();
assert.isArray(firstPageResult, 'Expected result to be an array');
assert.equal(firstPageResult.length, 20, 'Expected 20 orders in array');
}
@test('If no page option is specified, first page is returned')
public async firstPageByDefault() {
let result = await getAllOrders();
let firstPageResult = await getAllOrders({ page: 1 });
assert.isArray(result, 'Expected result to be an array');
assert.isArray(firstPageResult, 'Expected result to be an array');
assert.deepEqual(
result[0],
firstPageResult[0],
'First item is the same, regardless of whether page=1 or page option is not provided at all'
);
}
}