File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import nock from "nock" ;
2+
3+ export const mockEntities = ( host : string ) => {
4+ nock ( host )
5+ . get ( "/entities" )
6+ . reply ( 200 , {
7+ data : [ ] ,
8+ } ) ;
9+
10+ nock ( host )
11+ . get ( "/entities/123" )
12+ . reply ( 200 , {
13+ data : [ ] ,
14+ } ) ;
15+ } ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { Connection } from "../../src";
22
33import { mockBlocks } from "./blocks" ;
44import { mockDelegates } from "./delegates" ;
5+ import { mockEntities } from "./entities" ;
56import { mockLocks } from "./locks" ;
67import { mockNode } from "./node" ;
78import { mockPeers } from "./peers" ;
@@ -16,6 +17,7 @@ export const configureMocks = <T>(resource): T => {
1617
1718 mockBlocks ( host ) ;
1819 mockDelegates ( host ) ;
20+ mockEntities ( host ) ;
1921 mockLocks ( host ) ;
2022 mockNode ( host ) ;
2123 mockPeers ( host ) ;
Original file line number Diff line number Diff line change 1+ import { Entities } from "../../src/resources/entities" ;
2+ import { configureMocks } from "../mocks" ;
3+
4+ const resource : Entities = configureMocks < Entities > ( Entities ) ;
5+
6+ describe ( "API - 2.0 - Resources - Entities" , ( ) => {
7+ it ( "should call \"all\" method" , async ( ) => {
8+ const response = await resource . all ( ) ;
9+
10+ expect ( response . status ) . toBe ( 200 ) ;
11+ } ) ;
12+
13+ it ( "should call \"get\" method" , async ( ) => {
14+ const response = await resource . get ( "123" ) ;
15+
16+ expect ( response . status ) . toBe ( 200 ) ;
17+ } ) ;
18+ } ) ;
Original file line number Diff line number Diff line change 1+ import { ApiResponse , ApiResponseWithPagination } from "../interfaces" ;
2+ import {
3+ AllEntitiesApiQuery ,
4+ Entity ,
5+ } from "../resourcesTypes/entities" ;
6+ import { Resource } from "./resource" ;
7+
8+ /**
9+ * This endpoints return Entities.
10+ */
11+ export class Entities extends Resource {
12+ /**
13+ * List all entities
14+ */
15+ public async all ( query ?: AllEntitiesApiQuery ) : Promise < ApiResponseWithPagination < Entity [ ] > > {
16+ return this . sendGet ( "entities" , query ) ;
17+ }
18+
19+ /**
20+ * Return entity by id
21+ * @param id Entity id
22+ */
23+ public async get ( id : string ) : Promise < ApiResponse < Entity > > {
24+ return this . sendGet ( `entities/${ id } ` ) ;
25+ }
26+ }
Original file line number Diff line number Diff line change 11import { Blocks } from "./blocks" ;
22import { Delegates } from "./delegates" ;
3+ import { Entities } from "./entities" ;
34import { Locks } from "./locks" ;
45import { Node } from "./node" ;
56import { Peers } from "./peers" ;
@@ -14,6 +15,7 @@ export * from "./resource";
1415export const Resources = {
1516 blocks : Blocks ,
1617 delegates : Delegates ,
18+ entities : Entities ,
1719 locks : Locks ,
1820 node : Node ,
1921 peers : Peers ,
Original file line number Diff line number Diff line change 1+ import { ApiQuery } from "../interfaces" ;
2+
3+ export interface Entity {
4+ id ?: string ;
5+ address ?: string ;
6+ publicKey ?: string ;
7+ isResigned ?: boolean ;
8+ type ?: number ;
9+ subType ?: number ;
10+ data : {
11+ name ?: string ;
12+ ipfsData ?: string ;
13+ } ;
14+ }
15+
16+ export interface AllEntitiesApiQuery extends ApiQuery {
17+ /** Type by which it orders entities. */
18+ orderBy ?: string ;
19+ publicKey ?: string ;
20+ type ?: number ;
21+ subType ?: number ;
22+ name ?: string ;
23+ isResigned ?: boolean ;
24+ }
Original file line number Diff line number Diff line change 11export * from "./blocks" ;
22export * from "./delegates" ;
3+ export * from "./entities" ;
34export * from "./locks" ;
45export * from "./node" ;
56export * from "./peers" ;
You can’t perform that action at this time.
0 commit comments