Handle no council for bounties proposals (#3062)

* Handle no council for bounties proposals

* Fix code climate

* Handle no council present with api derive
This commit is contained in:
Ewa Kowalska
2021-01-18 09:33:20 +01:00
committed by GitHub
parent 129d1214fe
commit d5cfa9b0e9
2 changed files with 25 additions and 3 deletions
@@ -59,7 +59,7 @@ describe('bounties derive', () => {
bountyDescriptions: {
multi: () => of([
optionOf(bytes('make polkadot even better')),
optionOf(bytes('this will be totally ignored'))
optionOf(bytes('some other bounty'))
])
}
}
@@ -117,6 +117,28 @@ describe('bounties derive', () => {
expect(result[1].proposals).toHaveLength(0);
});
it('when no council, returns bounties without motions', async () => {
const mockApi = {
...defaultMockApi,
query: {
...defaultMockApi.query,
council: null
}
} as unknown as ApiInterfaceRx;
const result = await bounties('', mockApi)().toPromise();
expect(result).toHaveLength(2);
expect(result[0].bounty.proposer.toString()).toEqual(DEFAULT_PROPOSER);
expect(result[0].description).toEqual('make polkadot even better');
expect(result[0].index.eq(0)).toBe(true);
expect(result[0].proposals).toHaveLength(0);
expect(result[1].bounty.proposer.toString()).toEqual(DEFAULT_PROPOSER);
expect(result[1].description).toEqual('some other bounty');
expect(result[1].index.eq(1)).toBe(true);
expect(result[1].proposals).toHaveLength(0);
});
it('combines bounties with motions', async () => {
const mockApi = {
...defaultMockApi,
+2 -2
View File
@@ -37,12 +37,12 @@ export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observ
return memo(instanceId, (): Observable<DeriveBounties> =>
combineLatest([
bountyBase.bountyCount<BountyIndex>(),
api.query.council.proposalCount<ProposalIndex>()
api.query.council ? api.query.council.proposalCount<ProposalIndex>() : of(0)
]).pipe(
switchMap(() =>
combineLatest([
bountyBase.bounties.keys(),
api.derive.council.proposals()
api.derive.council ? api.derive.council.proposals() : of([])
])
),
switchMap(([keys, proposals]): Observable<Result> => {