-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: sort stake pools by fixed cost
- Loading branch information
1 parent
161ccd8
commit 6e1d6e4
Showing
8 changed files
with
2,545 additions
and
14 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
43 changes: 43 additions & 0 deletions
43
packages/cardano-services/test/StakePool/DbSyncStakePoolProvider/queries.test.ts
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,43 @@ | ||
import { withSort } from '../../../src/StakePool/DbSyncStakePoolProvider/queries'; | ||
|
||
describe('queries', () => { | ||
describe('withSort', () => { | ||
const dummyQuery = 'SELECT * FROM table'; | ||
test('sort by field with no mapping', () => { | ||
const query = withSort(dummyQuery, { field: 'saturation', order: 'asc' }); | ||
expect(query).toEqual(`${dummyQuery} ORDER BY saturation asc NULLS LAST, id asc NULLS LAST`); | ||
}); | ||
test('sort by field with simple mapping', () => { | ||
const query = withSort(dummyQuery, { field: 'name', order: 'asc' }); | ||
expect(query).toEqual( | ||
`${dummyQuery} ORDER BY lower((pod.json -> 'name')::TEXT) asc NULLS LAST, pool_id asc NULLS LAST` | ||
); | ||
}); | ||
test('sort by field with secondary sorts', () => { | ||
const query = withSort(dummyQuery, { field: 'cost', order: 'asc' }); | ||
expect(query).toEqual( | ||
`${dummyQuery} ORDER BY fixed_cost asc NULLS LAST, margin asc NULLS LAST, pool_id asc NULLS LAST` | ||
); | ||
}); | ||
test('single default sort', () => { | ||
const query = withSort(dummyQuery, undefined, [{ field: 'some_field', order: 'asc' }]); | ||
expect(query).toEqual(`${dummyQuery} ORDER BY some_field asc NULLS LAST`); | ||
}); | ||
test('multiple default sort', () => { | ||
const query = withSort(dummyQuery, undefined, [ | ||
{ field: 'some_field', order: 'asc' }, | ||
{ field: 'another_field', order: 'desc' } | ||
]); | ||
expect(query).toEqual(`${dummyQuery} ORDER BY some_field asc NULLS LAST, another_field desc NULLS LAST`); | ||
}); | ||
test('multiple default sort with secondary mapped sorts', () => { | ||
const query = withSort(dummyQuery, undefined, [ | ||
{ field: 'some_field', order: 'asc' }, | ||
{ field: 'cost', order: 'desc' } | ||
]); | ||
expect(query).toEqual( | ||
`${dummyQuery} ORDER BY some_field asc NULLS LAST, fixed_cost desc NULLS LAST, margin desc NULLS LAST` | ||
); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.