-
Notifications
You must be signed in to change notification settings - Fork 106
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from mike-north/ex3-tests
Exercise 3 tests
- Loading branch information
Showing
6 changed files
with
88 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { assert } from 'chai'; | ||
import { slow, suite, test, timeout } from 'mocha-typescript'; | ||
import { getAllOrders } from '../src/data/orders'; | ||
|
||
@suite('EX3: Order List Query - Pagination tests') | ||
class EmployeeDataTest { | ||
@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' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { assert } from 'chai'; | ||
import { sortBy } from 'lodash'; | ||
import { slow, suite, test, timeout } from 'mocha-typescript'; | ||
import { getAllOrders } from '../src/data/orders'; | ||
|
||
@suite('EX3: Order List Query - Sort tests') | ||
class EmployeeDataTest { | ||
@test('By default, order list is sorted ascending by Id') | ||
public async orderListDefaults() { | ||
let firstPageResult = await getAllOrders({ perPage: 3 }); | ||
let sortedById = sortBy(firstPageResult, 'Id'); | ||
assert.deepEqual(firstPageResult, sortedById); | ||
} | ||
|
||
@test('using order="desc" (and specifying no column to sort on) sorts decending by Id') | ||
public async orderListDesc() { | ||
let firstPageResult = await getAllOrders({ perPage: 3, order: 'desc' }); | ||
let sortedById = sortBy(firstPageResult, o => { | ||
let id: number = typeof o.Id === 'string' ? parseInt(o.Id, 10) : o.Id; | ||
return -1 * id; | ||
}); | ||
assert.deepEqual(firstPageResult, sortedById); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
{ | ||
"extends": "../tsconfig", | ||
"include": ["./"] | ||
"include": ["./", "../src/types"] | ||
} |