Skip to content

Commit

Permalink
Merge pull request #33 from PolymathNetwork/feat/MSDK-71-security-tok…
Browse files Browse the repository at this point in the history
…en-entity

Feat/msdk 71 security token entity
  • Loading branch information
shuffledex authored Mar 8, 2020
2 parents 2c95127 + d2c6dab commit e5f18c9
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
40 changes: 40 additions & 0 deletions src/api/entities/SecurityToken/__tests__/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Entity } from '~/base';
import { PolkadotMockFactory } from '~/testUtils/mocks';

import { SecurityToken } from '../';

describe('SecurityToken class', () => {
const polkadotMockFactory = new PolkadotMockFactory();

polkadotMockFactory.initMocks({ mockContext: true });

afterEach(() => {
polkadotMockFactory.reset();
});

afterAll(() => {
polkadotMockFactory.cleanup();
});

test('should extend entity', () => {
expect(SecurityToken.prototype instanceof Entity).toBe(true);
});

describe('constructor', () => {
test('should assign ticker to instance', () => {
const ticker = 'test';
const context = polkadotMockFactory.getContextInstance();
const securityToken = new SecurityToken({ ticker }, context);

expect(securityToken.ticker).toBe(ticker);
});
});

describe('method: isUniqueIdentifiers', () => {
test('should return true if the object conforms to the interface', () => {
expect(SecurityToken.isUniqueIdentifiers({ ticker: 'someTicker' })).toBe(true);
expect(SecurityToken.isUniqueIdentifiers({})).toBe(false);
expect(SecurityToken.isUniqueIdentifiers({ ticker: 3 })).toBe(false);
});
});
});
43 changes: 43 additions & 0 deletions src/api/entities/SecurityToken/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { Entity } from '~/base';
import { Context } from '~/context';

/**
* Properties that uniquely identify a Security Token
*/
export interface UniqueIdentifiers {
/**
* ticker of the security token
*/
ticker: string;
}

/**
* Class used to manage all the Security Token functionality
*/
export class SecurityToken extends Entity<UniqueIdentifiers> {
/**
* @hidden
* Check if a value is of type [[UniqueIdentifiers]]
*/
public static isUniqueIdentifiers(identifier: unknown): identifier is UniqueIdentifiers {
const { ticker } = identifier as UniqueIdentifiers;

return typeof ticker === 'string';
}

/**
* ticker of the Security Token
*/
public ticker: string;

/**
* @hidden
*/
constructor(identifiers: UniqueIdentifiers, context: Context) {
super(identifiers, context);

const { ticker } = identifiers;

this.ticker = ticker;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
} from '~/testUtils/mocks';
import { TickerReservationStatus } from '~/types';

import { TickerReservation } from '../TickerReservation';
import { TickerReservation } from '../';

describe('TickerReservation class', () => {
const polkadotMockFactory = new PolkadotMockFactory();
Expand Down
1 change: 1 addition & 0 deletions src/api/entities/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { Identity } from './Identity';
export { TickerReservation } from './TickerReservation';
export { SecurityToken } from './SecurityToken';

0 comments on commit e5f18c9

Please sign in to comment.