forked from cerc-io/registry-sdk
Add a method to query bonds by owner and update tests
This commit is contained in:
parent
574434fede
commit
fc1ff1207a
@ -54,15 +54,20 @@ const bondTests = () => {
|
|||||||
test('Query bonds.', async () => {
|
test('Query bonds.', async () => {
|
||||||
const bonds = await registry.queryBonds();
|
const bonds = await registry.queryBonds();
|
||||||
expect(bonds).toBeDefined();
|
expect(bonds).toBeDefined();
|
||||||
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
|
|
||||||
expect(bond).toBeDefined();
|
const filteredBonds = bonds.filter((bond: any) => bond.id === bond1.id);
|
||||||
|
expect(filteredBonds).toHaveLength(1);
|
||||||
|
expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Query bonds by owner.', async () => {
|
test('Query bonds by owner.', async () => {
|
||||||
const bonds = await registry.queryBonds({ owner: bond1.owner });
|
const [result] = await registry.queryBondsByOwner([bond1.owner]);
|
||||||
expect(bonds).toBeDefined();
|
expect(result).toBeDefined();
|
||||||
const bond = bonds.filter((bond: any) => bond.id === bond1.id);
|
expect(result.bonds).toBeDefined();
|
||||||
expect(bond).toBeDefined();
|
|
||||||
|
const filteredBonds = result.bonds.filter((bond: any) => bond.id === bond1.id);
|
||||||
|
expect(filteredBonds).toHaveLength(1);
|
||||||
|
expect(filteredBonds[0]).toMatchObject({ id: bond1.id, owner: bond1.owner });
|
||||||
});
|
});
|
||||||
|
|
||||||
test('Refill bond.', async () => {
|
test('Refill bond.', async () => {
|
||||||
|
13
src/index.ts
13
src/index.ts
@ -192,10 +192,17 @@ export class Registry {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query bonds by attributes.
|
* Query bonds.
|
||||||
*/
|
*/
|
||||||
async queryBonds (attributes = {}) {
|
async queryBonds () {
|
||||||
return this._client.queryBonds(attributes);
|
return this._client.queryBonds();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Query bonds by owner(s).
|
||||||
|
*/
|
||||||
|
async queryBondsByOwner (owners: string[]) {
|
||||||
|
return this._client.queryBondsByOwner(owners);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -425,11 +425,11 @@ export class RegistryClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get bonds by attributes.
|
* Get bonds.
|
||||||
*/
|
*/
|
||||||
async queryBonds (attributes = {}) {
|
async queryBonds () {
|
||||||
const query = `query ($attributes: [KeyValueInput!]) {
|
const query = `query {
|
||||||
queryBonds(attributes: $attributes) {
|
queryBonds {
|
||||||
id
|
id
|
||||||
owner
|
owner
|
||||||
balance {
|
balance {
|
||||||
@ -439,11 +439,32 @@ export class RegistryClient {
|
|||||||
}
|
}
|
||||||
}`;
|
}`;
|
||||||
|
|
||||||
|
return RegistryClient.getResult(this._graph(query)({}), 'queryBonds');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get bonds by owner(s).
|
||||||
|
*/
|
||||||
|
async queryBondsByOwner (ownerAddresses: string[]) {
|
||||||
|
const query = `query ($ownerAddresses: [String!]) {
|
||||||
|
queryBondsByOwner(ownerAddresses: $ownerAddresses) {
|
||||||
|
owner
|
||||||
|
bonds {
|
||||||
|
id
|
||||||
|
owner
|
||||||
|
balance {
|
||||||
|
type
|
||||||
|
quantity
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}`;
|
||||||
|
|
||||||
const variables = {
|
const variables = {
|
||||||
attributes: Util.toGQLAttributes(attributes)
|
ownerAddresses
|
||||||
};
|
};
|
||||||
|
|
||||||
return RegistryClient.getResult(this._graph(query)(variables), 'queryBonds');
|
return RegistryClient.getResult(this._graph(query)(variables), 'queryBondsByOwner');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user