Merge pull request #6 from sharpshark28/2
Test to prove sorting by integer works
This commit is contained in:
commit
652d417f66
3 changed files with 21 additions and 2 deletions
|
@ -48,8 +48,6 @@ Simpler version of search using a custom function in the chain.
|
|||
|
||||
#### Sort
|
||||
|
||||
Currently supports booleans and strings. (See [#1](https://github.com/sharpshark28/json-query-chain/issues/2) for Integer Support)
|
||||
|
||||
##### By Boolean
|
||||
|
||||
```javascript
|
||||
|
@ -62,6 +60,12 @@ Currently supports booleans and strings. (See [#1](https://github.com/sharpshark
|
|||
.sort('name')
|
||||
```
|
||||
|
||||
##### By Number
|
||||
|
||||
```javascript
|
||||
.sort('netWorth')
|
||||
```
|
||||
|
||||
#### Pagination
|
||||
|
||||
Page 1 with 5 results per page.
|
||||
|
|
|
@ -58,6 +58,16 @@ test('should sort by boolean isActive', () => {
|
|||
expect(query[0].name).toBe('Katelyn Steele');
|
||||
});
|
||||
|
||||
test('should sort by number netWorth', () => {
|
||||
let query = new Query(TestData)
|
||||
.sort('netWorth')
|
||||
.results;
|
||||
|
||||
expect(query[0].name).toBe('Howard Buckley'); // Negative
|
||||
expect(query[1].name).toBe('Natalia Petty'); // 0
|
||||
expect(query[query.length - 1].name).toBe('Newman Mays'); // Richest
|
||||
});
|
||||
|
||||
test('should sort by string name', () => {
|
||||
let query = new Query(TestData)
|
||||
.sort('name')
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
"_id": "5928038b69b33613f3577487",
|
||||
"isActive": true,
|
||||
"age": 20,
|
||||
"netWorth": 54200.49,
|
||||
"name": "Haynes Meadows",
|
||||
"tags": [
|
||||
"et",
|
||||
|
@ -18,6 +19,7 @@
|
|||
"_id": "5928038ba2400e7e09550991",
|
||||
"isActive": false,
|
||||
"age": 22,
|
||||
"netWorth": 11900,
|
||||
"name": "Katelyn Steele",
|
||||
"tags": [
|
||||
"cupidatat",
|
||||
|
@ -33,6 +35,7 @@
|
|||
"_id": "5928038bff4df5c29016be22",
|
||||
"isActive": false,
|
||||
"age": 29,
|
||||
"netWorth": 0,
|
||||
"name": "Natalia Petty",
|
||||
"tags": [
|
||||
"nulla",
|
||||
|
@ -48,6 +51,7 @@
|
|||
"_id": "5928038b496f64e646cb8d69",
|
||||
"isActive": false,
|
||||
"age": 34,
|
||||
"netWorth": -5000.2,
|
||||
"name": "Howard Buckley",
|
||||
"tags": [
|
||||
"qui",
|
||||
|
@ -63,6 +67,7 @@
|
|||
"_id": "5928038b4d214186ba1e7fa2",
|
||||
"isActive": false,
|
||||
"age": 22,
|
||||
"netWorth": 401512.99,
|
||||
"name": "Jenkins Mosley",
|
||||
"tags": [
|
||||
"adipisicing",
|
||||
|
|
Loading…
Add table
Reference in a new issue