Skip to content

Commit f0fb387

Browse files
authored
feat: entities endpoint (#147)
1 parent 4c239aa commit f0fb387

7 files changed

Lines changed: 88 additions & 0 deletions

File tree

__tests__/mocks/entities.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
};

__tests__/mocks/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Connection } from "../../src";
22

33
import { mockBlocks } from "./blocks";
44
import { mockDelegates } from "./delegates";
5+
import { mockEntities } from "./entities";
56
import { mockLocks } from "./locks";
67
import { mockNode } from "./node";
78
import { 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);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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+
});

src/resources/entities.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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+
}

src/resources/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { Blocks } from "./blocks";
22
import { Delegates } from "./delegates";
3+
import { Entities } from "./entities";
34
import { Locks } from "./locks";
45
import { Node } from "./node";
56
import { Peers } from "./peers";
@@ -14,6 +15,7 @@ export * from "./resource";
1415
export const Resources = {
1516
blocks: Blocks,
1617
delegates: Delegates,
18+
entities: Entities,
1719
locks: Locks,
1820
node: Node,
1921
peers: Peers,

src/resourcesTypes/entities.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
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+
}

src/resourcesTypes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./blocks";
22
export * from "./delegates";
3+
export * from "./entities";
34
export * from "./locks";
45
export * from "./node";
56
export * from "./peers";

0 commit comments

Comments
 (0)