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
|
#### Sort
|
||||||
|
|
||||||
Currently supports booleans and strings. (See [#1](https://github.com/sharpshark28/json-query-chain/issues/2) for Integer Support)
|
|
||||||
|
|
||||||
##### By Boolean
|
##### By Boolean
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
|
@ -62,6 +60,12 @@ Currently supports booleans and strings. (See [#1](https://github.com/sharpshark
|
||||||
.sort('name')
|
.sort('name')
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### By Number
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
.sort('netWorth')
|
||||||
|
```
|
||||||
|
|
||||||
#### Pagination
|
#### Pagination
|
||||||
|
|
||||||
Page 1 with 5 results per page.
|
Page 1 with 5 results per page.
|
||||||
|
|
|
@ -58,6 +58,16 @@ test('should sort by boolean isActive', () => {
|
||||||
expect(query[0].name).toBe('Katelyn Steele');
|
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', () => {
|
test('should sort by string name', () => {
|
||||||
let query = new Query(TestData)
|
let query = new Query(TestData)
|
||||||
.sort('name')
|
.sort('name')
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
"_id": "5928038b69b33613f3577487",
|
"_id": "5928038b69b33613f3577487",
|
||||||
"isActive": true,
|
"isActive": true,
|
||||||
"age": 20,
|
"age": 20,
|
||||||
|
"netWorth": 54200.49,
|
||||||
"name": "Haynes Meadows",
|
"name": "Haynes Meadows",
|
||||||
"tags": [
|
"tags": [
|
||||||
"et",
|
"et",
|
||||||
|
@ -18,6 +19,7 @@
|
||||||
"_id": "5928038ba2400e7e09550991",
|
"_id": "5928038ba2400e7e09550991",
|
||||||
"isActive": false,
|
"isActive": false,
|
||||||
"age": 22,
|
"age": 22,
|
||||||
|
"netWorth": 11900,
|
||||||
"name": "Katelyn Steele",
|
"name": "Katelyn Steele",
|
||||||
"tags": [
|
"tags": [
|
||||||
"cupidatat",
|
"cupidatat",
|
||||||
|
@ -33,6 +35,7 @@
|
||||||
"_id": "5928038bff4df5c29016be22",
|
"_id": "5928038bff4df5c29016be22",
|
||||||
"isActive": false,
|
"isActive": false,
|
||||||
"age": 29,
|
"age": 29,
|
||||||
|
"netWorth": 0,
|
||||||
"name": "Natalia Petty",
|
"name": "Natalia Petty",
|
||||||
"tags": [
|
"tags": [
|
||||||
"nulla",
|
"nulla",
|
||||||
|
@ -48,6 +51,7 @@
|
||||||
"_id": "5928038b496f64e646cb8d69",
|
"_id": "5928038b496f64e646cb8d69",
|
||||||
"isActive": false,
|
"isActive": false,
|
||||||
"age": 34,
|
"age": 34,
|
||||||
|
"netWorth": -5000.2,
|
||||||
"name": "Howard Buckley",
|
"name": "Howard Buckley",
|
||||||
"tags": [
|
"tags": [
|
||||||
"qui",
|
"qui",
|
||||||
|
@ -63,6 +67,7 @@
|
||||||
"_id": "5928038b4d214186ba1e7fa2",
|
"_id": "5928038b4d214186ba1e7fa2",
|
||||||
"isActive": false,
|
"isActive": false,
|
||||||
"age": 22,
|
"age": 22,
|
||||||
|
"netWorth": 401512.99,
|
||||||
"name": "Jenkins Mosley",
|
"name": "Jenkins Mosley",
|
||||||
"tags": [
|
"tags": [
|
||||||
"adipisicing",
|
"adipisicing",
|
||||||
|
|
Loading…
Add table
Reference in a new issue