diff --git a/src/api/entities/SecurityToken/__tests__/index.ts b/src/api/entities/SecurityToken/__tests__/index.ts new file mode 100644 index 0000000000..3c00d640af --- /dev/null +++ b/src/api/entities/SecurityToken/__tests__/index.ts @@ -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); + }); + }); +}); diff --git a/src/api/entities/SecurityToken/index.ts b/src/api/entities/SecurityToken/index.ts new file mode 100644 index 0000000000..0b6fbf5c32 --- /dev/null +++ b/src/api/entities/SecurityToken/index.ts @@ -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 { + /** + * @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; + } +} diff --git a/src/api/entities/__tests__/TickerReservation.ts b/src/api/entities/TickerReservation/__tests__/index.ts similarity index 99% rename from src/api/entities/__tests__/TickerReservation.ts rename to src/api/entities/TickerReservation/__tests__/index.ts index 94680e226c..eaa14295f3 100644 --- a/src/api/entities/__tests__/TickerReservation.ts +++ b/src/api/entities/TickerReservation/__tests__/index.ts @@ -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(); diff --git a/src/api/entities/index.ts b/src/api/entities/index.ts index f32a32848b..2c092191a4 100644 --- a/src/api/entities/index.ts +++ b/src/api/entities/index.ts @@ -1,2 +1,3 @@ export { Identity } from './Identity'; export { TickerReservation } from './TickerReservation'; +export { SecurityToken } from './SecurityToken';