Skip to content

Commit a260eea

Browse files
datedfaustbrian
authored andcommitted
feat: 2.6 api endpoints (#70)
1 parent 4f8941e commit a260eea

14 files changed

Lines changed: 241 additions & 0 deletions

File tree

__tests__/mocks/bridgechains.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import nock from "nock";
2+
3+
export const mockBridgechains = (host: string) => {
4+
nock(host)
5+
.get("/bridgechains")
6+
.reply(200, {
7+
data: [],
8+
});
9+
10+
nock(host)
11+
.get("/bridgechains/123")
12+
.reply(200, {
13+
data: [],
14+
});
15+
16+
nock(host)
17+
.post("/bridgechains/search")
18+
.reply(200, {
19+
data: [],
20+
});
21+
};

__tests__/mocks/businesses.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import nock from "nock";
2+
3+
export const mockBusinesses = (host: string) => {
4+
nock(host)
5+
.get("/businesses")
6+
.reply(200, {
7+
data: [],
8+
});
9+
10+
nock(host)
11+
.get("/businesses/123")
12+
.reply(200, {
13+
data: [],
14+
});
15+
16+
nock(host)
17+
.get("/businesses/123/bridgechains")
18+
.reply(200, {
19+
data: [],
20+
});
21+
22+
nock(host)
23+
.post("/businesses/search")
24+
.reply(200, {
25+
data: [],
26+
});
27+
};

__tests__/mocks/index.ts

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

33
import { mockBlocks } from "./blocks";
4+
import { mockBridgechains } from "./bridgechains";
5+
import { mockBusinesses } from "./businesses";
46
import { mockDelegates } from "./delegates";
7+
import { mockLocks } from "./locks";
58
import { mockNode } from "./node";
69
import { mockPeers } from "./peers";
710
import { mockRounds } from "./rounds";
@@ -14,7 +17,10 @@ export const configureMocks = <T>(resource): T => {
1417
const host = "https://example.net:4003/api";
1518

1619
mockBlocks(host);
20+
mockBridgechains(host);
21+
mockBusinesses(host);
1722
mockDelegates(host);
23+
mockLocks(host);
1824
mockNode(host);
1925
mockPeers(host);
2026
mockRounds(host);

__tests__/mocks/locks.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import nock from "nock";
2+
3+
export const mockLocks = (host: string) => {
4+
nock(host)
5+
.get("/locks")
6+
.reply(200, {
7+
data: [],
8+
});
9+
10+
nock(host)
11+
.get("/locks/123")
12+
.reply(200, {
13+
data: [],
14+
});
15+
16+
nock(host)
17+
.post("/locks/search")
18+
.reply(200, {
19+
data: [],
20+
});
21+
22+
nock(host)
23+
.post("/locks/unlocked")
24+
.reply(200, {
25+
data: [],
26+
});
27+
};

__tests__/mocks/wallets.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export const mockWallets = (host: string) => {
1313
.get("/wallets/123")
1414
.reply(200, { data: [] });
1515

16+
nock(host)
17+
.get("/wallets/123/locks")
18+
.reply(200, { data: [] });
19+
1620
nock(host)
1721
.get("/wallets/123/transactions")
1822
.reply(200, { data: [] });
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { Bridgechains } from "../../src/resources/bridgechains";
2+
import { configureMocks } from "../mocks";
3+
4+
const resource: Bridgechains = configureMocks<Bridgechains>(Bridgechains);
5+
6+
describe("API - 2.0 - Resources - Bridgechains", () => {
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+
19+
it("should call \"search\" method", async () => {
20+
const response = await resource.search({});
21+
22+
expect(response.status).toBe(200);
23+
});
24+
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Businesses } from "../../src/resources/businesses";
2+
import { configureMocks } from "../mocks";
3+
4+
const resource: Businesses = configureMocks<Businesses>(Businesses);
5+
6+
describe("API - 2.0 - Resources - Businesses", () => {
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+
19+
it("should call \"bridgechains\" method", async () => {
20+
const response = await resource.bridgechains("123");
21+
22+
expect(response.status).toBe(200);
23+
});
24+
25+
it("should call \"search\" method", async () => {
26+
const response = await resource.search({});
27+
28+
expect(response.status).toBe(200);
29+
});
30+
});

__tests__/resources/locks.test.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Locks } from "../../src/resources/locks";
2+
import { configureMocks } from "../mocks";
3+
4+
const resource: Locks = configureMocks<Locks>(Locks);
5+
6+
describe("API - 2.0 - Resources - Locks", () => {
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+
19+
it("should call \"search\" method", async () => {
20+
const response = await resource.search({});
21+
22+
expect(response.status).toBe(200);
23+
});
24+
25+
it("should call \"unlocked\" method", async () => {
26+
const response = await resource.unlocked({});
27+
28+
expect(response.status).toBe(200);
29+
});
30+
});

__tests__/resources/wallets.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ describe("API - 2.0 - Resources - Wallets", () => {
2222
expect(response.status).toBe(200);
2323
});
2424

25+
it("should call \"locks\" method", async () => {
26+
const response = await resource.locks("123");
27+
28+
expect(response.status).toBe(200);
29+
});
30+
2531
it("should call \"transactions\" method", async () => {
2632
const response = await resource.transactions("123");
2733

src/resources/bridgechains.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { IResponse } from "../interfaces";
2+
import { Resource } from "./resource";
3+
4+
export class Bridgechains extends Resource {
5+
public async all<T = any>(query?: Record<string, any>): Promise<IResponse<T>> {
6+
return this.sendGet("bridgechains", query);
7+
}
8+
9+
public async get<T = any>(id: string): Promise<IResponse<T>> {
10+
return this.sendGet(`bridgechains/${id}`);
11+
}
12+
13+
public async search<T = any>(payload?: Record<string, any>): Promise<IResponse<T>> {
14+
return this.sendPost("bridgechains/search", payload);
15+
}
16+
}

0 commit comments

Comments
 (0)