Skip to content

Commit

Permalink
feat: rename isOwned to isOwnedBy
Browse files Browse the repository at this point in the history
  • Loading branch information
shuffledex committed Nov 4, 2020
1 parent 088b63f commit 1136439
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions src/api/entities/Portfolio/__tests__/index.ts
Expand Up @@ -52,7 +52,7 @@ describe('Portfolio class', () => {
});
});

describe('method: isOwned', () => {
describe('method: isOwnedBy', () => {
let did: string;

beforeAll(() => {
Expand All @@ -63,13 +63,13 @@ describe('Portfolio class', () => {
test('should return whether the current Identity is the Portfolio owner', async () => {
let portfolio = new Portfolio({ did }, context);

let result = await portfolio.isOwned();
let result = await portfolio.isOwnedBy();

expect(result).toBe(true);

portfolio = new Portfolio({ did: 'notTheCurrentIdentity' }, context);

result = await portfolio.isOwned();
result = await portfolio.isOwnedBy({ identity: did });

expect(result).toBe(false);
});
Expand Down
10 changes: 6 additions & 4 deletions src/api/entities/Portfolio/index.ts
Expand Up @@ -4,7 +4,7 @@ import { Ticker } from 'polymesh-types/types';

import { Entity, Identity, SecurityToken } from '~/api/entities';
import { Context } from '~/base';
import { balanceToBigNumber, portfolioIdToMeshPortfolioId, tickerToString } from '~/utils';
import { balanceToBigNumber, getDid, portfolioIdToMeshPortfolioId, tickerToString } from '~/utils';

import { PortfolioBalance } from './types';

Expand Down Expand Up @@ -50,15 +50,17 @@ export class Portfolio extends Entity<UniqueIdentifiers> {
}

/**
* Return whether the current Identity is the Portfolio owner
* Return whether an Identity is the Portfolio owner
*
* @param args.identity - defaults to the current Identity
*/
public async isOwned(): Promise<boolean> {
public async isOwnedBy(args?: { identity: string | Identity }): Promise<boolean> {
const {
owner: { did: ownerDid },
context,
} = this;

const { did } = await context.getCurrentIdentity();
const did = await getDid(args?.identity, context);

return ownerDid === did;
}
Expand Down
2 changes: 1 addition & 1 deletion src/api/procedures/deletePortfolio.ts
Expand Up @@ -34,7 +34,7 @@ export async function prepareDeletePortfolio(
const rawPortfolioNumber = numberToU64(id, context);

const [isOwned, rawPortfolioName, portfolioBalances] = await Promise.all([
numberedPortfolio.isOwned(),
numberedPortfolio.isOwnedBy(),
queryPortfolio.portfolios(identityId, rawPortfolioNumber),
numberedPortfolio.getTokenBalances(),
]);
Expand Down
2 changes: 1 addition & 1 deletion src/api/procedures/renamePortfolio.ts
Expand Up @@ -38,7 +38,7 @@ export async function prepareRenamePortfolio(
const rawPortfolioNumber = numberToU64(id, context);

const [isOwned, rawPortfolioName, rawPortfolios] = await Promise.all([
numberedPortfolio.isOwned(),
numberedPortfolio.isOwnedBy(),
queryPortfolio.portfolios(identityId, rawPortfolioNumber),
queryPortfolio.portfolios.entries(identityId),
]);
Expand Down
6 changes: 3 additions & 3 deletions src/testUtils/mocks/entities.ts
Expand Up @@ -171,7 +171,7 @@ let currentAccountGetTransactionHistoryStub: SinonStub;
let tickerReservationDetailsStub: SinonStub;
let venueDetailsStub: SinonStub;
let instructionDetailsStub: SinonStub;
let numberedPortfolioIsOwnedStub: SinonStub;
let numberedPortfolioIsOwnedByStub: SinonStub;
let numberedPortfolioGetTokenBalancesStub: SinonStub;

const MockIdentityClass = class {
Expand Down Expand Up @@ -503,7 +503,7 @@ function initVenue(opts?: VenueOptions): void {
function configureNumberedPortfolio(opts: NumberedPortfolioOptions): void {
const numberedPortfolio = ({
id: opts.id,
isOwned: numberedPortfolioIsOwnedStub.resolves(opts.isOwned),
isOwnedBy: numberedPortfolioIsOwnedByStub.resolves(opts.isOwned),
getTokenBalances: numberedPortfolioGetTokenBalancesStub.resolves(opts.tokenBalances),
} as unknown) as MockNumberedPortfolio;

Expand All @@ -519,7 +519,7 @@ function configureNumberedPortfolio(opts: NumberedPortfolioOptions): void {
*/
function initNumberedPortfolio(opts?: NumberedPortfolioOptions): void {
numberedPortfolioConstructorStub = sinon.stub();
numberedPortfolioIsOwnedStub = sinon.stub();
numberedPortfolioIsOwnedByStub = sinon.stub();
numberedPortfolioGetTokenBalancesStub = sinon.stub();

numberedPortfolioOptions = { ...defaultNumberedPortfolioOptions, ...opts };
Expand Down

0 comments on commit 1136439

Please sign in to comment.