Skip to content

Commit

Permalink
feat: portfolio getName method
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Oct 23, 2020
1 parent 84dd7da commit eb64d24
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/api/entities/NumberedPortfolio.ts
Expand Up @@ -2,6 +2,7 @@ import BigNumber from 'bignumber.js';

import { Portfolio } from '~/api/entities';
import { Context } from '~/base';
import { bytesToString, numberToU64 } from '~/utils';

export interface UniqueIdentifiers {
did: string;
Expand Down Expand Up @@ -37,4 +38,23 @@ export class NumberedPortfolio extends Portfolio {

this.id = id;
}

/**
* Return the Portfolio name
*/
public async getName(): Promise<string> {
const {
owner: { did },
id,
context: {
polymeshApi: {
query: { portfolio },
},
},
context,
} = this;

const rawPortfolioName = await portfolio.portfolios(did, numberToU64(id, context));
return bytesToString(rawPortfolioName);
}
}
18 changes: 18 additions & 0 deletions src/api/entities/__tests__/NumberedPortfolio.ts
Expand Up @@ -50,4 +50,22 @@ describe('Numberedortfolio class', () => {
expect(NumberedPortfolio.isUniqueIdentifiers({ did: 1, id: new BigNumber(1) })).toBe(false);
});
});

describe('method: getName', () => {
test('should return the name of the Portfolio', async () => {
const id = new BigNumber(1);
const did = 'someDid';
const portfolioName = 'someName';
const rawPortfolioName = dsMockUtils.createMockBytes(portfolioName);
const numberedPortfolio = new NumberedPortfolio({ id, did }, context);

dsMockUtils.createQueryStub('portfolio', 'portfolios', {
returnValue: rawPortfolioName,
});

const result = await numberedPortfolio.getName();

expect(result).toEqual(portfolioName);
});
});
});

0 comments on commit eb64d24

Please sign in to comment.