Fix queryRecords to return results filtered by attributes

This commit is contained in:
nabarun 2022-04-13 17:37:24 +05:30 committed by Ashwin Phatak
parent 0bc619cad2
commit 407d31cea7

View File

@ -1,13 +1,10 @@
import assert from 'assert'; import assert from 'assert';
import path from 'path'; import path from 'path';
import semver from 'semver';
import { Account } from './account'; import { Account } from './account';
import { Registry } from './index'; import { Registry } from './index';
import { getBaseConfig, getConfig } from './testing/helper'; import { ensureUpdatedConfig, getBaseConfig, getConfig } from './testing/helper';
const WATCHER_1_ID = 'bafyreif7z4lbftuxkj7nu4bl7xihitqvhus3wmoqdkjo7lwv24j6fkfskm'
const WATCHER_2_ID = 'bafyreiaplz7n2bddg3xhkeuiavwnku7xta2s2cfyaza37ytv4vw367exo4'
const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml'); const WATCHER_YML_PATH = path.join(__dirname, './testing/data/watcher.yml');
jest.setTimeout(120 * 1000); jest.setTimeout(120 * 1000);
@ -35,9 +32,8 @@ const namingTests = () => {
await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee); await registry.createBond({ denom: 'aphoton', amount: '1000000000' }, privateKey, fee);
// Create bot. // Create bot.
// TODO: Use ensureUpdatedConfig from helper. watcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
watcher = await getBaseConfig(WATCHER_YML_PATH); await registry.setRecord(
const result = await registry.setRecord(
{ {
privateKey, privateKey,
bondId, bondId,
@ -47,9 +43,8 @@ const namingTests = () => {
fee fee
) )
// TODO: Get id from setRecord response. const [record] = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true);
// watcherId = result.data; watcherId = record.id;
watcherId = WATCHER_1_ID;
}); });
test('Reserve authority.', async () => { test('Reserve authority.', async () => {
@ -127,8 +122,7 @@ const namingTests = () => {
// Query records should return it (some WRN points to it). // Query records should return it (some WRN points to it).
const records = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }); const records = await registry.queryRecords({ type: 'watcher', version: watcher.record.version });
expect(records).toBeDefined(); expect(records).toBeDefined();
// TODO: Fix queryRecords to return filtered results. expect(records).toHaveLength(1);
// expect(records).toHaveLength(1);
}); });
test('Lookup name', async () => { test('Lookup name', async () => {
@ -154,10 +148,8 @@ const namingTests = () => {
}); });
test('Lookup name with history', async () => { test('Lookup name with history', async () => {
// TODO: Use ensureUpdatedConfig from helper. const updatedWatcher = await ensureUpdatedConfig(WATCHER_YML_PATH);
const updatedWatcher = await getBaseConfig(WATCHER_YML_PATH); await registry.setRecord(
updatedWatcher.record.version = semver.inc(updatedWatcher.record.version, 'patch');
const result = await registry.setRecord(
{ {
privateKey, privateKey,
bondId, bondId,
@ -167,9 +159,8 @@ const namingTests = () => {
fee fee
) )
// TODO: Get id from setRecord response. const [record] = await registry.queryRecords({ type: 'watcher', version: updatedWatcher.record.version }, true);
// const updatedWatcherId = result.data; const updatedWatcherId = record.id;
const updatedWatcherId = WATCHER_2_ID;
await registry.setName({ wrn, cid: updatedWatcherId }, privateKey, fee); await registry.setName({ wrn, cid: updatedWatcherId }, privateKey, fee);
const records = await registry.lookupNames([wrn], true); const records = await registry.lookupNames([wrn], true);
@ -242,13 +233,12 @@ const namingTests = () => {
// Query records should NOT return it (no WRN points to it). // Query records should NOT return it (no WRN points to it).
records = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }); records = await registry.queryRecords({ type: 'watcher', version: watcher.record.version });
expect(records).toBeDefined(); expect(records).toBeDefined();
// TODO: Fix queryRecords to return filtered results. expect(records).toHaveLength(0);
// expect(records).toHaveLength(0);
// Query all records should return it (all: true). // Query all records should return it (all: true).
records = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true); records = await registry.queryRecords({ type: 'watcher', version: watcher.record.version }, true);
expect(records).toBeDefined(); expect(records).toBeDefined();
// expect(records).toHaveLength(1); expect(records).toHaveLength(1);
}); });
test('Delete already deleted name', async () => { test('Delete already deleted name', async () => {