Tests for approvalFlagToBool (#1251)

* Tests for approvalFlagToBool

* Merge master
This commit is contained in:
Jaco Greeff
2019-08-02 20:44:25 +02:00
committed by GitHub
parent 658cdbbb10
commit 82a1c25f17
3 changed files with 43 additions and 3 deletions
@@ -0,0 +1,34 @@
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { ApprovalFlag } from '@polkadot/types/interfaces';
import { createType } from '@polkadot/types';
import { approvalFlagsToBools } from './approvalFlagsToBools';
describe('approvalFlagsToBools', (): void => {
it('translates and empty array to empty', (): void => {
expect(
approvalFlagsToBools([] as ApprovalFlag[])
).toEqual([]);
});
it('translates a single input', (): void => {
expect(
approvalFlagsToBools([
createType('ApprovalFlag', 0b1010)
])
).toEqual([false, true, false, true]);
});
it('translates multiple inputs', (): void => {
expect(
approvalFlagsToBools([
createType('ApprovalFlag', 0b0000),
createType('ApprovalFlag', 0b1100)
])
).toEqual([false, false, false, true, true]);
});
});
@@ -6,7 +6,7 @@ import { ApprovalFlag } from '@polkadot/types/interfaces/elections';
import { Vec } from '@polkadot/types';
export function approvalFlagsToBools (flags: Vec<ApprovalFlag>): boolean[] {
export function approvalFlagsToBools (flags: Vec<ApprovalFlag> | ApprovalFlag[]): boolean[] {
const bools: boolean[] = [];
flags.forEach((flag: ApprovalFlag): void => {