From 5a8c5838acbee885147d8bdffe0c4a9bd7e1a910 Mon Sep 17 00:00:00 2001 From: Cedrik Date: Tue, 20 Apr 2021 07:52:48 -0500 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20sort?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/__tests__/ardb.ts | 22 ++++++++++++++++++++++ src/ardb.ts | 5 ++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/__tests__/ardb.ts b/src/__tests__/ardb.ts index ceb28de..8fe2658 100644 --- a/src/__tests__/ardb.ts +++ b/src/__tests__/ardb.ts @@ -106,3 +106,25 @@ test('exclude', async () => { expect(res2[0].node.owner).not.toHaveProperty('address'); expect(res2[0].node.owner).toHaveProperty('key'); }); + +test('order', async () => { + let res = await ardb + .search('transactions') + .appName('SmartWeaveAction') + .tag('Type', 'ArweaveActivity') + .only('id') + .sort('HEIGHT_ASC') + .find(); + + expect(res[0].node.id).toBe('5AYV-RdPCoyfjeeabHVnDGvXrFNM5azcTlkNpp7RQhE'); + + res = await ardb + .search('transactions') + .appName('SmartWeaveAction') + .tag('Type', 'ArweaveActivity') + .only('id') + .sort('HEIGHT_DESC') + .find(); + + expect(res[0].node.id).not.toBe('5AYV-RdPCoyfjeeabHVnDGvXrFNM5azcTlkNpp7RQhE'); +}); \ No newline at end of file diff --git a/src/ardb.ts b/src/ardb.ts index b57cd19..37cf2c6 100644 --- a/src/ardb.ts +++ b/src/ardb.ts @@ -407,7 +407,10 @@ export default class ArDB { this.options = { id: this.options.id }; } - let params: string = JSON.stringify(this.options, null, 2).replace(/"([^"]+)":/gm, '$1: '); + let params: string = JSON.stringify(this.options, null, 2) + .replace(/"([^"]+)":/gm, '$1: ') + .replace('"HEIGHT_DESC"', 'HEIGHT_DESC') + .replace('"HEIGHT_ASC"', 'HEIGHT_ASC'); params = params.substring(1, params.length - 1); let fields: string = '';