Skip to content

Commit

Permalink
feat: add namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
monitz87 committed Mar 19, 2020
1 parent 528474c commit ef55589
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/api/entities/TickerReservation/__tests__/index.ts
Expand Up @@ -30,7 +30,7 @@ describe('TickerReservation class', () => {
});

describe('constructor', () => {
test('should assign ticker instance', () => {
test('should assign ticker to instance', () => {
const ticker = 'abc';
const context = polkadotMockUtils.getContextInstance();
const tickerReservation = new TickerReservation({ ticker }, context);
Expand Down
19 changes: 19 additions & 0 deletions src/base/Namespace.ts
@@ -0,0 +1,19 @@
import { Entity } from '~/base';
import { Context } from '~/context';

/**
* Represents a namespace within an Entity with the purpose of grouping related functionality
*/
export class Namespace<Parent extends Entity<{}>> {
protected parent: Parent;

protected context: Context;

/**
* @hidden
*/
constructor(parent: Parent, context: Context) {
this.parent = parent;
this.context = context;
}
}
13 changes: 0 additions & 13 deletions src/base/__tests__/Entity.ts
@@ -1,23 +1,10 @@
import sinon from 'sinon';

import { polkadotMockUtils } from '~/testUtils/mocks';
import * as utils from '~/utils';

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

describe('Entity class', () => {
beforeAll(() => {
polkadotMockUtils.initMocks();
});

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

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

describe('method: generateUuid', () => {
test("should generate the Entity's UUID", async () => {
sinon
Expand Down
18 changes: 18 additions & 0 deletions src/base/__tests__/Namespace.ts
@@ -0,0 +1,18 @@
import { Entity } from '~/base';
import { Namespace } from '~/base/Namespace';
import { Context } from '~/context';

describe('Namespace class', () => {
describe('constructor', () => {
test('should assign parent and context to instance', () => {
const context = ('context' as unknown) as Context;
const parent = ('entity' as unknown) as Entity<{}>;
const namespace = new Namespace(parent, context);

/* eslint-disable @typescript-eslint/no-explicit-any */
expect((namespace as any).parent).toEqual(parent);
expect((namespace as any).context).toEqual(context);
/* eslint-enable @typescript-eslint/no-explicit-any */
});
});
});
1 change: 1 addition & 0 deletions src/base/index.ts
Expand Up @@ -4,3 +4,4 @@ export { PolymeshError } from './PolymeshError';
export { TransactionQueue } from './TransactionQueue';
export { Procedure } from './Procedure';
export { Entity } from './Entity';
export { Namespace } from './Namespace';

0 comments on commit ef55589

Please sign in to comment.